Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose instrumentation scope name #4448

Merged
merged 19 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
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 = "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
Original file line number Diff line number Diff line change
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 = "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
Original file line number Diff line number Diff line change
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 = "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
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
)

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.
Expand All @@ -47,7 +48,7 @@
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 @@
}
if !ok {
tracer = otel.GetTracerProvider().Tracer(
tracerName,
ScopeName,

Check warning on line 120 in instrumentation/github.com/gin-gonic/gin/otelgin/gintrace.go

View check run for this annotation

Codecov / codecov/patch

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

Added line #L120 was not covered by tests
oteltrace.WithInstrumentationVersion(Version()),
)
}
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 = "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
Original file line number Diff line number Diff line change
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 = "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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"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 {
Expand All @@ -41,7 +42,7 @@
}

cfg.Tracer = cfg.TracerProvider.Tracer(
defaultTracerName,
ScopeName,

Check warning on line 45 in instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/config.go

View check run for this annotation

Codecov / codecov/patch

instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/config.go#L45

Added line #L45 was not covered by tests
trace.WithInstrumentationVersion(Version()),
)
return cfg
Expand Down
8 changes: 4 additions & 4 deletions instrumentation/google.golang.org/grpc/otelgrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down Expand Up @@ -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),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var (
func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor {
cfg := newConfig(opts, "client")
tracer := cfg.TracerProvider.Tracer(
instrumentationName,
ScopeName,
trace.WithInstrumentationVersion(Version()),
)

Expand Down Expand Up @@ -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()),
)

Expand Down Expand Up @@ -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()),
)

Expand Down Expand Up @@ -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()),
)

Expand Down
6 changes: 3 additions & 3 deletions instrumentation/gopkg.in/macaron.v1/otelmacaron/macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion instrumentation/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"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
Expand Down Expand Up @@ -102,7 +105,7 @@
}
h := &host{
meter: c.MeterProvider.Meter(
"go.opentelemetry.io/contrib/instrumentation/host",
ScopeName,

Check warning on line 108 in instrumentation/host/host.go

View check run for this annotation

Codecov / codecov/patch

instrumentation/host/host.go#L108

Added line #L108 was not covered by tests
metric.WithInstrumentationVersion(Version()),
),
config: c,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()),
)

Expand Down
2 changes: 1 addition & 1 deletion instrumentation/net/http/otelhttp/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
7 changes: 3 additions & 4 deletions instrumentation/net/http/otelhttp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -76,7 +75,7 @@ func newConfig(opts ...Option) *config {
}

c.Meter = c.MeterProvider.Meter(
instrumentationName,
ScopeName,
metric.WithInstrumentationVersion(Version()),
)

Expand Down
5 changes: 4 additions & 1 deletion instrumentation/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"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
Expand Down Expand Up @@ -106,7 +109,7 @@
}
r := &runtime{
meter: c.MeterProvider.Meter(
"go.opentelemetry.io/contrib/instrumentation/runtime",
ScopeName,

Check warning on line 112 in instrumentation/runtime/runtime.go

View check run for this annotation

Codecov / codecov/patch

instrumentation/runtime/runtime.go#L112

Added line #L112 was not covered by tests
metric.WithInstrumentationVersion(Version()),
),
config: c,
Expand Down
Loading