mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-03-17 20:57:51 +02:00
Allow relying on InstrumentationScope in SpanStub and fix remaining deprecation issues (#5627)
Rather than the deprecated InstrumentationLibrary This is a replacement for https://github.com/open-telemetry/opentelemetry-go/pull/3104, as after this, there is no usage of `instrumentation.Library` within the SDK anymore. --------- Co-authored-by: Robert Pająk <pellared@hotmail.com> Co-authored-by: Sam Xie <sam@samxie.me>
This commit is contained in:
parent
d4b5396f84
commit
3e17ef99d6
@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
This new module contains an OTLP exporter that transmits log telemetry using gRPC.
|
||||
This module is unstable and breaking changes may be introduced.
|
||||
See our [versioning policy](VERSIONING.md) for more information about these stability guarantees. (#5629)
|
||||
- Add `InstrumentationScope` field to `SpanStub` in `go.opentelemetry.io/otel/sdk/trace/tracetest`, as a replacement for the deprecated `InstrumentationLibrary`. (#5627)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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",
|
||||
},
|
||||
|
@ -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",
|
||||
},
|
||||
|
@ -186,6 +186,11 @@ func expectedJSON(now time.Time) string {
|
||||
}
|
||||
}
|
||||
],
|
||||
"InstrumentationScope": {
|
||||
"Name": "",
|
||||
"Version": "",
|
||||
"SchemaURL": ""
|
||||
},
|
||||
"InstrumentationLibrary": {
|
||||
"Name": "",
|
||||
"Version": "",
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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",
|
||||
},
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
@ -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,
|
||||
@ -107,7 +116,7 @@ func (s SpanStub) Snapshot() tracesdk.ReadOnlySpan {
|
||||
droppedLinks: s.DroppedLinks,
|
||||
childSpanCount: s.ChildSpanCount,
|
||||
resource: s.Resource,
|
||||
instrumentationScope: s.InstrumentationLibrary,
|
||||
instrumentationScope: scopeOrLibrary,
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user