Skip to content
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

Prefix baggage key not value when adding it to logback mdc #8066

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions instrumentation/logback/logback-mdc-1.0/javaagent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Settings for the Logback MDC instrumentation

| System property | Type | Default | Description |
|---|---|---|---|
| `otel.instrumentation.logback-mdc.add-baggage` | Boolean | `false` | Enable exposing baggage attributes through MDC. |
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ public static void onExit(
// (Java 6 related errors are observed) so relying on for loop instead
for (Map.Entry<String, BaggageEntry> entry : baggage.asMap().entrySet()) {
spanContextData.put(
entry.getKey(),
// prefix all baggage values to avoid clashes with existing context
"baggage." + entry.getValue().getValue());
"baggage." + entry.getKey(), entry.getValue().getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ public ILoggingEvent wrapEvent(ILoggingEvent event) {
baggage.forEach(
(key, value) ->
contextData.put(
key,
// prefix all baggage values to avoid clashes with existing context
"baggage." + value.getValue()));
"baggage." + key, value.getValue()));
}

if (eventContext == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ abstract class AbstractLogbackTest extends InstrumentationSpecification {
events[0].getMDCPropertyMap().get("trace_id") == null
events[0].getMDCPropertyMap().get("span_id") == null
events[0].getMDCPropertyMap().get("trace_flags") == null
events[0].getMDCPropertyMap().get("baggage_key") == (expectBaggage() ? "baggage.baggage_value" : null)
events[0].getMDCPropertyMap().get("baggage.baggage_key") == (expectBaggage() ? "baggage_value" : null)

events[1].message == "log message 2"
events[1].getMDCPropertyMap().get("trace_id") == null
events[1].getMDCPropertyMap().get("span_id") == null
events[1].getMDCPropertyMap().get("trace_flags") == null
events[1].getMDCPropertyMap().get("baggage_key") == (expectBaggage() ? "baggage.baggage_value" : null)
events[1].getMDCPropertyMap().get("baggage.baggage_key") == (expectBaggage() ? "baggage_value" : null)
}

def "ids when span"() {
Expand All @@ -86,19 +86,19 @@ abstract class AbstractLogbackTest extends InstrumentationSpecification {
events[0].getMDCPropertyMap().get("trace_id") == span1.spanContext.traceId
events[0].getMDCPropertyMap().get("span_id") == span1.spanContext.spanId
events[0].getMDCPropertyMap().get("trace_flags") == "01"
events[0].getMDCPropertyMap().get("baggage_key") == (expectBaggage() ? "baggage.baggage_value" : null)
events[0].getMDCPropertyMap().get("baggage.baggage_key") == (expectBaggage() ? "baggage_value" : null)

events[1].message == "log message 2"
events[1].getMDCPropertyMap().get("trace_id") == null
events[1].getMDCPropertyMap().get("span_id") == null
events[1].getMDCPropertyMap().get("trace_flags") == null
events[1].getMDCPropertyMap().get("baggage_key") == null
events[1].getMDCPropertyMap().get("baggage.baggage_key") == null

events[2].message == "log message 3"
events[2].getMDCPropertyMap().get("trace_id") == span2.spanContext.traceId
events[2].getMDCPropertyMap().get("span_id") == span2.spanContext.spanId
events[2].getMDCPropertyMap().get("trace_flags") == "01"
events[2].getMDCPropertyMap().get("baggage_key") == (expectBaggage() ? "baggage.baggage_value" : null)
events[2].getMDCPropertyMap().get("baggage.baggage_key") == (expectBaggage() ? "baggage_value" : null)
}

Span runWithSpanAndBaggage(String spanName, Baggage baggage, Closure callback) {
Expand Down