jaegertracing/jaeger · error

trace ID from DB is too long: %d chars

Error message

trace ID from DB is too long: %d chars

What it means

convertTraceIDFromDB converts a stored DB trace ID (hex string) into a pcommon.TraceID. It rejects any trace ID longer than 32 hex characters (128 bits), since that cannot fit into the 16-byte OTLP TraceID. This indicates corrupt or non-conformant data in Elasticsearch rather than a caller bug.

Source

Thrown at internal/storage/v2/elasticsearch/tracestore/ids.go:20

// SPDX-License-Identifier: Apache-2.0

package tracestore

import (
	"encoding/hex"
	"fmt"
	"strings"

	"go.opentelemetry.io/collector/pdata/pcommon"

	"github.com/jaegertracing/jaeger/internal/storage/v2/elasticsearch/tracestore/core/dbmodel"
)

func convertTraceIDFromDB(dbTraceId dbmodel.TraceID) (pcommon.TraceID, error) {
	var traceId [16]byte
	traceIdHex := string(dbTraceId)
	if len(traceIdHex) > 32 {
		return pcommon.TraceID{}, fmt.Errorf("trace ID from DB is too long: %d chars", len(traceIdHex))
	}
	// Left-pad with zeros to 32 hex chars to handle shorter (e.g. 64-bit) trace IDs.
	if len(traceIdHex) < 32 {
		traceIdHex = strings.Repeat("0", 32-len(traceIdHex)) + traceIdHex
	}
	traceBytes, err := hex.DecodeString(traceIdHex)
	if err != nil {
		return pcommon.TraceID{}, err
	}
	copy(traceId[:], traceBytes)
	return traceId, nil
}

func fromDbSpanId(dbSpanId dbmodel.SpanID) (pcommon.SpanID, error) {
	var spanId [8]byte
	spanIdHex := string(dbSpanId)
	if len(spanIdHex) > 16 {
		return pcommon.SpanID{}, fmt.Errorf("span ID from DB is too long: %d chars", len(spanIdHex))

View on GitHub (pinned to 806f444784)

Solutions

  1. Inspect the offending document's trace_id field in Elasticsearch and correct or delete the malformed record
  2. Ensure all writes go through jaeger's ES span writer so trace IDs are canonical hex
  3. Check for scripts/migrations that transformed trace IDs (e.g. re-encoding base64 to hex twice)
  4. Pin reader/writer versions so both use the same dbmodel schema

Example fix

// before (corrupt document in ES)
{"trace_id": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0"}
// after
{"trace_id": "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6"}
Defensive patterns

Strategy: validation

Validate before calling

if len(span.GetTraceId()) > 32 {
    return fmt.Errorf("trace ID exceeds 32 hex chars: %d", len(span.GetTraceId()))
}

Type guard

func isValidTraceIDHex(s string) bool {
    return len(s) <= 32 && len(s) > 0
}

Prevention

When it happens

Trigger: Reading spans or trace summaries from Elasticsearch whose trace_id field contains more than 32 hex characters, via GetTraces, FindTraceSummaries, or related read paths that call dbSpanToSpan/dbSpanRefsToSpanEvents.

Common situations: An index written by a different/older jaeger schema or manually seeded documents with malformed trace_id; a custom ingester storing non-standard-width trace IDs; data migration from another backend leaving oversized IDs.

Related errors


AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01). Data as JSON: /api/errors/8fd64aac22b2966d. Report an issue: GitHub.