Skip to content

Commit 5514595

Browse files
authored
Expose values added by logback mdc instrumentation to the appender instrumentation (#14904)
1 parent 8e66fc4 commit 5514595

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

instrumentation/logback/logback-appender-1.0/javaagent/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ dependencies {
4646

4747
implementation(project(":instrumentation:logback:logback-appender-1.0:library"))
4848

49+
testInstrumentation(project(":instrumentation:logback:logback-mdc-1.0:javaagent"))
50+
4951
testImplementation("org.awaitility:awaitility")
5052
}
5153

instrumentation/logback/logback-appender-1.0/javaagent/src/test/java/io/opentelemetry/instrumentation/logback/appender/v1_0/LogbackTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.opentelemetry.api.common.AttributeKey;
1818
import io.opentelemetry.api.logs.Severity;
1919
import io.opentelemetry.api.trace.SpanContext;
20+
import io.opentelemetry.api.trace.TraceFlags;
2021
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
2122
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2223
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
@@ -167,6 +168,15 @@ private static void test(
167168
satisfies(
168169
EXCEPTION_STACKTRACE, v -> v.contains(LogbackTest.class.getName()))));
169170
}
171+
if (withParent) {
172+
SpanContext spanContext = testing.spans().get(0).getSpanContext();
173+
attributeAsserts.addAll(
174+
Arrays.asList(
175+
equalTo(AttributeKey.stringKey("trace_id"), spanContext.getTraceId()),
176+
equalTo(AttributeKey.stringKey("span_id"), spanContext.getSpanId()),
177+
equalTo(
178+
AttributeKey.stringKey("trace_flags"), TraceFlags.getSampled().asHex())));
179+
}
170180
logRecord.hasAttributesSatisfyingExactly(attributeAsserts);
171181
});
172182
} else {

instrumentation/logback/logback-mdc-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/logback/mdc/v1_0/LogbackMdcInstrumentationModule.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ public List<TypeInstrumentation> typeInstrumentations() {
2929
public boolean isIndyReady() {
3030
return true;
3131
}
32+
33+
@Override
34+
public int order() {
35+
// run before logback appender instrumentation so that the appender instrumentation can observe
36+
// the attributes added to the mdc by this instrumentation
37+
return -1;
38+
}
3239
}

0 commit comments

Comments
 (0)