-
Notifications
You must be signed in to change notification settings - Fork 148
(Python): Add OpenTelemetry existing parent span support #4992
Description
Describe the feature
Add support for attaching Valkey Glide operations to existing OpenTelemetry spans in the Python client; similar to the SpanFromContext functionality implemented for the Go client.
The Go client gained the ability to attach Glide operations as child spans to existing traces through #4243 and #4507. This allows for proper parent-child span relationships (e.g. for an existing request trace) and improved distributed tracing visibility.
The Python client currently lacks equivalent functionality; there's no way to extract active span context from the current execution context and set existing spans as parents for Valkey operations.
Use Case
This enables end-to-end distributed tracing where:
- Application creates a parent span for a request
- Valkey operations automatically become child spans
- Full request flow is visible in tracing systems
- Performance bottlenecks in cache operations are easily identified under the request trace
Proposed Solution
From a client perspective this could look something like:
from opentelemetry import trace
def active_span_id() -> int:
span = trace.get_current_span()
if span and span.get_span_context().is_valid:
return span.get_span_context().span_id
return 0
OpenTelemetry.init(
OpenTelemetryConfig(
active_span=active_span_id,
# other fields as is
)
)Other Information
- (Go): CORE/FFI/GO - SpanFromContext implementation #4507
- (Node.js): Add OpenTelemetry existing parent span support #4655
- (Java): Add OpenTelemetry existing parent span support #5061
- (PHP): Add OpenTelemetry existing parent span support #95
- (C#): Add OpenTelemetry existing parent span support #162
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
Client version used
2.1.1
Environment details (OS name and version, etc.)
MacOS 15.7, Python 3.13