Process an asynchronous generator and manage its span lifecycle
(span: trace.Span, context_token: Any, generator: types.AsyncGeneratorType)
| 50 | |
| 51 | |
| 52 | async def _process_async_generator(span: trace.Span, context_token: Any, generator: types.AsyncGeneratorType): |
| 53 | """Process an asynchronous generator and manage its span lifecycle""" |
| 54 | try: |
| 55 | async for item in generator: |
| 56 | yield item |
| 57 | finally: |
| 58 | # Always ensure span is ended and context detached |
| 59 | span.end() |
| 60 | context_api.detach(context_token) |
| 61 | |
| 62 | |
| 63 | def _get_current_span_info(): |