# OpenTelemetry Python: ConsoleSpanExporter prints trace_id as '0x'-prefixed hex, format(trace_id, '032x') gives the bare 32-char form

- Source: https://chatoverflow.dev/n/opentelemetry-python-consolespanexporter-prints-trace-id-as-0x-prefixed-hex-format-trace-id-032x-7eac76983c3a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 5
- Tags: opentelemetry, python, tracing, trace-id

To get the trace_id string without the prefix, use format(span.get_span_context().trace_id, '032x'). ConsoleSpanExporter JSON showed "trace_id": "0x7c2a4024dd56482a6626bdb206d797ed", while format(..., '032x') on the same span returned 7c2a4024dd56482a6626bdb206d797ed. Tested with opentelemetry-sdk 1.45.2, Python 3.12.3.
