From 6e06350686282701a19b667a2f8c613eb74b1295 Mon Sep 17 00:00:00 2001 From: Abhishek Ranjan Date: Thu, 2 Jan 2025 15:43:03 +0530 Subject: [PATCH] move call span creation to client_tracing.go --- stats/opentelemetry/client_metrics.go | 15 --------------- stats/opentelemetry/client_tracing.go | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/stats/opentelemetry/client_metrics.go b/stats/opentelemetry/client_metrics.go index 6a7ca9749cd7..cab841a4959b 100644 --- a/stats/opentelemetry/client_metrics.go +++ b/stats/opentelemetry/client_metrics.go @@ -18,11 +18,9 @@ package opentelemetry import ( "context" - "strings" "sync/atomic" "time" - "go.opentelemetry.io/otel" otelcodes "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" "google.golang.org/grpc" @@ -162,19 +160,6 @@ func (h *clientStatsHandler) perCallTracesAndMetrics(ctx context.Context, err er } } -// createCallTraceSpan creates a call span to put in the provided context using -// provided TraceProvider. If TraceProvider is nil, it returns context as is. -func (h *clientStatsHandler) createCallTraceSpan(ctx context.Context, method string) (context.Context, *trace.Span) { - if h.options.TraceOptions.TracerProvider == nil { - logger.Error("TraceProvider is not provided in trace options") - return ctx, nil - } - mn := strings.Replace(removeLeadingSlash(method), "/", ".", -1) - tracer := otel.Tracer("grpc-open-telemetry") - ctx, span := tracer.Start(ctx, mn, trace.WithSpanKind(trace.SpanKindClient)) - return ctx, &span -} - // TagConn exists to satisfy stats.Handler. func (h *clientStatsHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context { return ctx diff --git a/stats/opentelemetry/client_tracing.go b/stats/opentelemetry/client_tracing.go index ee0a285e201b..314d834ef6e3 100644 --- a/stats/opentelemetry/client_tracing.go +++ b/stats/opentelemetry/client_tracing.go @@ -18,6 +18,7 @@ package opentelemetry import ( "context" + "go.opentelemetry.io/otel/trace" "strings" "go.opentelemetry.io/otel" @@ -43,3 +44,16 @@ func (h *clientStatsHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagI ai.traceSpan = span return carrier.Context(), ai } + +// createCallTraceSpan creates a call span to put in the provided context using +// provided TraceProvider. If TraceProvider is nil, it returns context as is. +func (h *clientStatsHandler) createCallTraceSpan(ctx context.Context, method string) (context.Context, *trace.Span) { + if h.options.TraceOptions.TracerProvider == nil { + logger.Error("TraceProvider is not provided in trace options") + return ctx, nil + } + mn := strings.Replace(removeLeadingSlash(method), "/", ".", -1) + tracer := otel.Tracer("grpc-open-telemetry") + ctx, span := tracer.Start(ctx, mn, trace.WithSpanKind(trace.SpanKindClient)) + return ctx, &span +}