Skip to content

Commit

Permalink
otel: update spans transform helper to use new API
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Dmitrichenko <errordeveloper@gmail.com>
  • Loading branch information
errordeveloper committed Dec 6, 2022
1 parent 3896142 commit 9a693bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
17 changes: 0 additions & 17 deletions util/tracing/transform/instrumentation.go

This file was deleted.

33 changes: 14 additions & 19 deletions util/tracing/transform/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"go.opentelemetry.io/otel/attribute"
"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/trace"
Expand All @@ -18,30 +17,30 @@ const (
maxMessageEventsPerSpan = 128
)

// Spans transforms slice of OTLP ResourceSpan into a slice of SpanSnapshots.
func Spans(sdl []*tracepb.ResourceSpans) []tracesdk.ReadOnlySpan {
if len(sdl) == 0 {
// Spans transforms slice of OTLP ResourceSpan into a slice of ReadOnlySpans.
func Spans(resourceSpans []*tracepb.ResourceSpans) []tracesdk.ReadOnlySpan {
if len(resourceSpans) == 0 {
return nil
}

var out []tracesdk.ReadOnlySpan

for _, sd := range sdl {
if sd == nil {
for _, resourceSpan := range resourceSpans {
if resourceSpan == nil {
continue
}

for _, sdi := range sd.InstrumentationLibrarySpans {
sda := make([]tracesdk.ReadOnlySpan, len(sdi.Spans))
for i, s := range sdi.Spans {
sda[i] = &readOnlySpan{
for _, scopeSpan := range resourceSpan.ScopeSpans {
spans := make([]tracesdk.ReadOnlySpan, len(scopeSpan.Spans))
for i, s := range scopeSpan.Spans {
spans[i] = &readOnlySpan{
pb: s,
il: sdi.InstrumentationLibrary,
resource: sd.Resource,
schemaURL: sd.SchemaUrl,
scope: scopeSpan.Scope,
resource: resourceSpan.Resource,
schemaURL: resourceSpan.SchemaUrl,
}
}
out = append(out, sda...)
out = append(out, spans...)
}
}

Expand All @@ -53,7 +52,7 @@ type readOnlySpan struct {
tracesdk.ReadOnlySpan

pb *tracepb.Span
il *v11.InstrumentationLibrary
scope *v11.InstrumentationScope
resource *v1.Resource
schemaURL string
}
Expand Down Expand Up @@ -122,10 +121,6 @@ func (s *readOnlySpan) Status() tracesdk.Status {
}
}

func (s *readOnlySpan) InstrumentationLibrary() instrumentation.Library {
return instrumentationLibrary(s.il)
}

// Resource returns information about the entity that produced the span.
func (s *readOnlySpan) Resource() *resource.Resource {
if s.resource == nil {
Expand Down

0 comments on commit 9a693bf

Please sign in to comment.