Process a synchronous generator and manage its span lifecycle
(span: trace.Span, generator: types.GeneratorType)
| 36 | |
| 37 | |
| 38 | def _process_sync_generator(span: trace.Span, generator: types.GeneratorType): |
| 39 | """Process a synchronous generator and manage its span lifecycle""" |
| 40 | # Ensure span context is attached to the generator context |
| 41 | context_api.attach(trace.set_span_in_context(span)) |
| 42 | |
| 43 | # Yield from the generator while maintaining span context |
| 44 | yield from generator |
| 45 | |
| 46 | # End the span when generator is exhausted |
| 47 | span.end() |
| 48 | # No detach because of OpenTelemetry issue #2606 |
| 49 | # Context will be detached during garbage collection |
| 50 | |
| 51 | |
| 52 | async def _process_async_generator(span: trace.Span, context_token: Any, generator: types.AsyncGeneratorType): |