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 (elastic#4671) (elastic#4801)

* 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 <[email protected]>
  • Loading branch information
axw and tobiasstadler authored Feb 18, 2021
1 parent fd7458b commit 05f5a8a
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 05f5a8a

Please sign in to comment.