Skip to content

Commit

Permalink
allow relying on InstrumentationScope in SpanStub
Browse files Browse the repository at this point in the history
rather than the deprecated InstrumentationLibrary
  • Loading branch information
dmathieu committed Jul 17, 2024
1 parent e3892f0 commit 813c485
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
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
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
2 changes: 1 addition & 1 deletion internal/shared/otlp/otlptrace/otlptracetest/data.go.tmpl
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
9 changes: 8 additions & 1 deletion sdk/trace/tracetest/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type SpanStub struct {
DroppedLinks int
ChildSpanCount int
Resource *resource.Resource
InstrumentationScope instrumentation.Scope
InstrumentationLibrary instrumentation.Library
}

Expand All @@ -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,
Expand All @@ -107,7 +114,7 @@ func (s SpanStub) Snapshot() tracesdk.ReadOnlySpan {
droppedLinks: s.DroppedLinks,
childSpanCount: s.ChildSpanCount,
resource: s.Resource,
instrumentationScope: s.InstrumentationLibrary,
instrumentationScope: scopeOrLibrary,
}
}

Expand Down

0 comments on commit 813c485

Please sign in to comment.