diff --git a/rpc/handler.go b/rpc/handler.go index 2b03888614..c7aa0b8434 100644 --- a/rpc/handler.go +++ b/rpc/handler.go @@ -32,7 +32,6 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" - sdktrace "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.24.0" "go.opentelemetry.io/otel/trace" ) @@ -598,7 +597,6 @@ func (h *handler) handleSubscribe(cp *callProc, msg *jsonrpcMessage) *jsonrpcMes // end the span. The function will record errors and set span status based on // the error value. func (h *handler) startSpan(ctx context.Context, msg *jsonrpcMessage, spanName string) (context.Context, func(*error)) { - parentSpan := trace.SpanFromContext(ctx) ctx, span := h.tracer().Start(ctx, spanName) // Fast path: noop provider or span not sampled @@ -615,19 +613,10 @@ func (h *handler) startSpan(ctx context.Context, msg *jsonrpcMessage, spanName s // Define the function to end the span and handle error recording spanEnd := func(err *error) { - ro, _ := span.(sdktrace.ReadOnlySpan) if *err != nil { // Error occurred, record it and set status on span and parent span.RecordError(*err) span.SetStatus(codes.Error, (*err).Error()) - parentSpan.SetStatus(codes.Error, (*err).Error()) - } else if ro.Status().Code == codes.Error { - // Span's child had an error, propagate it to parent - // Note: Span's status was already set in the child - parentSpan.SetStatus(codes.Error, ro.Status().Description) - } else if ro.Status().Code == codes.Unset { - // No error and no status set, mark as success - span.SetStatus(codes.Ok, "") } span.End() } @@ -654,7 +643,9 @@ func (h *handler) runMethod(ctx context.Context, msg *jsonrpcMessage, callb *cal // If parent span is recording, start a span for the response. // Note: This prevents msg.response spans from being created when - // the parent span is not recording (e.g. subscription tracing disabled). + // the parent span is not recording. This is needed bc we aren't + // currently recording spans for subscriptions, but we do record spans + // for other RPC methods and this is called for both. parentSpan := trace.SpanFromContext(ctx) if parentSpan.IsRecording() { _, spanEnd := h.startSpan(ctx, msg, "rpc.msg.response") diff --git a/rpc/server.go b/rpc/server.go index ddf396b422..98e2d70f47 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -102,6 +102,10 @@ func (s *Server) SetWebsocketReadLimit(limit int64) { } // SetTracerProvider configures the OpenTelemetry TracerProvider for RPC call tracing. +// Note: This method (and the TracerProvider field in the Server/Handler struct) is +// primarily intended for testing. In particular, it allows tests to configure an +// isolated TracerProvider without changing the global provider, avoiding +// interference between tests running in parallel. func (s *Server) SetTracerProvider(tp trace.TracerProvider) { s.tracerProvider = tp }