Skip to content

(Python): Add OpenTelemetry existing parent span support #4992

@mahendrabishnoi2

Description

@mahendrabishnoi2

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions