Skip to content

"failed to decode trace id" warning by DataDog for Python OpenTelemetry logs #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
oldium opened this issue Mar 10, 2025 · 1 comment

Comments

@oldium
Copy link

oldium commented Mar 10, 2025

When the logs do not contain trace ID and span ID, the DataDog Go mapping spams the output with failed to decode trace id and failed to decode span id.

I tracked the problem down to the otel* variables, which has default "0":

            record.otelSpanID = "0"
            record.otelTraceID = "0"
            record.otelTraceSampled = False

This is decoded like a span ID/trace ID, so the 16 and 32 characters length check of the parser fails:

case "traceid", "trace_id", "contextmap.traceid", "oteltraceid":
traceID, err := decodeTraceID(v.AsString())

case "spanid", "span_id", "contextmap.spanid", "otelspanid":
spanID, err := decodeSpanID(v.AsString())

And the decoding:

func decodeTraceID(traceIDStr string) (pcommon.TraceID, error) {
var id pcommon.TraceID
if hex.DecodedLen(len(traceIDStr)) != len(id) {
return pcommon.TraceID{}, errors.New("trace ids must be 32 hex characters")
}
_, err := hex.Decode(id[:], []byte(traceIDStr))
if err != nil {
return pcommon.TraceID{}, err
}
return id, nil
}

func decodeSpanID(spanIDStr string) (pcommon.SpanID, error) {
var id pcommon.SpanID
if hex.DecodedLen(len(spanIDStr)) != len(id) {
return pcommon.SpanID{}, errors.New("span ids must be 16 hex characters")
}
_, err := hex.Decode(id[:], []byte(spanIDStr))
if err != nil {
return pcommon.SpanID{}, err
}
return id, nil
}

@oldium
Copy link
Author

oldium commented Mar 10, 2025

The full log line is the following:

2025-03-07T22:58:41.395Z	warn	[email protected]/transform.go:107	failed to decode span id	{"otelcol.component.id": "datadog", "otelcol.component.kind": "Exporter", "otelcol.signal": "logs", "span_id": "0", "error": "span ids must be 16 hex characters"}
2025-03-07T22:58:41.395Z	warn	[email protected]/transform.go:95	failed to decode trace id	{"otelcol.component.id": "datadog", "otelcol.component.kind": "Exporter", "otelcol.signal": "logs", "trace_id": "0", "error": "trace ids must be 32 hex characters"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant