From 6eb20e4dd13f41a66a3af8a8a2717c0606476919 Mon Sep 17 00:00:00 2001 From: Chris Leavoy Date: Wed, 16 Sep 2020 15:09:27 -0400 Subject: [PATCH 1/2] backport master to otel v0.4.3 --- go.mod | 2 +- go.sum | 3 +++ lightstep/lightstep.go | 12 ++++++------ lightstep/lightstep_test.go | 27 ++++++++++++++------------- lightstep/translator.go | 30 ++++++++++++++++-------------- 5 files changed, 40 insertions(+), 34 deletions(-) diff --git a/go.mod b/go.mod index 8d1a802..e3890b9 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/shirou/gopsutil v2.20.3+incompatible // indirect github.com/stretchr/testify v1.4.0 github.com/uudashr/gocognit v1.0.0 // indirect - go.opentelemetry.io/otel v0.6.0 + go.opentelemetry.io/otel v0.4.3 golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect google.golang.org/genproto v0.0.0-20200413115906-b5235f65be36 // indirect diff --git a/go.sum b/go.sum index f23e880..5c50171 100644 --- a/go.sum +++ b/go.sum @@ -285,10 +285,13 @@ go.opentelemetry.io/otel v0.2.3 h1:o97YpRYk0PyhCyuanlJY0DepUgAlyzl3rJ+4kb+456c= go.opentelemetry.io/otel v0.2.3/go.mod h1:OgNpQOjrlt33Ew6Ds0mGjmcTQg/rhUctsbkRdk/g1fw= go.opentelemetry.io/otel v0.4.2 h1:nT+GOqqRR1cIY92xmo1DeiXLHtIlXH1KLRgnsnhuNrs= go.opentelemetry.io/otel v0.4.2/go.mod h1:OgNpQOjrlt33Ew6Ds0mGjmcTQg/rhUctsbkRdk/g1fw= +go.opentelemetry.io/otel v0.4.3 h1:CroUX/0O1ZDcF0iWOO8gwYFWb5EbdSF0/C1yosO+Vhs= +go.opentelemetry.io/otel v0.4.3/go.mod h1:jzBIgIzK43Iu1BpDAXwqOd6UPsSAk+ewVZ5ofSXw4Ek= go.opentelemetry.io/otel v0.5.0 h1:tdIR1veg/z+VRJaw/6SIxz+QX3l+m+BDleYLTs+GC1g= go.opentelemetry.io/otel v0.5.0/go.mod h1:jzBIgIzK43Iu1BpDAXwqOd6UPsSAk+ewVZ5ofSXw4Ek= go.opentelemetry.io/otel v0.6.0 h1:+vkHm/XwJ7ekpISV2Ixew93gCrxTbuwTF5rSewnLLgw= go.opentelemetry.io/otel v0.6.0/go.mod h1:jzBIgIzK43Iu1BpDAXwqOd6UPsSAk+ewVZ5ofSXw4Ek= +go.opentelemetry.io/otel v0.11.0 h1:IN2tzQa9Gc4ZVKnTaMbPVcHjvzOdg5n9QfnmlqiET7E= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= diff --git a/lightstep/lightstep.go b/lightstep/lightstep.go index a06b4e0..e74443b 100644 --- a/lightstep/lightstep.go +++ b/lightstep/lightstep.go @@ -8,8 +8,8 @@ import ( "github.com/opentracing/opentracing-go/log" - "go.opentelemetry.io/otel/api/kv" - apitrace "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/api/core" + "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/resource" @@ -189,11 +189,11 @@ func lightStepSpan(data *trace.SpanData) *ls.RawSpan { return lsSpan } -func convertTraceID(id apitrace.ID) uint64 { +func convertTraceID(id core.TraceID) uint64 { return binary.BigEndian.Uint64(id[8:]) } -func convertSpanID(id apitrace.SpanID) uint64 { +func convertSpanID(id core.SpanID) uint64 { return binary.BigEndian.Uint64(id[:]) } @@ -208,7 +208,7 @@ func toLogRecords(input []trace.Event) []opentracing.LogRecord { return output } -func toTags(input []kv.KeyValue, resource *resource.Resource) map[string]interface{} { +func toTags(input []core.KeyValue, resource *resource.Resource) map[string]interface{} { output := make(map[string]interface{}) for iter := resource.Iter(); iter.Next(); { kv := iter.Label() @@ -227,7 +227,7 @@ func toLogRecord(ev trace.Event) opentracing.LogRecord { } } -func toFields(name string, input []kv.KeyValue) []log.Field { +func toFields(name string, input []core.KeyValue) []log.Field { output := make([]log.Field, 0, len(input)+1) output = append(output, log.String("name", name)) for _, value := range input { diff --git a/lightstep/lightstep_test.go b/lightstep/lightstep_test.go index 3c9b8b1..c4dfdf5 100644 --- a/lightstep/lightstep_test.go +++ b/lightstep/lightstep_test.go @@ -8,8 +8,9 @@ import ( "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/log" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/otel/api/kv" - apitrace "go.opentelemetry.io/otel/api/trace" + "go.opentelemetry.io/otel/api/core" + "go.opentelemetry.io/otel/api/key" + "go.opentelemetry.io/otel/sdk/export/trace" "go.opentelemetry.io/otel/sdk/resource" ) @@ -18,8 +19,8 @@ func TestExport(t *testing.T) { assert := assert.New(t) now := time.Now().Round(time.Microsecond) - traceID, _ := apitrace.IDFromHex("0102030405060708090a0b0c0d0e0f10") - spanID, _ := apitrace.SpanIDFromHex("0102030405060708") + traceID, _ := core.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") + spanID, _ := core.SpanIDFromHex("0102030405060708") expectedTraceID := uint64(0x90a0b0c0d0e0f10) expectedSpanID := uint64(0x102030405060708) @@ -32,7 +33,7 @@ func TestExport(t *testing.T) { { name: "root span", data: &trace.SpanData{ - SpanContext: apitrace.SpanContext{ + SpanContext: core.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -40,11 +41,11 @@ func TestExport(t *testing.T) { StartTime: now, EndTime: now, Resource: resource.New( - kv.String("R1", "V1"), + key.String("R1", "V1"), ), - Attributes: []kv.KeyValue{ - kv.String("A", "B"), - kv.String("C", "D"), + Attributes: []core.KeyValue{ + key.String("A", "B"), + key.String("C", "D"), }, }, want: &ls.RawSpan{ @@ -65,7 +66,7 @@ func TestExport(t *testing.T) { { name: "with events", data: &trace.SpanData{ - SpanContext: apitrace.SpanContext{ + SpanContext: core.SpanContext{ TraceID: traceID, SpanID: spanID, }, @@ -75,14 +76,14 @@ func TestExport(t *testing.T) { MessageEvents: []trace.Event{ trace.Event{ Name: "myevent", - Attributes: []kv.KeyValue{ - kv.String("A", "B"), + Attributes: []core.KeyValue{ + key.String("A", "B"), }, Time: now, }, }, Resource: resource.New( - kv.String("R1", "V1"), + key.String("R1", "V1"), ), }, want: &ls.RawSpan{ diff --git a/lightstep/translator.go b/lightstep/translator.go index 86cbd44..e08a325 100644 --- a/lightstep/translator.go +++ b/lightstep/translator.go @@ -6,11 +6,13 @@ import ( "errors" "time" + "go.opentelemetry.io/otel/api/key" "go.opentelemetry.io/otel/sdk/resource" + "go.opentelemetry.io/otel/api/core" + tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1" "github.com/golang/protobuf/ptypes/timestamp" - "go.opentelemetry.io/otel/api/kv" apitrace "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/sdk/export/trace" ) @@ -42,8 +44,8 @@ func oTelSpanKind(kind tracepb.Span_SpanKind) apitrace.SpanKind { // Creates an OpenTelemetry SpanContext from information in an OC Span. // Note that the OC Span has no equivalent to TraceFlags field in the // OpenTelemetry SpanContext type. -func spanContext(traceID []byte, spanID []byte) apitrace.SpanContext { - ctx := apitrace.SpanContext{} +func spanContext(traceID []byte, spanID []byte) core.SpanContext { + ctx := core.SpanContext{} if traceID != nil { copy(ctx.TraceID[:], traceID[:]) } @@ -54,26 +56,26 @@ func spanContext(traceID []byte, spanID []byte) apitrace.SpanContext { } // Create []kv.KeyValue attributes from an OC *Span_Attributes -func createOTelAttributes(attributes *tracepb.Span_Attributes) []kv.KeyValue { +func createOTelAttributes(attributes *tracepb.Span_Attributes) []core.KeyValue { if attributes == nil || attributes.AttributeMap == nil { return nil } - oTelAttrs := make([]kv.KeyValue, len(attributes.AttributeMap)) + oTelAttrs := make([]core.KeyValue, len(attributes.AttributeMap)) i := 0 - for key, attributeValue := range attributes.AttributeMap { - var keyValue kv.KeyValue - key := kv.Key(key) + for k, attributeValue := range attributes.AttributeMap { + var keyValue core.KeyValue + k := core.Key(k) switch value := attributeValue.Value.(type) { case *tracepb.AttributeValue_StringValue: - keyValue = key.String(attributeValueAsString(attributeValue)) + keyValue = k.String(attributeValueAsString(attributeValue)) case *tracepb.AttributeValue_BoolValue: - keyValue = key.Bool(value.BoolValue) + keyValue = k.Bool(value.BoolValue) case *tracepb.AttributeValue_IntValue: - keyValue = key.Int64(value.IntValue) + keyValue = k.Int64(value.IntValue) case *tracepb.AttributeValue_DoubleValue: - keyValue = key.Float64(value.DoubleValue) + keyValue = k.Float64(value.DoubleValue) } oTelAttrs[i] = keyValue i++ @@ -169,10 +171,10 @@ func spanResource(span *tracepb.Span) *resource.Resource { if span.Resource == nil { return nil } - attrs := make([]kv.KeyValue, len(span.Resource.Labels)) + attrs := make([]core.KeyValue, len(span.Resource.Labels)) i := 0 for k, v := range span.Resource.Labels { - attrs[i] = kv.String(k, v) + attrs[i] = key.String(k, v) i++ } return resource.New(attrs...) From 8ae01fe635c791db40b872518d9723c7fd8ee63e Mon Sep 17 00:00:00 2001 From: Chris Leavoy Date: Thu, 17 Sep 2020 08:16:19 -0400 Subject: [PATCH 2/2] change module name --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e3890b9..cb86a44 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/lightstep/opentelemetry-exporter-go +module github.com/InVisionApp/opentelemetry-lightstep-exporter-go go 1.13