Skip to content

MDC & Baggage AutoConfiguration for Micrometer Tracing with Brave and OpenTelemetry #32480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

marcingrzejszczak
Copy link
Contributor

@marcingrzejszczak marcingrzejszczak commented Sep 22, 2022

Rationale

In order to provide the users with the basic tracing observability story we need the following, additional features

  • W3C propagation type as the default propagation option (there would be 2 options, W3C and B3)
  • Baggage support (remote fields only (these are passed over the wire) - no local field support, no tagged field support)
    • Correlation fields support (automatically ads to MDC given baggage entries)
  • MDC updating for OTel and Brave (we will NOT modify the logging format but we WILL prepare the MDC so that the logging format would pick those entries)

Conditionals

  • If Micrometer Tracing IS NOT on the classpath
    • For Brave
      • [Context-Propagation] We will setup Brave B3 Propagation as default (there's no W3C support out of the box in Brave)
    • For OTel
      • [Baggage] [Context-Propagation] We will setup W3C Propagation with Baggage as default
      • [Context-Propagation] We will setup W3C Propagation without Baggage when Baggage disabled via property
      • [Context-Propagation] We will setup B3 Propagation without Baggage when B3 propagation property turned on (there's no option to have baggage with B3 without Micrometer Tracing)
  • If Micrometer Tracing IS on the classpath
    • For Brave
      • If baggage is not opt-out (management.tracing.baggage.enabled)
        • [Context-Propagation] [Baggage] By default we setup W3C context propagation with Baggage
        • [Context-Propagation] [Baggage] We can switch to B3 context propagation (via a property) with Baggage
        • [Baggage] If provided up-front via properties, we will set remote baggage entries
        • [Baggage] [MDC] If MDC is on the classpath
          • We will setup injecting correlated baggage entries to MDC (those need to be provided up-front)
      • If baggage is opt-out
      • [MDC] If MDC is on the classpath
        • We will setup injecting spanId / traceId to MDC context
    • For OTel:
      • [Baggage] [Context-Propagation] We will setup W3C Propagation with Baggage as default
      • [Context-Propagation] We will setup W3C Propagation without Baggage when Baggage disabled via property
      • [Baggage] [Context-Propagation] We will setup B3 Propagation with Baggage when B3 propagation property turned on
      • [Context-Propagation] We will setup B3 Propagation without Baggage when B3 propagation property turned on and baggage option disabled
      • [Baggage] [MDC] If MDC is on the classpath
        • We will setup injecting correlated baggage entries to MDC (those need to be provided up-front)
      • [MDC] If MDC is on the classpath
        • We will setup injecting spanId / traceId to MDC context

prerequisites

superseeds #32214

@ConditionalOnProperty(value = "management.tracing.propagation.type", havingValue = "W3C",
matchIfMissing = true)
Factory w3cPropagationNoBaggageFactory() {
return new W3CPropagation(BRAVE_BAGGAGE_MANAGER, List.of()); // TODO: Use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

micrometer-metrics/tracing@29feef8 is the change that we need so that there's no baggage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I mean if we leave this as it is the components for baggage (i.e. BraveBaggageManager) will be called, but no baggage will be propagated cause there's nothing configured. With this change in tracing we are nulling anything baggage related so that will not be called at all

Comment on lines 79 to 88
/**
* Whether to enable correlation of the baggage context with logging contexts.
*/
private boolean correlationEnabled = true;

/**
* List of fields that should be correlated with the logging context. That means
* that these fields would end up as key-value pairs in e.g. MDC.
*/
private List<String> correlationFields = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks as if there could be a correlation group with enabled and fields properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good idea!

@@ -53,4 +74,81 @@ public void setProbability(float probability) {

}

public static class Baggage {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class could have an enabled property, removing the need for some additional metadata.

},
{
"name": "management.tracing.sampling.probability",
"defaultValue": "0.10"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the annotation processor not pick up this default automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intellij told me that it doesn't 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check default values are produced by building on the command-line.

@wilkinsona wilkinsona self-assigned this Sep 26, 2022
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 26, 2022
@wilkinsona wilkinsona added this to the 3.0.x milestone Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants