Skip to content

Commit

Permalink
Set Schema URL when exporting traces to OTLP
Browse files Browse the repository at this point in the history
We previously were recording the Schema URL but were not setting
the recorded value when exporting. This change now uses the recorded
value when exporting to OTLP.
  • Loading branch information
tigrannajaryan committed Sep 14, 2021
1 parent ec26b55 commit 25c9e39
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions exporters/otlp/otlptrace/internal/tracetransform/span.go
Expand Up @@ -60,6 +60,7 @@ func Spans(sdl []tracesdk.ReadOnlySpan) []*tracepb.ResourceSpans {
ils = &tracepb.InstrumentationLibrarySpans{
InstrumentationLibrary: InstrumentationLibrary(sd.InstrumentationLibrary()),
Spans: []*tracepb.Span{},
SchemaUrl: sd.InstrumentationLibrary().SchemaURL,
}
}
ils.Spans = append(ils.Spans, span(sd))
Expand All @@ -72,6 +73,7 @@ func Spans(sdl []tracesdk.ReadOnlySpan) []*tracepb.ResourceSpans {
rs = &tracepb.ResourceSpans{
Resource: Resource(sd.Resource()),
InstrumentationLibrarySpans: []*tracepb.InstrumentationLibrarySpans{ils},
SchemaUrl: sd.Resource().SchemaURL(),
}
rsm[rKey] = rs
continue
Expand Down
20 changes: 14 additions & 6 deletions exporters/otlp/otlptrace/internal/tracetransform/span_test.go
Expand Up @@ -25,14 +25,14 @@ import (
"google.golang.org/protobuf/proto"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"

"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"go.opentelemetry.io/otel/trace"
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
)

func TestSpanKind(t *testing.T) {
Expand Down Expand Up @@ -266,10 +266,16 @@ func TestSpanData(t *testing.T) {
DroppedAttributes: 1,
DroppedEvents: 2,
DroppedLinks: 3,
Resource: resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5), attribute.StringSlice("rk3", []string{"sv1", "sv2"})),
Resource: resource.NewWithAttributes(
"http://example.com/custom-resource-schema",
attribute.String("rk1", "rv1"),
attribute.Int64("rk2", 5),
attribute.StringSlice("rk3", []string{"sv1", "sv2"}),
),
InstrumentationLibrary: instrumentation.Library{
Name: "go.opentelemetry.io/test/otel",
Version: "v0.0.1",
Name: "go.opentelemetry.io/test/otel",
Version: "v0.0.1",
SchemaURL: semconv.SchemaURL,
},
}

Expand Down Expand Up @@ -298,8 +304,10 @@ func TestSpanData(t *testing.T) {
require.Len(t, got, 1)

assert.Equal(t, got[0].GetResource(), Resource(spanData.Resource))
assert.Equal(t, got[0].SchemaUrl, spanData.Resource.SchemaURL())
ilSpans := got[0].GetInstrumentationLibrarySpans()
require.Len(t, ilSpans, 1)
assert.Equal(t, ilSpans[0].SchemaUrl, spanData.InstrumentationLibrary.SchemaURL)
assert.Equal(t, ilSpans[0].GetInstrumentationLibrary(), InstrumentationLibrary(spanData.InstrumentationLibrary))
require.Len(t, ilSpans[0].Spans, 1)
actualSpan := ilSpans[0].Spans[0]
Expand Down

0 comments on commit 25c9e39

Please sign in to comment.