Skip to content

Commit

Permalink
More libraries are exposing ScopeName
Browse files Browse the repository at this point in the history
  • Loading branch information
utezduyar committed Nov 3, 2023
1 parent 3ab611a commit a74e64b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 25 deletions.
Expand Up @@ -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)
Expand All @@ -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{},
}
}
Expand Down
5 changes: 3 additions & 2 deletions instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go
Expand Up @@ -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{}
Expand Down Expand Up @@ -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,
Expand Down
Expand Up @@ -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.
//
Expand All @@ -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 {
Expand Down
Expand Up @@ -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())
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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()),
)
}
Expand Down
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions instrumentation/github.com/gorilla/mux/otelmux/mux.go
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions instrumentation/github.com/labstack/echo/otelecho/echo.go
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Expand Up @@ -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 {
Expand All @@ -41,7 +42,7 @@ func newConfig(opts ...Option) config {
}

cfg.Tracer = cfg.TracerProvider.Tracer(
defaultTracerName,
ScopeName,
trace.WithInstrumentationVersion(Version()),
)
return cfg
Expand Down

0 comments on commit a74e64b

Please sign in to comment.