Allow configuring Micrometer Tracing MDC keys#50595
Conversation
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>
|
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? |
|
Some ecosystems use 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. |
| CorrelationScopeDecorator.Builder builder = MDCScopeDecorator.newBuilder() | ||
| // Clear existing traceId/spanId backage field mappings | ||
| // so the MDC key names can be customized below. | ||
| .clear() |
There was a problem hiding this comment.
This seems risky to me.
If the builder's default state ever includes mappings other than traceId and spanId, they would be lost. At a minimum, there needs to be a test that checks that the builder's default fields match the assumption made here. Ideally, CorrelationScopeDecorator would provide public API that allows an existing mapping to be overwritten, rather than failing as add does.
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_idinstead oftraceId/spanIdIntroduce 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.