Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public ExecutionOtelPlugin(SdkTracerProviderBuilder tracerProviderBuilder, Conte
*
* @param tracerProviderBuilder the tracer provider builder (ID generator will be overridden)
* @param contextExtractor extracts parent trace context from the Lambda environment
* @param enableMdc if true, injects traceId/spanId/traceSampled into SLF4J MDC for log correlation
* @param enableMdc if true, injects traceId/spanId/otelTraceSampled into SLF4J MDC for log correlation
* @param workflowSpanName the name for the Workflow root span
*/
public ExecutionOtelPlugin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public InvocationOtelPlugin(SdkTracerProviderBuilder tracerProviderBuilder, Cont
*
* @param tracerProviderBuilder the tracer provider builder (ID generator will be overridden)
* @param contextExtractor extracts parent trace context from the Lambda environment
* @param enableMdc if true, injects traceId/spanId/traceSampled into SLF4J MDC for log correlation
* @param enableMdc if true, injects traceId/spanId/otelTraceSampled into SLF4J MDC for log correlation
*/
public InvocationOtelPlugin(
SdkTracerProviderBuilder tracerProviderBuilder, ContextExtractor contextExtractor, boolean enableMdc) {
Expand All @@ -177,7 +177,7 @@ public InvocationOtelPlugin(
*
* @param tracerProviderBuilder the tracer provider builder (ID generator will be overridden)
* @param contextExtractor extracts parent trace context from the Lambda environment
* @param enableMdc if true, injects traceId/spanId/traceSampled into SLF4J MDC for log correlation
* @param enableMdc if true, injects traceId/spanId/otelTraceSampled into SLF4J MDC for log correlation
* @param workflowSpanName the name for the Workflow span
*/
public InvocationOtelPlugin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
* <p>When used with structured logging (Log4j2 JSON, Logback JSON), these MDC fields appear in every log line, enabling
* tools like CloudWatch Application Signals and Datadog to correlate logs with traces.
*
* <p>MDC keys injected:
* <p>MDC keys injected (aligned with the JS and Python SDK OTel plugins):
*
* <ul>
* <li>{@code trace_id} — the W3C trace ID (32 hex chars)
* <li>{@code span_id} — the current span ID (16 hex chars)
* <li>{@code traceSampled} — whether the trace is sampled (true/false)
* <li>{@code traceId} — the W3C trace ID (32 hex chars)
* <li>{@code spanId} — the current span ID (16 hex chars)
* <li>{@code otelTraceSampled} — whether the trace is sampled (true/false)
* </ul>
*
* <p>Usage: Call {@link #inject()} in {@code onUserFunctionStart} (after span is active) and {@link #clear()} in
Expand All @@ -28,9 +28,14 @@
@Deprecated
public final class MdcSpanEnricher {

public static final String MDC_TRACE_ID = "trace_id";
public static final String MDC_SPAN_ID = "span_id";
public static final String MDC_TRACE_SAMPLED = "traceSampled";
// MDC key names are aligned with the JS and Python SDK OTel plugins
// (enrichLogContext -> traceId/spanId/otelTraceSampled) so log-trace
// correlation uses one consistent field schema across all three SDKs.
// Note: SLF4J MDC values are always strings, so otelTraceSampled is the
// string "true"/"false" here (a boolean in the JS/Python log records).
public static final String MDC_TRACE_ID = "traceId";
public static final String MDC_SPAN_ID = "spanId";
public static final String MDC_TRACE_SAMPLED = "otelTraceSampled";

private MdcSpanEnricher() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ void cleanup() {
MDC.clear();
}

@Test
void mdcKeyNames_matchJsAndPythonSchema() {
// The JS (enrichLogContext) and Python (OtelContextLogFilter) plugins emit
// traceId / spanId / otelTraceSampled. Java's MDC keys must match so all
// three SDKs share one log-trace-correlation field schema.
assertEquals("traceId", MdcSpanEnricher.MDC_TRACE_ID);
assertEquals("spanId", MdcSpanEnricher.MDC_SPAN_ID);
assertEquals("otelTraceSampled", MdcSpanEnricher.MDC_TRACE_SAMPLED);
}

@Test
void clear_removesAllMdcKeys() {
MDC.put(MdcSpanEnricher.MDC_TRACE_ID, "abc123");
Expand Down
Loading