Skip to content

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

Open
@oldium

Description

@oldium

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions