diff --git a/CHANGELOG.md b/CHANGELOG.md index 4289ab3d444..58a51701025 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,13 +34,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Rename `MergeItererator` to `MergeIterator` in the `go.opentelemetry.io/otel/label` package. (#1244) - Move the `go.opentelemetry.io/otel/api/metric/metrictest` package into `go.opentelemetry.io/oteltest` as part of #964. (#1252) - Move the `go.opentelemetry.io/otel/api/metric` package into `go.opentelemetry.io/otel/metric` as part of #1303. (#1321) -- Move the `go.opentelemetry.io/otel/api/metric/registry` package into `go.opentelemetry.io/otel/metric/registry as a part of #1303. (#1316) +- Move the `go.opentelemetry.io/otel/api/metric/registry` package into `go.opentelemetry.io/otel/metric/registry` as a part of #1303. (#1316) - Move the `Number` type (together with related functions) from `go.opentelemetry.io/otel/api/metric` package into `go.opentelemetry.io/otel/metric/number` as a part of #1303. (#1316) - The function signature of the Span `AddEvent` method in `go.opentelemetry.io/otel` is updated to no longer take an unused context and instead take a required name and a variable number of `EventOption`s. (#1254) - The function signature of the Span `RecordError` method in `go.opentelemetry.io/otel` is updated to no longer take an unused context and instead take a required error value and a variable number of `EventOption`s. (#1254) - Move the `go.opentelemetry.io/otel/api/global` package to `go.opentelemetry.io/otel/global`. (#1262) - Rename correlation context header from `"otcorrelations"` to `"baggage"` to match the OpenTelemetry specification. (#1267) - Fix `Code.UnmarshalJSON` to work with valid json only. (#1276) +- Fix the global `TracerProvider` to pass options to its configured provider. (#FIXME) - The `resource.New()` method changes signature to support builtin attributes and functional options, including `telemetry.sdk.*` and `host.name` semantic conventions; the former method is renamed `resource.NewWithAttributes`. (#1235) - The prometheus exporter now exports non-monotonic counters (i.e. `UpDownCounter`s) as gauges. (#1210) diff --git a/global/internal/trace.go b/global/internal/trace.go index c60828e8a44..fa4a3a74be1 100644 --- a/global/internal/trace.go +++ b/global/internal/trace.go @@ -84,7 +84,7 @@ func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T defer p.mtx.Unlock() if p.delegate != nil { - return p.delegate.Tracer(name) + return p.delegate.Tracer(name, opts...) } t := &tracer{name: name, opts: opts} diff --git a/global/internal/trace_test.go b/global/internal/trace_test.go index 39baa07d2c0..a5753a73950 100644 --- a/global/internal/trace_test.go +++ b/global/internal/trace_test.go @@ -23,6 +23,7 @@ import ( "go.opentelemetry.io/otel/global" "go.opentelemetry.io/otel/global/internal" "go.opentelemetry.io/otel/oteltest" + "go.opentelemetry.io/otel/trace" ) func TestTraceWithSDK(t *testing.T) { @@ -61,3 +62,32 @@ func TestTraceWithSDK(t *testing.T) { assert.ElementsMatch(t, expected, filterNames(sr.Started())) assert.ElementsMatch(t, expected, filterNames(sr.Completed())) } + +type fnTracerProvider struct { + tracer func(string, ...trace.TracerOption) trace.Tracer +} + +func (fn fnTracerProvider) Tracer(instrumentationName string, opts ...trace.TracerOption) trace.Tracer { + return fn.tracer(instrumentationName, opts...) +} + +func TestTraceProviderDelegates(t *testing.T) { + internal.ResetForTest() + + // Retrieve the placeholder TracerProvider. + gtp := global.TracerProvider() + + // Configure it with a spy. + called := false + global.SetTracerProvider(fnTracerProvider{ + tracer: func(name string, opts ...trace.TracerOption) trace.Tracer { + called = true + assert.Equal(t, "abc", name) + assert.Equal(t, []trace.TracerOption{trace.WithInstrumentationVersion("xyz")}, opts) + return trace.NewNoopTracerProvider().Tracer("") + }, + }) + + gtp.Tracer("abc", trace.WithInstrumentationVersion("xyz")) + assert.True(t, called, "expected configured TraceProvider to be called") +}