Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Merge pull request #1 from InVisionApp/backport
Browse files Browse the repository at this point in the history
backport master to otel v0.4.3
  • Loading branch information
Chris Leavoy authored Oct 1, 2020
2 parents 338f356 + 8ae01fe commit eca2786
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/lightstep/opentelemetry-exporter-go
module github.com/InVisionApp/opentelemetry-lightstep-exporter-go

go 1.13

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
12 changes: 6 additions & 6 deletions lightstep/lightstep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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[:])
}

Expand All @@ -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()
Expand All @@ -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 {
Expand Down
27 changes: 14 additions & 13 deletions lightstep/lightstep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand All @@ -32,19 +33,19 @@ func TestExport(t *testing.T) {
{
name: "root span",
data: &trace.SpanData{
SpanContext: apitrace.SpanContext{
SpanContext: core.SpanContext{
TraceID: traceID,
SpanID: spanID,
},
Name: "/test",
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{
Expand All @@ -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,
},
Expand All @@ -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{
Expand Down
30 changes: 16 additions & 14 deletions lightstep/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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[:])
}
Expand All @@ -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++
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit eca2786

Please sign in to comment.