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

Allow relying on InstrumentationScope in SpanStub and fix remaining deprecation issues #5627

Merged
merged 8 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -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)
- Add `InstrumentationScope` field to `SpanStub` in `go.opentelemetry.io/otel/sdk/trace/tracetest`, as a replacement for the deprecated `InstrumentationLibrary`. (#5627)

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions bridge/opencensus/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
5 changes: 5 additions & 0 deletions exporters/stdout/stdouttrace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ func expectedJSON(now time.Time) string {
}
}
],
"InstrumentationScope": {
"Name": "",
"Version": "",
"SchemaURL": ""
},
"InstrumentationLibrary": {
"Name": "",
"Version": "",
Expand Down
6 changes: 3 additions & 3 deletions exporters/zipkin/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,15 +1015,15 @@ func TestTagsTransformation(t *testing.T) {
{
name: "instrLib-empty",
data: tracetest.SpanStub{
InstrumentationLibrary: instrumentation.Library{},
InstrumentationScope: instrumentation.Scope{},
},
want: nil,
},
{
name: "instrLib-noversion",
data: tracetest.SpanStub{
Attributes: []attribute.KeyValue{},
InstrumentationLibrary: instrumentation.Library{
InstrumentationScope: instrumentation.Scope{
Name: instrLibName,
},
},
Expand All @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
3 changes: 2 additions & 1 deletion sdk/instrumentation/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion sdk/trace/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
45 changes: 27 additions & 18 deletions sdk/trace/tracetest/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +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
InstrumentationLibrary instrumentation.Library
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.
Expand All @@ -85,12 +88,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,
Expand All @@ -107,7 +116,7 @@ func (s SpanStub) Snapshot() tracesdk.ReadOnlySpan {
droppedLinks: s.DroppedLinks,
childSpanCount: s.ChildSpanCount,
resource: s.Resource,
instrumentationScope: s.InstrumentationLibrary,
instrumentationScope: scopeOrLibrary,
}
}

Expand Down Expand Up @@ -152,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
}