From 07826ab735375b580d3ec212ebb9b9db2fa629c8 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 30 Oct 2024 08:23:59 -0700 Subject: [PATCH 1/2] Rename GetTracerProvider to TracerProvider in `sdk` package (#1231) * Rename GetTracerProvider to TracerProvider Resolve #1227 * Add a changelog entry --- CHANGELOG.md | 4 ++++ internal/test/e2e/autosdk/main.go | 2 +- sdk/example_test.go | 4 ++-- sdk/trace.go | 6 +++--- sdk/trace_test.go | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8d83670c..e4e14282c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http ## [Unreleased] +### Changed + +- The `GetTracerProvider` fucntion in `go.opentelemtry.io/auto/sdk` is renamed to `TracerProvider`. ([#1231](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1231)) + ### Fixed - Sporadic shutdown deadlock. ([#1220](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1220)) diff --git a/internal/test/e2e/autosdk/main.go b/internal/test/e2e/autosdk/main.go index c085dbba6..57f367852 100644 --- a/internal/test/e2e/autosdk/main.go +++ b/internal/test/e2e/autosdk/main.go @@ -79,7 +79,7 @@ func main() { // give time for auto-instrumentation to start up time.Sleep(5 * time.Second) - provider := sdk.GetTracerProvider() + provider := sdk.TracerProvider() tracer := provider.Tracer( pkgName, trace.WithInstrumentationVersion(pkgVer), diff --git a/sdk/example_test.go b/sdk/example_test.go index 9394fb15c..d209b0e1d 100644 --- a/sdk/example_test.go +++ b/sdk/example_test.go @@ -5,10 +5,10 @@ package sdk import "context" -func ExampleGetTracerProvider() { +func ExampleTracerProvider() { // Get a Tracer from an auto-instrumented TracerProvider so all spans // created will be passed to the auto-instrumentation telemetry pipeline. - tracer := GetTracerProvider().Tracer("my.pkg/name") + tracer := TracerProvider().Tracer("my.pkg/name") // The tracer is used normally to create spans to encapsulate work. _, span := tracer.Start(context.Background(), "do.work") diff --git a/sdk/trace.go b/sdk/trace.go index 052c02d1c..c1dec80db 100644 --- a/sdk/trace.go +++ b/sdk/trace.go @@ -20,14 +20,14 @@ import ( "go.opentelemetry.io/auto/sdk/telemetry" ) -// GetTracerProvider returns an auto-instrumentable [trace.TracerProvider]. +// TracerProvider returns an auto-instrumentable [trace.TracerProvider]. // // If an [go.opentelemetry.io/auto.Instrumentation] is configured to instrument // the process using the returned TracerProvider, all of the telemetry it // produces will be processed and handled by that Instrumentation. By default, // if no Instrumentation instruments the TracerProvider it will not generate // any trace telemetry. -func GetTracerProvider() trace.TracerProvider { return tracerProviderInstance } +func TracerProvider() trace.TracerProvider { return tracerProviderInstance } var tracerProviderInstance = tracerProvider{} @@ -383,4 +383,4 @@ func (s *span) SetName(name string) { s.span.Name = name } -func (*span) TracerProvider() trace.TracerProvider { return GetTracerProvider() } +func (*span) TracerProvider() trace.TracerProvider { return TracerProvider() } diff --git a/sdk/trace_test.go b/sdk/trace_test.go index f2937d08f..87815d4f5 100644 --- a/sdk/trace_test.go +++ b/sdk/trace_test.go @@ -111,7 +111,7 @@ func TestSpanCreation(t *testing.T) { ts := time.Now() - tracer := GetTracerProvider().Tracer( + tracer := TracerProvider().Tracer( tracerName, trace.WithInstrumentationVersion(tracerVer), trace.WithSchemaURL(semconv.SchemaURL), From 77e8de9e0f4e33afb00bacb77917bad4f3056d1f Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 30 Oct 2024 08:31:23 -0700 Subject: [PATCH 2/2] Embed noop into sdk instead of embedded (#1230) * Embed noop into sdk instead of embedded Default to NoOp behavior when the `sdk` pkg does not implement a method of the Go OTel API instead of causing a compilation error. Resolve #1228 * Add a changelog entry --- CHANGELOG.md | 2 ++ sdk/trace.go | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4e14282c..49205ad60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http ### Changed +- The SDK provided in `go.opentelemtry.io/auto/sdk` now defaults to NoOp behavior for unimplemented methods of the OpenTelemetry API. + This is changed from causing a compilation error for unimplemented methods. ([#1230](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1230)) - The `GetTracerProvider` fucntion in `go.opentelemtry.io/auto/sdk` is renamed to `TracerProvider`. ([#1231](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/1231)) ### Fixed diff --git a/sdk/trace.go b/sdk/trace.go index c1dec80db..1b9508b7d 100644 --- a/sdk/trace.go +++ b/sdk/trace.go @@ -15,7 +15,7 @@ import ( "go.opentelemetry.io/otel/codes" semconv "go.opentelemetry.io/otel/semconv/v1.26.0" "go.opentelemetry.io/otel/trace" - "go.opentelemetry.io/otel/trace/embedded" + "go.opentelemetry.io/otel/trace/noop" "go.opentelemetry.io/auto/sdk/telemetry" ) @@ -31,7 +31,7 @@ func TracerProvider() trace.TracerProvider { return tracerProviderInstance } var tracerProviderInstance = tracerProvider{} -type tracerProvider struct{ embedded.TracerProvider } +type tracerProvider struct{ noop.TracerProvider } var _ trace.TracerProvider = tracerProvider{} @@ -45,7 +45,7 @@ func (p tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tr } type tracer struct { - embedded.Tracer + noop.Tracer name, schemaURL, version string } @@ -140,7 +140,7 @@ func spanKind(kind trace.SpanKind) telemetry.SpanKind { } type span struct { - embedded.Span + noop.Span sampled bool spanContext trace.SpanContext