version: Spring Boot 3.3.2
When using Spring Boot + Micrometer Tracing Brave, propagation remote fields could be customized by:
@Bean
BaggagePropagationCustomizer braveCanaryBaggagePropagationCustomizer() {
return builder -> {
builder.add(BaggagePropagationConfig.SingleBaggageField.remote(
BaggageField.create("remote field")));
}
}
};
}
But after migration to Spring Boot + Micrometer Tracing Otel, this way is not possible(or not easy), because we need to override these beans:
@Bean
@ConditionalOnMissingBean(io.micrometer.tracing.Tracer.class)
OtelTracer micrometerOtelTracer(io.opentelemetry.api.trace.Tracer tracer, OtelTracer.EventPublisher eventPublisher,
OtelCurrentTraceContext otelCurrentTraceContext) {
return new OtelTracer(tracer, otelCurrentTraceContext, eventPublisher,
new OtelBaggageManager(otelCurrentTraceContext, this.tracingProperties.getBaggage().getRemoteFields(),
Collections.emptyList()));
}
@Bean
@ConditionalOnEnabledTracing
TextMapPropagator textMapPropagatorWithBaggage(OtelCurrentTraceContext otelCurrentTraceContext) {
List<String> remoteFields = this.tracingProperties.getBaggage().getRemoteFields();
BaggageTextMapPropagator baggagePropagator = new BaggageTextMapPropagator(remoteFields,
new OtelBaggageManager(otelCurrentTraceContext, remoteFields, Collections.emptyList()));
return CompositeTextMapPropagator.create(this.tracingProperties.getPropagation(), baggagePropagator);
}
in which CompositeTextMapPropagator class is protected, and textMapPropagatorWithBaggage Bean is not a ConditionalOnMissingBean. So, i undertand that was not intended to be overrided. But could we provider an easy way to customize remote fields by java code?
Comment From: mhalbritter
The remote fields are read from tracingProperties.getBaggage().getRemoteFields(), so they are customizable via properties. If you want code to set these properties, you can implement an EnvironmentPostProcessor to do that. Does that work for you?
Comment From: wapkch
The remote fields are read from
tracingProperties.getBaggage().getRemoteFields(), so they are customizable via properties. If you want code to set these properties, you can implement anEnvironmentPostProcessorto do that. Does that work for you?
It does work, and i think the former would be more elegant. Thanks for your reply, feel free to close it.