diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d4babe8..0e99d350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/VERSION b/VERSION index a67b05e8..8e8b0a93 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.4 +1.18.5 diff --git a/go.mod b/go.mod index d736b70f..b9814dd8 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/launcher/version.go b/launcher/version.go index 73104619..ead33319 100644 --- a/launcher/version.go +++ b/launcher/version.go @@ -14,4 +14,4 @@ package launcher -const version = "1.18.4" +const version = "1.18.5" diff --git a/lightstep/sdk/metric/example/go.mod b/lightstep/sdk/metric/example/go.mod index e2c125f7..5a6b781d 100644 --- a/lightstep/sdk/metric/example/go.mod +++ b/lightstep/sdk/metric/example/go.mod @@ -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 ) @@ -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 diff --git a/lightstep/sdk/metric/go.mod b/lightstep/sdk/metric/go.mod index f29ba916..6fa9a0b4 100644 --- a/lightstep/sdk/metric/go.mod +++ b/lightstep/sdk/metric/go.mod @@ -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 diff --git a/lightstep/sdk/trace/exporters/otlp/otelcol/client_test.go b/lightstep/sdk/trace/exporters/otlp/otelcol/client_test.go index d9648822..94b26aa5 100644 --- a/lightstep/sdk/trace/exporters/otlp/otelcol/client_test.go +++ b/lightstep/sdk/trace/exporters/otlp/otelcol/client_test.go @@ -34,6 +34,7 @@ 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" @@ -41,6 +42,7 @@ import ( 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" ) @@ -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) @@ -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", @@ -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()) } diff --git a/lightstep/sdk/trace/exporters/otlp/otelcol/otlp.go b/lightstep/sdk/trace/exporters/otlp/otelcol/otlp.go index 2895b543..93a3048d 100644 --- a/lightstep/sdk/trace/exporters/otlp/otelcol/otlp.go +++ b/lightstep/sdk/trace/exporters/otlp/otelcol/otlp.go @@ -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) { @@ -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() @@ -72,7 +102,7 @@ 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())) @@ -80,7 +110,7 @@ func (c *client) d2pd(in []trace.ReadOnlySpan) ptrace.Traces { 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()...)) diff --git a/lightstep/sdk/trace/go.mod b/lightstep/sdk/trace/go.mod index 334c1a50..8a630c50 100644 --- a/lightstep/sdk/trace/go.mod +++ b/lightstep/sdk/trace/go.mod @@ -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 diff --git a/pipelines/go.mod b/pipelines/go.mod index 7928d34e..8870ee71 100644 --- a/pipelines/go.mod +++ b/pipelines/go.mod @@ -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 ) @@ -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