Skip to content

Allow configuring Micrometer Tracing MDC keys#50595

Open
philsttr wants to merge 4 commits into
spring-projects:mainfrom
philsttr:configurable_trace_mdc_keys
Open

Allow configuring Micrometer Tracing MDC keys#50595
philsttr wants to merge 4 commits into
spring-projects:mainfrom
philsttr:configurable_trace_mdc_keys

Conversation

@philsttr

@philsttr philsttr commented May 27, 2026

Copy link
Copy Markdown

Allow the user to configure the names of the MDC keys in which the trace id and span id are stored when using Micrometer Tracing. For example, to use trace_id/span_id instead of traceId/spanId

Introduce the following new properties:

  • management.tracing.mdc.trace-id-key (default: traceId)
  • management.tracing.mdc.span-id-key (default: spanId)

The default key names keep backwards compatibility with the previously hardcoded values.

Autoconfigurations for both the Brave and OpenTelemetry Micrometer Tracing bridges honor the new properties.

Allow the user to configure the names of the MDC keys in which the trace
id and span id are stored when using Micrometer Tracing.

Introduce the following new properties:
- management.tracing.mdc.trace-id-key (default: "traceId")
- management.tracing.mdc.span-id-key  (default: "spanId")

The properties are honored by both the Brave and OpenTelemetry Micrometer
Tracing bridges.

The default key names keep backwards compatibility with the previously
hardcoded values.

Signed-off-by: Phil Clay <philsttr@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 27, 2026
@wilkinsona

Copy link
Copy Markdown
Member

Why do you want the keys to be configurable? What would configuring them allow you to do that currently isn't possible or isn't as concise as you'd like?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label May 28, 2026
@philsttr

philsttr commented May 28, 2026

Copy link
Copy Markdown
Author

Some ecosystems use trace_id/span_id. For example, python structlog and OpenTelemetry

Allowing the keys to be configurable (as supported in Micrometer Tracing) allows users to use the same names already in use in those ecosystems. This helps when enabling tracing in Spring Boot apps where a naming pattern has already been established.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 28, 2026
@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jun 28, 2026
…tion

Previously, clearing the MDCScopeDecorator builder to allow custom
MDC key names for traceId and spanId also discarded any other default
correlation fields configured by Brave. The builder is now cleared,
the customized traceId and spanId fields are added, and any remaining
default fields are re-added to restore the original behavior for
non-customized fields.

Signed-off-by: Phil Clay <philsttr@users.noreply.github.com>
@philsttr philsttr force-pushed the configurable_trace_mdc_keys branch from f7c6462 to 8955e1f Compare June 29, 2026 19:13
philsttr added 2 commits June 29, 2026 16:25
…ustomization"

This reverts commit 8955e1f.

Signed-off-by: Phil Clay <philsttr@users.noreply.github.com>
Add a unit test to validate that MDCScopeDecorator.newBuilder() only
has traceId and spanId fields configured by default.

The mdcCorrelationScopeDecoratorBuilder method in
BravePropagationConfigurations.PropagationWithBaggage clears the
builder's defaults and re-adds only those two fields so their MDC key
names can be customized. If Brave adds new default fields in the future,
the .clear() call would silently drop them; this test will catch that.

Signed-off-by: Phil Clay <philsttr@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants