Skip to content

Commit a3b16ae

Browse files
utezduyarpellareddashpole
authored
Expose instrumentation scope name (#4448)
Co-authored-by: Robert Pająk <[email protected]> Co-authored-by: David Ashpole <[email protected]>
1 parent 2b69029 commit a3b16ae

File tree

19 files changed

+58
-42
lines changed

19 files changed

+58
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1818
- Add support for `console` span exporter and metrics exporter in `go.opentelemetry.io/contrib/exporters/autoexport`. (#4486)
1919
- Set unit and description on all instruments in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp`. (#4500)
2020
- Add metric support for `grpc.StatsHandler` in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#4356)
21+
- Expose the name of the scopes in all instrumentation libraries as `ScopeName`. (#4448)
2122

2223
### Changed
2324

instrumentation/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ Additionally the following guidelines for package composition need to be followe
9292
- 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.
9393
Also, packages MUST use the default `TracerProvider`, `MeterProvider`, and `Propagators` supplied by the `global` package if no optional one is provided.
9494
- All instrumentation packages MUST NOT provide an option to accept a `Tracer` or `Meter`.
95-
- All instrumentation packages MUST create any used `Tracer` or `Meter` with a name matching the instrumentation package name.
96-
- All instrumentation packages MUST create any used `Tracer` or `Meter` with a semantic version corresponding to the version of the module containing the instrumentation.
95+
- All instrumentation packages MUST define a `ScopeName` constant with a value matching the instrumentation package and use it when creating a `Tracer` or `Meter`.
96+
- 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`.

instrumentation/github.com/aws/aws-lambda-go/otellambda/lambda.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import (
2929
)
3030

3131
const (
32-
tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda"
32+
// ScopeName is the instrumentation scope name.
33+
ScopeName = "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda"
3334
)
3435

3536
var errorLogger = log.New(log.Writer(), "OTel Lambda Error: ", 0)
@@ -53,7 +54,7 @@ func newInstrumentor(opts ...Option) instrumentor {
5354

5455
return instrumentor{
5556
configuration: cfg,
56-
tracer: cfg.TracerProvider.Tracer(tracerName, trace.WithInstrumentationVersion(Version())),
57+
tracer: cfg.TracerProvider.Tracer(ScopeName, trace.WithInstrumentationVersion(Version())),
5758
resAttrs: []attribute.KeyValue{},
5859
}
5960
}

instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import (
3131
)
3232

3333
const (
34-
tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws"
34+
// ScopeName is the instrumentation scope name.
35+
ScopeName = "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws"
3536
)
3637

3738
type spanTimestampKey struct{}
@@ -160,7 +161,7 @@ func AppendMiddlewares(apiOptions *[]func(*middleware.Stack) error, opts ...Opti
160161
}
161162

162163
m := otelMiddlewares{
163-
tracer: cfg.TracerProvider.Tracer(tracerName,
164+
tracer: cfg.TracerProvider.Tracer(ScopeName,
164165
trace.WithInstrumentationVersion(Version())),
165166
propagator: cfg.TextMapPropagator,
166167
attributeSetter: cfg.AttributeSetter,

instrumentation/github.com/emicklei/go-restful/otelrestful/restful.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import (
2424
oteltrace "go.opentelemetry.io/otel/trace"
2525
)
2626

27-
const tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful"
27+
// ScopeName is the instrumentation scope name.
28+
const ScopeName = "go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful"
2829

2930
// OTelFilter returns a restful.FilterFunction which will trace an incoming request.
3031
//
@@ -40,7 +41,7 @@ func OTelFilter(service string, opts ...Option) restful.FilterFunction {
4041
cfg.TracerProvider = otel.GetTracerProvider()
4142
}
4243
tracer := cfg.TracerProvider.Tracer(
43-
tracerName,
44+
ScopeName,
4445
oteltrace.WithInstrumentationVersion(Version()),
4546
)
4647
if cfg.Propagators == nil {

instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ import (
3131
)
3232

3333
const (
34-
tracerKey = "otel-go-contrib-tracer"
35-
tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
34+
tracerKey = "otel-go-contrib-tracer"
35+
// ScopeName is the instrumentation scope name.
36+
ScopeName = "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
3637
)
3738

3839
// Middleware returns middleware that will trace incoming requests.
@@ -47,7 +48,7 @@ func Middleware(service string, opts ...Option) gin.HandlerFunc {
4748
cfg.TracerProvider = otel.GetTracerProvider()
4849
}
4950
tracer := cfg.TracerProvider.Tracer(
50-
tracerName,
51+
ScopeName,
5152
oteltrace.WithInstrumentationVersion(Version()),
5253
)
5354
if cfg.Propagators == nil {
@@ -116,7 +117,7 @@ func HTML(c *gin.Context, code int, name string, obj interface{}) {
116117
}
117118
if !ok {
118119
tracer = otel.GetTracerProvider().Tracer(
119-
tracerName,
120+
ScopeName,
120121
oteltrace.WithInstrumentationVersion(Version()),
121122
)
122123
}

instrumentation/github.com/gin-gonic/gin/otelgin/gintrace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestPropagationWithGlobalPropagators(t *testing.T) {
6565
SpanID: trace.SpanID{0x01},
6666
})
6767
ctx = trace.ContextWithRemoteSpanContext(ctx, sc)
68-
ctx, _ = provider.Tracer(tracerName).Start(ctx, "test")
68+
ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test")
6969
otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(r.Header))
7070

7171
router := gin.New()
@@ -92,7 +92,7 @@ func TestPropagationWithCustomPropagators(t *testing.T) {
9292
SpanID: trace.SpanID{0x01},
9393
})
9494
ctx = trace.ContextWithRemoteSpanContext(ctx, sc)
95-
ctx, _ = provider.Tracer(tracerName).Start(ctx, "test")
95+
ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test")
9696
b3.Inject(ctx, propagation.HeaderCarrier(r.Header))
9797

9898
router := gin.New()

instrumentation/github.com/gorilla/mux/otelmux/mux.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import (
3030
)
3131

3232
const (
33-
tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux"
33+
// ScopeName is the instrumentation scope name.
34+
ScopeName = "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux"
3435
)
3536

3637
// Middleware sets up a handler to start tracing the incoming
@@ -45,7 +46,7 @@ func Middleware(service string, opts ...Option) mux.MiddlewareFunc {
4546
cfg.TracerProvider = otel.GetTracerProvider()
4647
}
4748
tracer := cfg.TracerProvider.Tracer(
48-
tracerName,
49+
ScopeName,
4950
trace.WithInstrumentationVersion(Version()),
5051
)
5152
if cfg.Propagators == nil {

instrumentation/github.com/labstack/echo/otelecho/echo.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import (
3030
)
3131

3232
const (
33-
tracerKey = "otel-go-contrib-tracer-labstack-echo"
34-
tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho"
33+
tracerKey = "otel-go-contrib-tracer-labstack-echo"
34+
// ScopeName is the instrumentation scope name.
35+
ScopeName = "go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho"
3536
)
3637

3738
// Middleware returns echo middleware which will trace incoming requests.
@@ -44,7 +45,7 @@ func Middleware(service string, opts ...Option) echo.MiddlewareFunc {
4445
cfg.TracerProvider = otel.GetTracerProvider()
4546
}
4647
tracer := cfg.TracerProvider.Tracer(
47-
tracerName,
48+
ScopeName,
4849
oteltrace.WithInstrumentationVersion(Version()),
4950
)
5051
if cfg.Propagators == nil {

instrumentation/github.com/labstack/echo/otelecho/echo_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestPropagationWithGlobalPropagators(t *testing.T) {
6161
SpanID: trace.SpanID{0x01},
6262
})
6363
ctx = trace.ContextWithRemoteSpanContext(ctx, sc)
64-
ctx, _ = provider.Tracer(tracerName).Start(ctx, "test")
64+
ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test")
6565
otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(r.Header))
6666

6767
router := echo.New()
@@ -92,7 +92,7 @@ func TestPropagationWithCustomPropagators(t *testing.T) {
9292
SpanID: trace.SpanID{0x01},
9393
})
9494
ctx = trace.ContextWithRemoteSpanContext(ctx, sc)
95-
ctx, _ = provider.Tracer(tracerName).Start(ctx, "test")
95+
ctx, _ = provider.Tracer(ScopeName).Start(ctx, "test")
9696
b3.Inject(ctx, propagation.HeaderCarrier(r.Header))
9797

9898
router := echo.New()

0 commit comments

Comments
 (0)