diff --git a/instrumentation/logback/logback-mdc-1.0/javaagent/README.md b/instrumentation/logback/logback-mdc-1.0/javaagent/README.md new file mode 100644 index 000000000000..ab349cf6a269 --- /dev/null +++ b/instrumentation/logback/logback-mdc-1.0/javaagent/README.md @@ -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. | diff --git a/instrumentation/logback/logback-mdc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/mdc/v1_0/LoggingEventInstrumentation.java b/instrumentation/logback/logback-mdc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/mdc/v1_0/LoggingEventInstrumentation.java index e2f8130e9406..c45a77984310 100644 --- a/instrumentation/logback/logback-mdc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/mdc/v1_0/LoggingEventInstrumentation.java +++ b/instrumentation/logback/logback-mdc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/mdc/v1_0/LoggingEventInstrumentation.java @@ -88,9 +88,8 @@ public static void onExit( // (Java 6 related errors are observed) so relying on for loop instead for (Map.Entry 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()); } } diff --git a/instrumentation/logback/logback-mdc-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/mdc/v1_0/OpenTelemetryAppender.java b/instrumentation/logback/logback-mdc-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/mdc/v1_0/OpenTelemetryAppender.java index d5e0378ab48e..b6a3d3b9a234 100644 --- a/instrumentation/logback/logback-mdc-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/mdc/v1_0/OpenTelemetryAppender.java +++ b/instrumentation/logback/logback-mdc-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/mdc/v1_0/OpenTelemetryAppender.java @@ -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) { diff --git a/instrumentation/logback/logback-mdc-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/logback/mdc/v1_0/AbstractLogbackTest.groovy b/instrumentation/logback/logback-mdc-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/logback/mdc/v1_0/AbstractLogbackTest.groovy index 0062ea09bc67..93212d192bef 100644 --- a/instrumentation/logback/logback-mdc-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/logback/mdc/v1_0/AbstractLogbackTest.groovy +++ b/instrumentation/logback/logback-mdc-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/logback/mdc/v1_0/AbstractLogbackTest.groovy @@ -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"() { @@ -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) {