Skip to content

Commit

Permalink
Do not strip leading 0s from traceIds and spanIds if the span source …
Browse files Browse the repository at this point in the history
…is jaeger (#4671) (#4811)

* Do not strip leading 0s from traceIds and spanIds if the span source is Jaeger. Jager is in the process of doing the same.

* Added Jaeger trace/span id formatting change to changelog
# Conflicts:
#	changelogs/head.asciidoc

Co-authored-by: Tobias Stadler <ts.stadler@gmx.de>
  • Loading branch information
axw and tobiasstadler committed Feb 19, 2021
1 parent 0554049 commit 11591d2
Show file tree
Hide file tree
Showing 23 changed files with 108 additions and 140 deletions.
44 changes: 6 additions & 38 deletions processor/otel/consumer.go
Expand Up @@ -19,7 +19,6 @@ package otel

import (
"context"
"encoding/binary"
"fmt"
"net"
"net/url"
Expand Down Expand Up @@ -93,21 +92,14 @@ func (c *Consumer) convertSpan(otelSpan pdata.Span, metadata model.Metadata, out

root := !otelSpan.ParentSpanID().IsValid()

var parentID, spanID, traceID string
if strings.HasPrefix(metadata.Service.Agent.Name, "Jaeger") {
if !root {
parentID = formatJaegerSpanID(otelSpan.ParentSpanID())
}
traceID = formatJaegerTraceID(otelSpan.TraceID())
spanID = formatJaegerSpanID(otelSpan.SpanID())
} else {
if !root {
parentID = otelSpan.ParentSpanID().HexString()
}
traceID = otelSpan.TraceID().HexString()
spanID = otelSpan.SpanID().HexString()
var parentID string
if !root {
parentID = otelSpan.ParentSpanID().HexString()
}

traceID := otelSpan.TraceID().HexString()
spanID := otelSpan.SpanID().HexString()

startTime := pdata.UnixNanoToTime(otelSpan.StartTime())
endTime := pdata.UnixNanoToTime(otelSpan.EndTime())
var durationMillis float64
Expand Down Expand Up @@ -629,30 +621,6 @@ func truncate(s string) string {
return s
}

// formatJaegerTraceID returns the traceID as string in Jaeger format (hexadecimal without leading zeros)
func formatJaegerTraceID(traceID pdata.TraceID) string {
if !traceID.IsValid() {
return ""
}
bytes := traceID.Bytes()
jaegerTraceIDHigh := binary.BigEndian.Uint64(bytes[:8])
jaegerTraceIDLow := binary.BigEndian.Uint64(bytes[8:])
if jaegerTraceIDHigh == 0 {
return fmt.Sprintf("%x", jaegerTraceIDLow)
}
return fmt.Sprintf("%x%016x", jaegerTraceIDHigh, jaegerTraceIDLow)
}

// formatJaegerSpanID returns the spanID as string in Jaeger format (hexadecimal without leading zeros)
func formatJaegerSpanID(spanID pdata.SpanID) string {
if !spanID.IsValid() {
return ""
}
bytes := spanID.Bytes()
jaegerSpanID := binary.BigEndian.Uint64(bytes[:])
return fmt.Sprintf("%x", jaegerSpanID)
}

func schemeDefaultPort(scheme string) int {
switch scheme {
case "http":
Expand Down
4 changes: 2 additions & 2 deletions processor/otel/consumer_test.go
Expand Up @@ -178,8 +178,8 @@ func TestConsumer_JaegerTraceID(t *testing.T) {
require.NoError(t, (&Consumer{Reporter: reporter}).ConsumeTraces(context.Background(), traces))

require.Len(t, transformables, 2)
assert.Equal(t, "46467830", transformables[0].(*model.Transaction).TraceID)
assert.Equal(t, "464678300000000046467830", transformables[1].(*model.Transaction).TraceID)
assert.Equal(t, "00000000000000000000000046467830", transformables[0].(*model.Transaction).TraceID)
assert.Equal(t, "00000000464678300000000046467830", transformables[1].(*model.Transaction).TraceID)
}

func TestConsumer_JaegerTransaction(t *testing.T) {
Expand Down
Expand Up @@ -102,7 +102,7 @@
"name": "host-abc"
},
"parent": {
"id": "1"
"id": "0000000000000001"
},
"processor": {
"event": "span",
Expand All @@ -128,7 +128,7 @@
"us": 1576500418000768
},
"trace": {
"id": "10000000000000001"
"id": "00000000000000010000000000000001"
}
}
]
Expand Down
Expand Up @@ -25,13 +25,13 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
},
"transaction": {
"duration": {
"us": 0
},
"id": "41414646",
"id": "0000000041414646",
"result": "Success",
"sampled": true,
"type": "custom"
Expand Down
Expand Up @@ -25,13 +25,13 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
},
"transaction": {
"duration": {
"us": 0
},
"id": "41414646",
"id": "0000000041414646",
"result": "Success",
"sampled": true,
"type": "custom"
Expand Down
4 changes: 2 additions & 2 deletions processor/otel/test_approved/metadata_jaeger.approved.json
Expand Up @@ -38,13 +38,13 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
},
"transaction": {
"duration": {
"us": 0
},
"id": "41414646",
"id": "0000000041414646",
"result": "Success",
"sampled": true,
"type": "custom"
Expand Down
6 changes: 3 additions & 3 deletions processor/otel/test_approved/span_jaeger_custom.approved.json
Expand Up @@ -16,7 +16,7 @@
"name": "host-abc"
},
"parent": {
"id": "58585858"
"id": "0000000058585858"
},
"processor": {
"event": "span",
Expand All @@ -35,15 +35,15 @@
"duration": {
"us": 79000000
},
"id": "41414646",
"id": "0000000041414646",
"name": "",
"type": "custom"
},
"timestamp": {
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions processor/otel/test_approved/span_jaeger_db.approved.json
Expand Up @@ -23,7 +23,7 @@
"component": "foo"
},
"parent": {
"id": "58585858"
"id": "0000000058585858"
},
"processor": {
"event": "span",
Expand Down Expand Up @@ -57,7 +57,7 @@
"duration": {
"us": 79000000
},
"id": "41414646",
"id": "0000000041414646",
"name": "",
"subtype": "mysql",
"type": "db"
Expand All @@ -66,7 +66,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
}
}
]
Expand Down
30 changes: 15 additions & 15 deletions processor/otel/test_approved/span_jaeger_http.approved.json
Expand Up @@ -27,7 +27,7 @@
"string_a_b": "some note"
},
"parent": {
"id": "58585858"
"id": "0000000058585858"
},
"processor": {
"event": "span",
Expand Down Expand Up @@ -62,7 +62,7 @@
"original": "http://foo.bar.com?a=12"
}
},
"id": "41414646",
"id": "0000000041414646",
"name": "HTTP GET",
"subtype": "http",
"type": "external"
Expand All @@ -71,7 +71,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
}
},
{
Expand Down Expand Up @@ -106,7 +106,7 @@
}
},
"parent": {
"id": "41414646"
"id": "0000000041414646"
},
"processor": {
"event": "error",
Expand All @@ -125,7 +125,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
},
"url": {
"domain": "foo.bar.com",
Expand Down Expand Up @@ -162,7 +162,7 @@
}
},
"parent": {
"id": "41414646"
"id": "0000000041414646"
},
"processor": {
"event": "error",
Expand All @@ -181,7 +181,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
},
"url": {
"domain": "foo.bar.com",
Expand Down Expand Up @@ -220,7 +220,7 @@
}
},
"parent": {
"id": "41414646"
"id": "0000000041414646"
},
"processor": {
"event": "error",
Expand All @@ -239,7 +239,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
},
"url": {
"domain": "foo.bar.com",
Expand Down Expand Up @@ -278,7 +278,7 @@
}
},
"parent": {
"id": "41414646"
"id": "0000000041414646"
},
"processor": {
"event": "error",
Expand All @@ -297,7 +297,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
},
"url": {
"domain": "foo.bar.com",
Expand Down Expand Up @@ -336,7 +336,7 @@
}
},
"parent": {
"id": "41414646"
"id": "0000000041414646"
},
"processor": {
"event": "error",
Expand All @@ -355,7 +355,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
},
"url": {
"domain": "foo.bar.com",
Expand Down Expand Up @@ -392,7 +392,7 @@
}
},
"parent": {
"id": "41414646"
"id": "0000000041414646"
},
"processor": {
"event": "error",
Expand All @@ -411,7 +411,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
},
"url": {
"domain": "foo.bar.com",
Expand Down
Expand Up @@ -20,7 +20,7 @@
"name": "host-abc"
},
"parent": {
"id": "58585858"
"id": "0000000058585858"
},
"processor": {
"event": "span",
Expand Down Expand Up @@ -55,7 +55,7 @@
"original": "http://foo.bar.com?a=12"
}
},
"id": "41414646",
"id": "0000000041414646",
"name": "HTTP GET",
"subtype": "http",
"type": "external"
Expand All @@ -64,7 +64,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
}
}
]
Expand Down
Expand Up @@ -20,7 +20,7 @@
"name": "host-abc"
},
"parent": {
"id": "58585858"
"id": "0000000058585858"
},
"processor": {
"event": "span",
Expand Down Expand Up @@ -51,7 +51,7 @@
"original": "https://foo.bar.com:443?a=12"
}
},
"id": "41414646",
"id": "0000000041414646",
"name": "HTTPS GET",
"subtype": "http",
"type": "external"
Expand All @@ -60,7 +60,7 @@
"us": 1576500418000768
},
"trace": {
"id": "46467830"
"id": "00000000000000000000000046467830"
}
}
]
Expand Down

0 comments on commit 11591d2

Please sign in to comment.