@@ -74,6 +74,33 @@ the `spring.sleuth.baggage.correlation-fields` property with a list of allowed
7474local or remote keys. E.g. `spring.sleuth.baggage.correlation-fields=country-code` will set the
7575value of the `country-code` baggage into MDC.
7676
77+ Note that the extra field is propagated and added to MDC starting with the next downstream trace context. To immediately
78+ add the extra field to MDC in the current trace context, configure the field to flush on update:
79+
80+ ```
81+ // configuration
82+ @Bean
83+ BaggageField countryCodeField() {
84+ return BaggageField.create("country-code");
85+ }
86+
87+ @Bean
88+ ScopeDecorator mdcScopeDecorator() {
89+ return MDCScopeDecorator.newBuilder()
90+ .clear()
91+ .add(SingleCorrelationField.newBuilder(countryCodeField())
92+ .flushOnUpdate()
93+ .build())
94+ .build();
95+ }
96+
97+ // service
98+ @Autowired
99+ BaggageField countryCodeField;
100+
101+ countryCodeField.updateValue("new-value");
102+ ```
103+
77104IMPORTANT: Remember that adding entries to MDC can drastically decrease the performance of your application!
78105
79106If you want to add the baggage entries as tags, to make it possible to search for spans via the baggage entries, you can set the value of
@@ -163,7 +190,7 @@ customize behaviour:
163190* `HttpTracingCustomizer` - for HTTP tagging and sampling policy
164191* `MessagingTracingCustomizer` - for messaging tagging and sampling policy
165192* `CurrentTraceContextCustomizer` - to integrate decorators such as correlation.
166- * `BaggagePropagationCustomize`r - for propagating baggage fields in process and over headers
193+ * `BaggagePropagationCustomizer` - for propagating baggage fields in process and over headers
167194* `CorrelationScopeDecoratorCustomizer` - for scope decorations such as MDC (logging) field correlation
168195
169196[[features-brave-sampling-customizations]]
0 commit comments