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

Translate enums SpanKind and StatusCode #495

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Unreleased

## [1.18.5](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.4) - 2023-06-26)

- Correct the translation of Span StatusCode. [#495](https://github.com/lightstep/otel-launcher-go/pull/495)

## [1.18.4](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.4) - 2023-06-26)

- Disable self-tracing, enable self-metrics, and make these optional behaviors. Bugfix in span event timestamps. [#494](https://github.com/lightstep/otel-launcher-go/pull/494)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.18.4
1.18.5
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/lightstep/otel-launcher-go
go 1.18

require (
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.4
github.com/lightstep/otel-launcher-go/pipelines v1.18.4
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.5
github.com/lightstep/otel-launcher-go/pipelines v1.18.5
github.com/sethvargo/go-envconfig v0.8.3
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.16.0
Expand Down Expand Up @@ -42,8 +42,8 @@ require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/lightstep/go-expohisto v1.0.0 // indirect
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.4 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4 // indirect
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.5 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
Expand Down
2 changes: 1 addition & 1 deletion launcher/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

package launcher

const version = "1.18.4"
const version = "1.18.5"
4 changes: 2 additions & 2 deletions lightstep/sdk/metric/example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/example
go 1.18

require (
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.4
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.5
github.com/lightstep/otel-launcher-go/pipelines v1.8.0
go.opentelemetry.io/proto/otlp v0.20.0
)
Expand Down Expand Up @@ -35,7 +35,7 @@ require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/lightstep/go-expohisto v1.0.0 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion lightstep/sdk/metric/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.9
github.com/lightstep/go-expohisto v1.0.0
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector v0.79.0
go.opentelemetry.io/collector/component v0.79.0
Expand Down
102 changes: 52 additions & 50 deletions lightstep/sdk/trace/exporters/otlp/otelcol/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ import (
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receivertest"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
resourcev1 "go.opentelemetry.io/proto/otlp/resource/v1"
tracev1 "go.opentelemetry.io/proto/otlp/trace/v1"

// "google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -171,9 +173,10 @@ func (t *clientTestSuite) TestSpan() {
ctx := context.Background()

tracer := t.sdk.Tracer("test-tracer")
_, span := tracer.Start(ctx, "ExecuteRequest")
_, span := tracer.Start(ctx, "ExecuteRequest", trace.WithSpanKind(trace.SpanKindServer))
span.SetAttributes(attribute.String("test-attribute-1", "test-value-1"))
span.AddEvent("test event", trace.WithAttributes(attribute.String("test-event-attribute-1", "test-event-value-1")))
span.SetStatus(codes.Error, "failed")
span.End()

_ = t.sdk.Shutdown(ctx)
Expand Down Expand Up @@ -225,9 +228,12 @@ func (t *clientTestSuite) TestSpan() {
&tracev1.Span{
SpanId: []byte(unqSpanID),
TraceId: []byte(unqTraceID),
Kind: tracev1.Span_SPAN_KIND_INTERNAL,
Kind: tracev1.Span_SPAN_KIND_SERVER,
Name: "ExecuteRequest",
Status: &tracev1.Status{},
Status: &tracev1.Status{
Code: tracev1.Status_STATUS_CODE_ERROR,
Message: "failed",
},
Attributes: []*commonpb.KeyValue{
&commonpb.KeyValue{
Key: "test-attribute-1",
Expand Down Expand Up @@ -279,67 +285,63 @@ func (t *clientTestSuite) TestD2PD() {
ctx := context.Background()

tracer := t.sdk.Tracer("test-tracer")
_, span := tracer.Start(ctx, "ExecuteRequest")
_, span := tracer.Start(ctx, "ExecuteRequest", trace.WithSpanKind(trace.SpanKindClient))
span.SetAttributes(attribute.String("test-attribute-1", "test-value-1"))
span.AddEvent("test event", trace.WithAttributes(attribute.String("test-event-attribute-1", "test-event-value-1")))
span.SetStatus(codes.Ok, "this is suppressed")

_, childSpan := tracer.Start(ctx, "child")
childSpan.SetAttributes(attribute.String("test-attribute-2", "test-value-2"))
childSpan.AddEvent("child test event", trace.WithAttributes(attribute.String("test-child-event-attribute-2", "test-child-event-value-2")))
childSpan.End()
_, child := tracer.Start(ctx, "child", trace.WithSpanKind(trace.SpanKindInternal))
child.SetAttributes(attribute.String("test-attribute-2", "test-value-2"))
child.AddEvent("child test event", trace.WithAttributes(attribute.String("test-child-event-attribute-2", "test-child-event-value-2")))
child.End()

span.End()

_ = t.sdk.Shutdown(ctx)
t.NoError(t.sdk.Shutdown(ctx))

t.Equal(1, len(t.sink.AllTraces()))

t.assertTimestamps()

roSpan := span.(sdktrace.ReadOnlySpan)
c := client{}
roSpanArr := []sdktrace.ReadOnlySpan{roSpan}
ptraceObj := c.d2pd(roSpanArr)

actualSpan := ptraceObj.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0)
t.Equal(uint32(roSpan.DroppedAttributes()), actualSpan.DroppedAttributesCount())
t.Equal(uint32(roSpan.DroppedLinks()), actualSpan.DroppedLinksCount())
t.Equal(uint32(roSpan.DroppedEvents()), actualSpan.DroppedEventsCount())
t.Equal(uint32(roSpan.SpanKind()), uint32(actualSpan.Kind()))
t.Equal(roSpan.SpanContext().TraceState().String(), actualSpan.TraceState().AsRaw())
t.Equal(ptrace.StatusCode(roSpan.Status().Code), actualSpan.Status().Code())
t.Equal(roSpan.Status().Description, actualSpan.Status().Message())

for _, attr := range roSpan.Attributes() {
actualVal, ok := actualSpan.Attributes().Get(string(attr.Key))
ptraceObj := c.d2pd([]sdktrace.ReadOnlySpan{
span.(sdktrace.ReadOnlySpan),
child.(sdktrace.ReadOnlySpan),
})

parentSpan := ptraceObj.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0)
t.Equal(uint32(0), parentSpan.DroppedAttributesCount())
t.Equal(uint32(0), parentSpan.DroppedLinksCount())
t.Equal(uint32(0), parentSpan.DroppedEventsCount())
t.Equal(ptrace.SpanKindClient, parentSpan.Kind())
t.Equal("", parentSpan.TraceState().AsRaw())
t.Equal(ptrace.StatusCodeOk, parentSpan.Status().Code())
t.Equal("", parentSpan.Status().Message()) // status is suppressed by the SDK

t.Equal(1, parentSpan.Attributes().Len())

sattr, _ := parentSpan.Attributes().Get("test-attribute-1")
t.Equal("test-value-1", sattr.Str())

t.Equal(1, parentSpan.Events().Len())

event := span.(sdktrace.ReadOnlySpan).Events()[0]
parentEvent := parentSpan.Events().At(0)
t.Equal(event.Time.UnixNano(), parentEvent.Timestamp().AsTime().UnixNano())
t.Equal(event.Name, parentEvent.Name())
t.Equal(uint32(0), parentEvent.DroppedAttributesCount())

for _, attr := range event.Attributes {
parentEventVal, ok := parentEvent.Attributes().Get(string(attr.Key))
t.True(ok)
t.Equal(attr.Value.AsString(), actualVal.AsString())
t.Equal(attr.Value.AsString(), parentEventVal.AsString())
}

for i, event := range roSpan.Events() {
actualEvent := actualSpan.Events().At(i)
t.Equal(event.Time.Nanosecond(), actualEvent.Timestamp().AsTime().Nanosecond())
t.Equal(event.Name, actualEvent.Name())
t.Equal(uint32(event.DroppedAttributeCount), actualEvent.DroppedAttributesCount())
childSpan := ptraceObj.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(1)
t.Equal(ptrace.SpanKindInternal, childSpan.Kind())
t.Equal(ptrace.StatusCodeUnset, childSpan.Status().Code())

for _, attr := range event.Attributes {
actualEventVal, ok := actualEvent.Attributes().Get(string(attr.Key))
t.True(ok)
t.Equal(attr.Value.AsString(), actualEventVal.AsString())
}
}

for i, link := range roSpan.Links() {
actualLink := actualSpan.Links().At(i)
t.Equal(link.DroppedAttributeCount, actualLink.DroppedAttributesCount())
t.Equal(link.SpanContext.SpanID(), actualLink.SpanID())
t.Equal(link.SpanContext.TraceID(), actualLink.TraceID())
t.Equal(link.SpanContext.TraceState().String(), actualLink.TraceState().AsRaw())

for _, attr := range link.Attributes {
actualLinkVal, ok := actualLink.Attributes().Get(string(attr.Key))
t.True(ok)
t.Equal(attr.Value.AsString(), actualLinkVal.AsString())
}
}
t.Equal(1, childSpan.Attributes().Len())
sattr, _ = childSpan.Attributes().Get("test-attribute-2")
t.Equal("test-value-2", sattr.Str())
}
34 changes: 32 additions & 2 deletions lightstep/sdk/trace/exporters/otlp/otelcol/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/sdk/trace"
apitrace "go.opentelemetry.io/otel/trace"
)

func copyEvents(dest ptrace.SpanEventSlice, events []trace.Event) {
Expand All @@ -45,6 +47,34 @@ func copyLinks(dest ptrace.SpanLinkSlice, links []trace.Link) {
}
}

func translateSpanStatusCode(in codes.Code) ptrace.StatusCode {
switch in {
case codes.Error:
return ptrace.StatusCodeError
case codes.Ok:
return ptrace.StatusCodeOk
default:
return ptrace.StatusCodeUnset
}
}

func translateSpanKind(in apitrace.SpanKind) ptrace.SpanKind {
switch in {
case apitrace.SpanKindInternal:
return ptrace.SpanKindInternal
case apitrace.SpanKindServer:
return ptrace.SpanKindServer
case apitrace.SpanKindClient:
return ptrace.SpanKindClient
case apitrace.SpanKindProducer:
return ptrace.SpanKindProducer
case apitrace.SpanKindConsumer:
return ptrace.SpanKindConsumer
default:
return ptrace.SpanKindUnspecified
}
}

func (c *client) d2pd(in []trace.ReadOnlySpan) ptrace.Traces {
out := ptrace.NewTraces()

Expand Down Expand Up @@ -72,15 +102,15 @@ func (c *client) d2pd(in []trace.ReadOnlySpan) ptrace.Traces {
s.SetDroppedAttributesCount(uint32(tr.DroppedAttributes()))
s.SetDroppedEventsCount(uint32(tr.DroppedEvents()))
s.SetDroppedLinksCount(uint32(tr.DroppedLinks()))
s.SetKind(ptrace.SpanKind(tr.SpanKind()))
s.SetKind(translateSpanKind(tr.SpanKind()))
s.SetName(tr.Name())
s.SetParentSpanID(pcommon.SpanID(tr.Parent().SpanID()))
s.SetSpanID(pcommon.SpanID(tr.SpanContext().SpanID()))
s.SetStartTimestamp(pcommon.NewTimestampFromTime(tr.StartTime()))
s.SetEndTimestamp(pcommon.NewTimestampFromTime(tr.EndTime()))
s.SetTraceID(pcommon.TraceID(tr.SpanContext().TraceID()))
s.TraceState().FromRaw(tr.SpanContext().TraceState().String())
s.Status().SetCode(ptrace.StatusCode(tr.Status().Code))
s.Status().SetCode(translateSpanStatusCode(tr.Status().Code))
s.Status().SetMessage(tr.Status().Description)

internal.CopyAttributes(s.Attributes(), attribute.NewSet(tr.Attributes()...))
Expand Down
2 changes: 1 addition & 1 deletion lightstep/sdk/trace/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/f5/otel-arrow-adapter v0.0.0-20230612212022-445aac7c6ae8
github.com/google/go-cmp v0.5.9
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector v0.79.0
go.opentelemetry.io/collector/component v0.79.0
Expand Down
6 changes: 3 additions & 3 deletions pipelines/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ require (
)

require (
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.4
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.4
github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.5
github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.5
go.opentelemetry.io/collector v0.79.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.39.0
)
Expand Down Expand Up @@ -79,7 +79,7 @@ require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/lightstep/go-expohisto v1.0.0 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4 // indirect
github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.5 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand Down