From a74e64b3cb754c1c93ed19e4709dc92a32dc59eb Mon Sep 17 00:00:00 2001 From: Umut Tezduyar Lidskog Date: Fri, 3 Nov 2023 08:16:05 +0100 Subject: [PATCH] More libraries are exposing ScopeName --- .../github.com/aws/aws-lambda-go/otellambda/lambda.go | 5 +++-- .../github.com/aws/aws-sdk-go-v2/otelaws/aws.go | 5 +++-- .../emicklei/go-restful/otelrestful/restful.go | 5 +++-- .../emicklei/go-restful/otelrestful/restful_test.go | 6 ++---- .../github.com/gin-gonic/gin/otelgin/gintrace.go | 9 +++++---- .../github.com/gin-gonic/gin/otelgin/gintrace_test.go | 4 ++-- instrumentation/github.com/gorilla/mux/otelmux/mux.go | 5 +++-- .../github.com/labstack/echo/otelecho/echo.go | 7 ++++--- .../github.com/labstack/echo/otelecho/echo_test.go | 4 ++-- .../mongo-driver/mongo/otelmongo/config.go | 5 +++-- 10 files changed, 30 insertions(+), 25 deletions(-) diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda.go b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda.go index 35fab5ba65f..d44fef33a99 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda.go +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda.go @@ -29,7 +29,8 @@ import ( ) const ( - tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda" + // ScopeName is the instrumentation scope name. + ScopeName string = "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda" ) var errorLogger = log.New(log.Writer(), "OTel Lambda Error: ", 0) @@ -53,7 +54,7 @@ func newInstrumentor(opts ...Option) instrumentor { return instrumentor{ configuration: cfg, - tracer: cfg.TracerProvider.Tracer(tracerName, trace.WithInstrumentationVersion(Version())), + tracer: cfg.TracerProvider.Tracer(ScopeName, trace.WithInstrumentationVersion(Version())), resAttrs: []attribute.KeyValue{}, } } diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go index 504fb796e8a..5b66a5c8c5e 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go @@ -31,7 +31,8 @@ import ( ) const ( - tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws" + // ScopeName is the instrumentation scope name. + ScopeName string = "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws" ) type spanTimestampKey struct{} @@ -160,7 +161,7 @@ func AppendMiddlewares(apiOptions *[]func(*middleware.Stack) error, opts ...Opti } m := otelMiddlewares{ - tracer: cfg.TracerProvider.Tracer(tracerName, + tracer: cfg.TracerProvider.Tracer(ScopeName, trace.WithInstrumentationVersion(Version())), propagator: cfg.TextMapPropagator, attributeSetter: cfg.AttributeSetter, diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/restful.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/restful.go index 4325368fa3a..069160656a4 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/restful.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/restful.go @@ -24,7 +24,8 @@ import ( oteltrace "go.opentelemetry.io/otel/trace" ) -const tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful" +// ScopeName is the instrumentation scope name. +const ScopeName string = "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful" // OTelFilter returns a restful.FilterFunction which will trace an incoming request. // @@ -40,7 +41,7 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction { cfg.TracerProvider = otel.GetTracerProvider() } tracer := cfg.TracerProvider.Tracer( - tracerName, + ScopeName, oteltrace.WithInstrumentationVersion(Version()), ) if cfg.Propagators == nil { diff --git a/instrumentation/github.com/emicklei/go-restful/otelrestful/restful_test.go b/instrumentation/github.com/emicklei/go-restful/otelrestful/restful_test.go index 30c718b72e1..6f411568750 100644 --- a/instrumentation/github.com/emicklei/go-restful/otelrestful/restful_test.go +++ b/instrumentation/github.com/emicklei/go-restful/otelrestful/restful_test.go @@ -33,8 +33,6 @@ import ( oteltrace "go.opentelemetry.io/otel/trace" ) -const tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful" - func TestGetSpanNotInstrumented(t *testing.T) { handlerFunc := func(req *restful.Request, resp *restful.Response) { span := oteltrace.SpanFromContext(req.Request.Context()) @@ -69,7 +67,7 @@ func TestPropagationWithGlobalPropagators(t *testing.T) { SpanID: oteltrace.SpanID{0x01}, }) ctx = oteltrace.ContextWithRemoteSpanContext(ctx, sc) - ctx, _ = provider.Tracer(tracerName).Start(ctx, "test") + ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test") otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(r.Header)) handlerFunc := func(req *restful.Request, resp *restful.Response) { @@ -101,7 +99,7 @@ func TestPropagationWithCustomPropagators(t *testing.T) { SpanID: oteltrace.SpanID{0x01}, }) ctx = oteltrace.ContextWithRemoteSpanContext(ctx, sc) - ctx, _ = provider.Tracer(tracerName).Start(ctx, "test") + ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test") b3.Inject(ctx, propagation.HeaderCarrier(r.Header)) handlerFunc := func(req *restful.Request, resp *restful.Response) { diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go b/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go index 45c8f854fc7..60ffa1df731 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go @@ -31,8 +31,9 @@ import ( ) const ( - tracerKey = "otel-go-contrib-tracer" - tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" + tracerKey = "otel-go-contrib-tracer" + // ScopeName is the instrumentation scope name. + ScopeName string = "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" ) // Middleware returns middleware that will trace incoming requests. @@ -47,7 +48,7 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc { cfg.TracerProvider = otel.GetTracerProvider() } tracer := cfg.TracerProvider.Tracer( - tracerName, + ScopeName, oteltrace.WithInstrumentationVersion(Version()), ) if cfg.Propagators == nil { @@ -116,7 +117,7 @@ func HTML(c *gin.Context, code int, name string, obj interface{}) { } if !ok { tracer = otel.GetTracerProvider().Tracer( - tracerName, + ScopeName, oteltrace.WithInstrumentationVersion(Version()), ) } diff --git a/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace_test.go b/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace_test.go index e95e1f0aa58..a84b82d3510 100644 --- a/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace_test.go +++ b/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace_test.go @@ -65,7 +65,7 @@ func TestPropagationWithGlobalPropagators(t *testing.T) { SpanID: trace.SpanID{0x01}, }) ctx = trace.ContextWithRemoteSpanContext(ctx, sc) - ctx, _ = provider.Tracer(tracerName).Start(ctx, "test") + ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test") otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(r.Header)) router := gin.New() @@ -92,7 +92,7 @@ func TestPropagationWithCustomPropagators(t *testing.T) { SpanID: trace.SpanID{0x01}, }) ctx = trace.ContextWithRemoteSpanContext(ctx, sc) - ctx, _ = provider.Tracer(tracerName).Start(ctx, "test") + ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test") b3.Inject(ctx, propagation.HeaderCarrier(r.Header)) router := gin.New() diff --git a/instrumentation/github.com/gorilla/mux/otelmux/mux.go b/instrumentation/github.com/gorilla/mux/otelmux/mux.go index f1ead848b3b..fc0f4eea144 100644 --- a/instrumentation/github.com/gorilla/mux/otelmux/mux.go +++ b/instrumentation/github.com/gorilla/mux/otelmux/mux.go @@ -30,7 +30,8 @@ import ( ) const ( - tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux" + // ScopeName is the instrumentation scope name. + ScopeName string = "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux" ) // Middleware sets up a handler to start tracing the incoming @@ -45,7 +46,7 @@ func Middleware(service string, opts ...Option) mux.MiddlewareFunc { cfg.TracerProvider = otel.GetTracerProvider() } tracer := cfg.TracerProvider.Tracer( - tracerName, + ScopeName, trace.WithInstrumentationVersion(Version()), ) if cfg.Propagators == nil { diff --git a/instrumentation/github.com/labstack/echo/otelecho/echo.go b/instrumentation/github.com/labstack/echo/otelecho/echo.go index 02f797f88df..fa82a83c96e 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/echo.go +++ b/instrumentation/github.com/labstack/echo/otelecho/echo.go @@ -30,8 +30,9 @@ import ( ) const ( - tracerKey = "otel-go-contrib-tracer-labstack-echo" - tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho" + tracerKey = "otel-go-contrib-tracer-labstack-echo" + // ScopeName is the instrumentation scope name. + ScopeName string = "go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho" ) // Middleware returns echo middleware which will trace incoming requests. @@ -44,7 +45,7 @@ func Middleware(service string, opts ...Option) echo.MiddlewareFunc { cfg.TracerProvider = otel.GetTracerProvider() } tracer := cfg.TracerProvider.Tracer( - tracerName, + ScopeName, oteltrace.WithInstrumentationVersion(Version()), ) if cfg.Propagators == nil { diff --git a/instrumentation/github.com/labstack/echo/otelecho/echo_test.go b/instrumentation/github.com/labstack/echo/otelecho/echo_test.go index 3d5b42d51a0..a6c135eb28c 100644 --- a/instrumentation/github.com/labstack/echo/otelecho/echo_test.go +++ b/instrumentation/github.com/labstack/echo/otelecho/echo_test.go @@ -61,7 +61,7 @@ func TestPropagationWithGlobalPropagators(t *testing.T) { SpanID: trace.SpanID{0x01}, }) ctx = trace.ContextWithRemoteSpanContext(ctx, sc) - ctx, _ = provider.Tracer(tracerName).Start(ctx, "test") + ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test") otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(r.Header)) router := echo.New() @@ -92,7 +92,7 @@ func TestPropagationWithCustomPropagators(t *testing.T) { SpanID: trace.SpanID{0x01}, }) ctx = trace.ContextWithRemoteSpanContext(ctx, sc) - ctx, _ = provider.Tracer(tracerName).Start(ctx, "test") + ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test") b3.Inject(ctx, propagation.HeaderCarrier(r.Header)) router := echo.New() diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/config.go b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/config.go index 558652cf570..679c633ea64 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/config.go +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/config.go @@ -19,7 +19,8 @@ import ( "go.opentelemetry.io/otel/trace" ) -const defaultTracerName = "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo" +// ScopeName is the instrumentation scope name. +const ScopeName string = "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo" // config is used to configure the mongo tracer. type config struct { @@ -41,7 +42,7 @@ func newConfig(opts ...Option) config { } cfg.Tracer = cfg.TracerProvider.Tracer( - defaultTracerName, + ScopeName, trace.WithInstrumentationVersion(Version()), ) return cfg