From 37e59e791b08dc83cf254fd9b4919c1b6e81f968 Mon Sep 17 00:00:00 2001 From: dmathieu Date: Wed, 17 Jul 2024 14:40:27 +0200 Subject: [PATCH 1/6] allow relying on InstrumentationScope in SpanStub rather than the deprecated InstrumentationLibrary --- .../otlptracegrpc/internal/otlptracetest/data.go | 2 +- .../otlptracehttp/internal/otlptracetest/data.go | 2 +- exporters/stdout/stdouttrace/trace_test.go | 5 +++++ exporters/zipkin/model_test.go | 6 +++--- .../shared/otlp/otlptrace/otlptracetest/data.go.tmpl | 2 +- sdk/trace/tracetest/span.go | 9 ++++++++- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlptracetest/data.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlptracetest/data.go index 75837732cc9..59f7b78e62b 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/otlptracetest/data.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/otlptracetest/data.go @@ -46,7 +46,7 @@ func SingleReadOnlySpan() []tracesdk.ReadOnlySpan { DroppedLinks: 0, ChildSpanCount: 0, Resource: resource.NewSchemaless(attribute.String("a", "b")), - InstrumentationLibrary: instrumentation.Library{ + InstrumentationScope: instrumentation.Scope{ Name: "bar", Version: "0.0.0", }, diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/otlptracetest/data.go b/exporters/otlp/otlptrace/otlptracehttp/internal/otlptracetest/data.go index dd296c75c0e..e4154f82d00 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/otlptracetest/data.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/otlptracetest/data.go @@ -46,7 +46,7 @@ func SingleReadOnlySpan() []tracesdk.ReadOnlySpan { DroppedLinks: 0, ChildSpanCount: 0, Resource: resource.NewSchemaless(attribute.String("a", "b")), - InstrumentationLibrary: instrumentation.Library{ + InstrumentationScope: instrumentation.Scope{ Name: "bar", Version: "0.0.0", }, diff --git a/exporters/stdout/stdouttrace/trace_test.go b/exporters/stdout/stdouttrace/trace_test.go index a1fc44e559d..d598ca4cd85 100644 --- a/exporters/stdout/stdouttrace/trace_test.go +++ b/exporters/stdout/stdouttrace/trace_test.go @@ -186,6 +186,11 @@ func expectedJSON(now time.Time) string { } } ], + "InstrumentationScope": { + "Name": "", + "Version": "", + "SchemaURL": "" + }, "InstrumentationLibrary": { "Name": "", "Version": "", diff --git a/exporters/zipkin/model_test.go b/exporters/zipkin/model_test.go index 90d38c302be..dc00f9a6791 100644 --- a/exporters/zipkin/model_test.go +++ b/exporters/zipkin/model_test.go @@ -1015,7 +1015,7 @@ func TestTagsTransformation(t *testing.T) { { name: "instrLib-empty", data: tracetest.SpanStub{ - InstrumentationLibrary: instrumentation.Library{}, + InstrumentationScope: instrumentation.Scope{}, }, want: nil, }, @@ -1023,7 +1023,7 @@ func TestTagsTransformation(t *testing.T) { name: "instrLib-noversion", data: tracetest.SpanStub{ Attributes: []attribute.KeyValue{}, - InstrumentationLibrary: instrumentation.Library{ + InstrumentationScope: instrumentation.Scope{ Name: instrLibName, }, }, @@ -1035,7 +1035,7 @@ func TestTagsTransformation(t *testing.T) { name: "instrLib-with-version", data: tracetest.SpanStub{ Attributes: []attribute.KeyValue{}, - InstrumentationLibrary: instrumentation.Library{ + InstrumentationScope: instrumentation.Scope{ Name: instrLibName, Version: instrLibVersion, }, diff --git a/internal/shared/otlp/otlptrace/otlptracetest/data.go.tmpl b/internal/shared/otlp/otlptrace/otlptracetest/data.go.tmpl index f9b020b71cc..9efc6038b0e 100644 --- a/internal/shared/otlp/otlptrace/otlptracetest/data.go.tmpl +++ b/internal/shared/otlp/otlptrace/otlptracetest/data.go.tmpl @@ -46,7 +46,7 @@ func SingleReadOnlySpan() []tracesdk.ReadOnlySpan { DroppedLinks: 0, ChildSpanCount: 0, Resource: resource.NewSchemaless(attribute.String("a", "b")), - InstrumentationLibrary: instrumentation.Library{ + InstrumentationScope: instrumentation.Scope{ Name: "bar", Version: "0.0.0", }, diff --git a/sdk/trace/tracetest/span.go b/sdk/trace/tracetest/span.go index 0a641f94889..4acff5e01bd 100644 --- a/sdk/trace/tracetest/span.go +++ b/sdk/trace/tracetest/span.go @@ -60,6 +60,7 @@ type SpanStub struct { DroppedLinks int ChildSpanCount int Resource *resource.Resource + InstrumentationScope instrumentation.Scope InstrumentationLibrary instrumentation.Library } @@ -85,12 +86,18 @@ func SpanStubFromReadOnlySpan(ro tracesdk.ReadOnlySpan) SpanStub { DroppedLinks: ro.DroppedLinks(), ChildSpanCount: ro.ChildSpanCount(), Resource: ro.Resource(), + InstrumentationScope: ro.InstrumentationScope(), InstrumentationLibrary: ro.InstrumentationScope(), } } // Snapshot returns a read-only copy of the SpanStub. func (s SpanStub) Snapshot() tracesdk.ReadOnlySpan { + scopeOrLibrary := s.InstrumentationScope + if scopeOrLibrary.Name == "" && scopeOrLibrary.Version == "" && scopeOrLibrary.SchemaURL == "" { + scopeOrLibrary = s.InstrumentationLibrary + } + return spanSnapshot{ name: s.Name, spanContext: s.SpanContext, @@ -107,7 +114,7 @@ func (s SpanStub) Snapshot() tracesdk.ReadOnlySpan { droppedLinks: s.DroppedLinks, childSpanCount: s.ChildSpanCount, resource: s.Resource, - instrumentationScope: s.InstrumentationLibrary, + instrumentationScope: scopeOrLibrary, } } From 2b05f3001093f2870e5a416237d53b6e89ea2bdb Mon Sep 17 00:00:00 2001 From: dmathieu Date: Wed, 17 Jul 2024 14:48:19 +0200 Subject: [PATCH 2/6] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76a355194da..936f2897814 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added - Add macOS ARM64 platform to the compatibility testing suite. (#5577) +- The `InstrumentationScope` attribute to `SpanStub` in `go.opentelemetry.io/otel/sdk/trace/tracetest`, as a replacement for the deprecated `InstrumentationLibrary`. (#5627) ### Fixed From e8a5e9a5f62162c8ef536dd3fc3fba997a93bc89 Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Wed, 17 Jul 2024 16:08:12 +0200 Subject: [PATCH 3/6] Update CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert PajÄ…k --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 936f2897814..8ea87db5907 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added - Add macOS ARM64 platform to the compatibility testing suite. (#5577) -- The `InstrumentationScope` attribute to `SpanStub` in `go.opentelemetry.io/otel/sdk/trace/tracetest`, as a replacement for the deprecated `InstrumentationLibrary`. (#5627) +- Add `InstrumentationScope` field to `SpanStub` in `go.opentelemetry.io/otel/sdk/trace/tracetest`, as a replacement for the deprecated `InstrumentationLibrary`. (#5627) ### Fixed From 743cc9f95d389f01af0c5aab1528cd8d0a53730d Mon Sep 17 00:00:00 2001 From: dmathieu Date: Wed, 17 Jul 2024 16:10:38 +0200 Subject: [PATCH 4/6] mark SpanStub.InstrumentationLibrary as deprecated --- sdk/trace/tracetest/span.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/trace/tracetest/span.go b/sdk/trace/tracetest/span.go index 4acff5e01bd..96415dd9a0f 100644 --- a/sdk/trace/tracetest/span.go +++ b/sdk/trace/tracetest/span.go @@ -61,7 +61,7 @@ type SpanStub struct { ChildSpanCount int Resource *resource.Resource InstrumentationScope instrumentation.Scope - InstrumentationLibrary instrumentation.Library + InstrumentationLibrary instrumentation.Library // Deprecated: use InstrumentationScope instead. } // SpanStubFromReadOnlySpan returns a SpanStub populated from ro. From 7b47d8b80ce9ba517208623b3973da56fbdc76f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 17 Jul 2024 16:02:07 +0200 Subject: [PATCH 5/6] sdk/instrumentation: Fix Library type deprecation --- sdk/instrumentation/library.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/instrumentation/library.go b/sdk/instrumentation/library.go index f4d1857c4f4..f2cdf3c6518 100644 --- a/sdk/instrumentation/library.go +++ b/sdk/instrumentation/library.go @@ -4,5 +4,6 @@ package instrumentation // import "go.opentelemetry.io/otel/sdk/instrumentation" // Library represents the instrumentation library. -// Deprecated: please use Scope instead. +// +// Deprecated: use [Scope] instead. type Library = Scope From 843af9a449654e3eed870a30aac7df547ba2deb2 Mon Sep 17 00:00:00 2001 From: dmathieu Date: Wed, 17 Jul 2024 17:11:06 +0200 Subject: [PATCH 6/6] fix remaining deprecation lint issues --- bridge/opencensus/trace_test.go | 4 +- .../internal/tracetransform/span_test.go | 6 +-- sdk/trace/snapshot.go | 2 +- sdk/trace/span.go | 4 +- sdk/trace/tracetest/span.go | 38 ++++++++++--------- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/bridge/opencensus/trace_test.go b/bridge/opencensus/trace_test.go index d00fff5414f..de507442adc 100644 --- a/bridge/opencensus/trace_test.go +++ b/bridge/opencensus/trace_test.go @@ -23,6 +23,6 @@ func TestNewTraceBridge(t *testing.T) { gotSpans := exporter.GetSpans() require.Len(t, gotSpans, 1) gotSpan := gotSpans[0] - assert.Equal(t, gotSpan.InstrumentationLibrary.Name, scopeName) - assert.Equal(t, gotSpan.InstrumentationLibrary.Version, Version()) + assert.Equal(t, gotSpan.InstrumentationScope.Name, scopeName) + assert.Equal(t, gotSpan.InstrumentationScope.Version, Version()) } diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go index 152ef383ad7..50cb9e123df 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go @@ -280,7 +280,7 @@ func TestSpanData(t *testing.T) { attribute.Int64("rk2", 5), attribute.StringSlice("rk3", []string{"sv1", "sv2"}), ), - InstrumentationLibrary: instrumentation.Scope{ + InstrumentationScope: instrumentation.Scope{ Name: "go.opentelemetry.io/test/otel", Version: "v0.0.1", SchemaURL: semconv.SchemaURL, @@ -316,8 +316,8 @@ func TestSpanData(t *testing.T) { assert.Equal(t, got[0].SchemaUrl, spanData.Resource.SchemaURL()) scopeSpans := got[0].GetScopeSpans() require.Len(t, scopeSpans, 1) - assert.Equal(t, scopeSpans[0].SchemaUrl, spanData.InstrumentationLibrary.SchemaURL) - assert.Equal(t, scopeSpans[0].GetScope(), InstrumentationScope(spanData.InstrumentationLibrary)) + assert.Equal(t, scopeSpans[0].SchemaUrl, spanData.InstrumentationScope.SchemaURL) + assert.Equal(t, scopeSpans[0].GetScope(), InstrumentationScope(spanData.InstrumentationScope)) require.Len(t, scopeSpans[0].Spans, 1) actualSpan := scopeSpans[0].Spans[0] diff --git a/sdk/trace/snapshot.go b/sdk/trace/snapshot.go index 32f862790c7..d511d0f271f 100644 --- a/sdk/trace/snapshot.go +++ b/sdk/trace/snapshot.go @@ -99,7 +99,7 @@ func (s snapshot) InstrumentationScope() instrumentation.Scope { // InstrumentationLibrary returns information about the instrumentation // library that created the span. -func (s snapshot) InstrumentationLibrary() instrumentation.Library { +func (s snapshot) InstrumentationLibrary() instrumentation.Library { //nolint:staticcheck // This method needs to be define for backwards compatibility return s.instrumentationScope } diff --git a/sdk/trace/span.go b/sdk/trace/span.go index ac90f1a2600..4945f508303 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -62,7 +62,7 @@ type ReadOnlySpan interface { // InstrumentationLibrary returns information about the instrumentation // library that created the span. // Deprecated: please use InstrumentationScope instead. - InstrumentationLibrary() instrumentation.Library + InstrumentationLibrary() instrumentation.Library //nolint:staticcheck // This method needs to be define for backwards compatibility // Resource returns information about the entity that produced the span. Resource() *resource.Resource // DroppedAttributes returns the number of attributes dropped by the span @@ -642,7 +642,7 @@ func (s *recordingSpan) InstrumentationScope() instrumentation.Scope { // InstrumentationLibrary returns the instrumentation.Library associated with // the Tracer that created this span. -func (s *recordingSpan) InstrumentationLibrary() instrumentation.Library { +func (s *recordingSpan) InstrumentationLibrary() instrumentation.Library { //nolint:staticcheck // This method needs to be define for backwards compatibility s.mu.Lock() defer s.mu.Unlock() return s.tracer.instrumentationScope diff --git a/sdk/trace/tracetest/span.go b/sdk/trace/tracetest/span.go index 96415dd9a0f..cd2cc30ca2d 100644 --- a/sdk/trace/tracetest/span.go +++ b/sdk/trace/tracetest/span.go @@ -45,23 +45,25 @@ func (s SpanStubs) Snapshots() []tracesdk.ReadOnlySpan { // SpanStub is a stand-in for a Span. type SpanStub struct { - Name string - SpanContext trace.SpanContext - Parent trace.SpanContext - SpanKind trace.SpanKind - StartTime time.Time - EndTime time.Time - Attributes []attribute.KeyValue - Events []tracesdk.Event - Links []tracesdk.Link - Status tracesdk.Status - DroppedAttributes int - DroppedEvents int - DroppedLinks int - ChildSpanCount int - Resource *resource.Resource - InstrumentationScope instrumentation.Scope - InstrumentationLibrary instrumentation.Library // Deprecated: use InstrumentationScope instead. + Name string + SpanContext trace.SpanContext + Parent trace.SpanContext + SpanKind trace.SpanKind + StartTime time.Time + EndTime time.Time + Attributes []attribute.KeyValue + Events []tracesdk.Event + Links []tracesdk.Link + Status tracesdk.Status + DroppedAttributes int + DroppedEvents int + DroppedLinks int + ChildSpanCount int + Resource *resource.Resource + InstrumentationScope instrumentation.Scope + + // Deprecated: use InstrumentationScope instead. + InstrumentationLibrary instrumentation.Library //nolint:staticcheck // This method needs to be define for backwards compatibility } // SpanStubFromReadOnlySpan returns a SpanStub populated from ro. @@ -159,6 +161,6 @@ func (s spanSnapshot) InstrumentationScope() instrumentation.Scope { return s.instrumentationScope } -func (s spanSnapshot) InstrumentationLibrary() instrumentation.Library { +func (s spanSnapshot) InstrumentationLibrary() instrumentation.Library { //nolint:staticcheck // This method needs to be define for backwards compatibility return s.instrumentationScope }