diff --git a/CHANGELOG.md b/CHANGELOG.md index e2d447ff2a1..c80b6b8a201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add support for `console` span exporter and metrics exporter in `go.opentelemetry.io/contrib/exporters/autoexport`. (#4486) - Set unit and description on all instruments in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#4500) - Add metric support for `grpc.StatsHandler` in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#4356) +- Expose the name of the scopes in all instrumentation libraries as `ScopeName`. (#4448) ### Changed diff --git a/instrumentation/README.md b/instrumentation/README.md index 93951140fad..fbc8e0ac657 100644 --- a/instrumentation/README.md +++ b/instrumentation/README.md @@ -92,5 +92,5 @@ Additionally the following guidelines for package composition need to be followe - All instrumentation packages MUST provide an option to accept a `TracerProvider` if it uses a Tracer, a `MeterProvider` if it uses a Meter, and `Propagators` if it handles any context propagation. Also, packages MUST use the default `TracerProvider`, `MeterProvider`, and `Propagators` supplied by the `global` package if no optional one is provided. - All instrumentation packages MUST NOT provide an option to accept a `Tracer` or `Meter`. -- All instrumentation packages MUST create any used `Tracer` or `Meter` with a name matching the instrumentation package name. -- All instrumentation packages MUST create any used `Tracer` or `Meter` with a semantic version corresponding to the version of the module containing the instrumentation. +- All instrumentation packages MUST define a `ScopeName` constant with a value matching the instrumentation package and use it when creating a `Tracer` or `Meter`. +- All instrumentation packages MUST define a `Version` function returning the version of the module containing the instrumentation and use it when creating a `Tracer` or `Meter`. 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..f853d9c52e4 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 = "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..e3f019a5942 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 = "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..ab0ac1e6929 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 = "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/gin-gonic/gin/otelgin/gintrace.go b/instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go index 45c8f854fc7..b9f31c7fa21 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 = "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..d5e3bb36c42 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 = "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..5b0617ef8fd 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 = "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..913b2919dc2 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 = "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 diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/config.go b/instrumentation/google.golang.org/grpc/otelgrpc/config.go index bad05b6734f..494465dc66a 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/config.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/config.go @@ -24,8 +24,8 @@ import ( ) const ( - // instrumentationName is the name of this instrumentation package. - instrumentationName = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + // ScopeName is the instrumentation scope name. + ScopeName = "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" // GRPCStatusCodeKey is convention for numeric status code of a gRPC request. GRPCStatusCodeKey = attribute.Key("rpc.grpc.status_code") ) @@ -73,12 +73,12 @@ func newConfig(opts []Option, role string) *config { } c.tracer = c.TracerProvider.Tracer( - instrumentationName, + ScopeName, trace.WithInstrumentationVersion(SemVersion()), ) c.meter = c.MeterProvider.Meter( - instrumentationName, + ScopeName, metric.WithInstrumentationVersion(Version()), metric.WithSchemaURL(semconv.SchemaURL), ) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go b/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go index c737d29dcd0..8ff583f0608 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go @@ -63,7 +63,7 @@ var ( func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor { cfg := newConfig(opts, "client") tracer := cfg.TracerProvider.Tracer( - instrumentationName, + ScopeName, trace.WithInstrumentationVersion(Version()), ) @@ -257,7 +257,7 @@ func (w *clientStream) sendStreamEvent(eventType streamEventType, err error) { func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor { cfg := newConfig(opts, "client") tracer := cfg.TracerProvider.Tracer( - instrumentationName, + ScopeName, trace.WithInstrumentationVersion(Version()), ) @@ -327,7 +327,7 @@ func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor { func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor { cfg := newConfig(opts, "server") tracer := cfg.TracerProvider.Tracer( - instrumentationName, + ScopeName, trace.WithInstrumentationVersion(Version()), ) @@ -448,7 +448,7 @@ func wrapServerStream(ctx context.Context, ss grpc.ServerStream, cfg *config) *s func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor { cfg := newConfig(opts, "server") tracer := cfg.TracerProvider.Tracer( - instrumentationName, + ScopeName, trace.WithInstrumentationVersion(Version()), ) diff --git a/instrumentation/gopkg.in/macaron.v1/otelmacaron/macaron.go b/instrumentation/gopkg.in/macaron.v1/otelmacaron/macaron.go index 62321a93545..a11efdba463 100644 --- a/instrumentation/gopkg.in/macaron.v1/otelmacaron/macaron.go +++ b/instrumentation/gopkg.in/macaron.v1/otelmacaron/macaron.go @@ -26,14 +26,14 @@ import ( oteltrace "go.opentelemetry.io/otel/trace" ) -// instrumentationName is the name of this instrumentation package. -const instrumentationName = "go.opentelemetry.io/contrib/instrumentation/gopkg.in/macaron.v1/otelmacaron" +// ScopeName is the instrumentation scope name. +const ScopeName = "go.opentelemetry.io/contrib/instrumentation/gopkg.in/macaron.v1/otelmacaron" // Middleware returns a macaron Handler to trace requests to the server. func Middleware(service string, opts ...Option) macaron.Handler { cfg := newConfig(opts) tracer := cfg.TracerProvider.Tracer( - instrumentationName, + ScopeName, oteltrace.WithInstrumentationVersion(Version()), ) return func(res http.ResponseWriter, req *http.Request, c *macaron.Context) { diff --git a/instrumentation/host/host.go b/instrumentation/host/host.go index edd2ef31aa5..f8cd3200642 100644 --- a/instrumentation/host/host.go +++ b/instrumentation/host/host.go @@ -30,6 +30,9 @@ import ( "go.opentelemetry.io/otel/metric" ) +// ScopeName is the instrumentation scope name. +const ScopeName = "go.opentelemetry.io/contrib/instrumentation/host" + // Host reports the work-in-progress conventional host metrics specified by OpenTelemetry. type host struct { config config @@ -102,7 +105,7 @@ func Start(opts ...Option) error { } h := &host{ meter: c.MeterProvider.Meter( - "go.opentelemetry.io/contrib/instrumentation/host", + ScopeName, metric.WithInstrumentationVersion(Version()), ), config: c, diff --git a/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go b/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go index e4b60769eba..b7efa5b503f 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go @@ -29,6 +29,9 @@ import ( "go.opentelemetry.io/otel/trace" ) +// ScopeName is the instrumentation scope name. +const ScopeName = "go.opentelemetry.io/otel/instrumentation/httptrace" + // HTTP attributes. var ( HTTPStatus = attribute.Key("http.status") @@ -169,7 +172,7 @@ func NewClientTrace(ctx context.Context, opts ...ClientTraceOption) *httptrace.C } ct.tr = ct.tracerProvider.Tracer( - "go.opentelemetry.io/otel/instrumentation/httptrace", + ScopeName, trace.WithInstrumentationVersion(Version()), ) diff --git a/instrumentation/net/http/otelhttp/common.go b/instrumentation/net/http/otelhttp/common.go index 4fa950dfe2e..9509014e87c 100644 --- a/instrumentation/net/http/otelhttp/common.go +++ b/instrumentation/net/http/otelhttp/common.go @@ -42,5 +42,5 @@ const ( type Filter func(*http.Request) bool func newTracer(tp trace.TracerProvider) trace.Tracer { - return tp.Tracer(instrumentationName, trace.WithInstrumentationVersion(Version())) + return tp.Tracer(ScopeName, trace.WithInstrumentationVersion(Version())) } diff --git a/instrumentation/net/http/otelhttp/config.go b/instrumentation/net/http/otelhttp/config.go index e4fa1b8d9d6..a1b5b5e5aa8 100644 --- a/instrumentation/net/http/otelhttp/config.go +++ b/instrumentation/net/http/otelhttp/config.go @@ -25,9 +25,8 @@ import ( "go.opentelemetry.io/otel/trace" ) -const ( - instrumentationName = "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" -) +// ScopeName is the instrumentation scope name. +const ScopeName = "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" // config represents the configuration options available for the http.Handler // and http.Transport types. @@ -76,7 +75,7 @@ func newConfig(opts ...Option) *config { } c.Meter = c.MeterProvider.Meter( - instrumentationName, + ScopeName, metric.WithInstrumentationVersion(Version()), ) diff --git a/instrumentation/runtime/runtime.go b/instrumentation/runtime/runtime.go index b6ad2c3b4ec..09c47d4826b 100644 --- a/instrumentation/runtime/runtime.go +++ b/instrumentation/runtime/runtime.go @@ -24,6 +24,9 @@ import ( "go.opentelemetry.io/otel/metric" ) +// ScopeName is the instrumentation scope name. +const ScopeName = "go.opentelemetry.io/contrib/instrumentation/runtime" + // Runtime reports the work-in-progress conventional runtime metrics specified by OpenTelemetry. type runtime struct { config config @@ -106,7 +109,7 @@ func Start(opts ...Option) error { } r := &runtime{ meter: c.MeterProvider.Meter( - "go.opentelemetry.io/contrib/instrumentation/runtime", + ScopeName, metric.WithInstrumentationVersion(Version()), ), config: c,