-
Notifications
You must be signed in to change notification settings - Fork 148
(Java): Add OpenTelemetry existing parent span support #5061
Description
Describe the feature
Add support for attaching Valkey GLIDE operations to existing OpenTelemetry spans in the Java client, similar to the SpanFromContext functionality implemented for the Go client.
The Go client gained the ability to attach Valkey GLIDE operations as child spans to existing traces through #4243. This allows for proper parent-child span relationships (e.g., for an existing request trace) and improved distributed tracing visibility.
The Java 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
Current behaviour: Valkey GLIDE operations create independent spans.
Desired behaviour: Valkey GLIDE operations appear as child spans under the application's active span.
Proposed Solution
From a client perspective, this could look something like:
import io.opentelemetry.api.trace.Span;
import glide.api.OpenTelemetry;
OpenTelemetry.OpenTelemetryConfig config =
OpenTelemetry.OpenTelemetryConfig.builder()
.traces(OpenTelemetry.TracesConfig.builder()
.endpoint("http://localhost:4318/v1/traces")
.spanFromContext(() -> {
Span span = Span.current();
if (span != null && span.getSpanContext().isValid()) {
return span.getSpanContext();
}
return null;
})
.build())
.build();
OpenTelemetry.init(config);Implementation approach:
- Add spanFromContext callback to TracesConfig.Builder
- Expose create_otel_span_with_parent from FFI layer via JNI as
OpenTelemetryResolver.createLeakedOtelSpanWithParent(String spanName, long parentSpanPtr) - Extract Java OpenTelemetry SDK's active span context and convert to GLIDE span pointer format
- Update CommandManager.prepareCommandRequest() methods to pass parent span pointer when creating operation spans
Other Information
- (Go): CORE/FFI/GO - SpanFromContext implementation #4507
- (Node.js): Add OpenTelemetry existing parent span support #4655
- (Python): Add OpenTelemetry existing parent span support #4992
- (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.2
Environment details (OS name and version, etc.)
Mac