Skip to content

fix(otel): align MDC log-correlation keys with JS and Python SDKs - #592

Merged
SilanHe merged 2 commits into
mainfrom
feat/otel-align-mdc-keys
Aug 4, 2026
Merged

fix(otel): align MDC log-correlation keys with JS and Python SDKs#592
SilanHe merged 2 commits into
mainfrom
feat/otel-align-mdc-keys

Conversation

@SilanHe

@SilanHe SilanHe commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Issue

aws/aws-durable-execution-conformance-tests#23 (comment)

Summary

MdcSpanEnricher injected the MDC keys trace_id / span_id / traceSampled, but the JS (enrichLogContext) and Python (OtelContextLogFilter) plugins emit traceId / spanId / otelTraceSampled. Log↔trace correlation was therefore using two different field schemas across the SDKs (and Java's own naming was internally inconsistent — snake_case IDs but camelCase traceSampled).

This PR renames the three MDC keys to traceId / spanId / otelTraceSampled so all six plugins (JS / Python / Java × Execution / Invocation) share one field schema.

Both Java plugins reference these via the MdcSpanEnricher.MDC_* constants, so this reconciles both ExecutionOtelPlugin and InvocationOtelPlugin in a single change.

Field schema (after this PR)

trace ID span ID sampled
JS (both) traceId spanId otelTraceSampled (boolean)
Python (both) traceId spanId otelTraceSampled (boolean)
Java (both) traceId spanId otelTraceSampled (string)

Residual difference (inherent, documented): SLF4J MDC stores only strings, so Java's otelTraceSampled is the string "true"/"false" rather than a boolean. The key names are now unified across all three SDKs.

Compatibility

⚠️ This changes the MDC key names emitted into structured logs. Anyone parsing the old trace_id / span_id / traceSampled keys (log formatters, CloudWatch/Datadog field mappings) must update to the new names.

Tests

+1 test asserting the exact key strings (traceId/spanId/otelTraceSampled); existing MDC + both plugin suites pass unchanged (they reference the constants).

MdcSpanEnricher injected MDC keys trace_id/span_id/traceSampled, but the JS
(enrichLogContext) and Python (OtelContextLogFilter) plugins emit
traceId/spanId/otelTraceSampled. This left log-trace correlation using two
different field schemas across the SDKs.

Rename the three MDC keys to traceId/spanId/otelTraceSampled so all six plugins
(JS/Python/Java x Execution/Invocation) share one schema. Both Java plugins use
these via the MdcSpanEnricher.MDC_* constants, so this reconciles both at once.

Note: SLF4J MDC values are always strings, so Java's otelTraceSampled remains
the string "true"/"false" (a boolean in the JS/Python log records); this
value-type difference is inherent to MDC and documented in the code.

Tests: +1 asserting the exact key strings (otel-plugin suite green).
@SilanHe
SilanHe requested a review from a team August 4, 2026 23:27
@SilanHe
SilanHe temporarily deployed to ai-pr-review-runtime August 4, 2026 23:27 — with GitHub Actions Inactive
@SilanHe
SilanHe temporarily deployed to ai-pr-review-runtime August 4, 2026 23:27 — with GitHub Actions Inactive
@SilanHe
SilanHe marked this pull request as draft August 4, 2026 23:28
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

SilanHe pushed a commit to aws/aws-durable-execution-docs that referenced this pull request Aug 4, 2026
Aligns with the Java SDK rename in aws/aws-durable-execution-sdk-java#592 and the
TS/Python otelTraceSampled naming.
@SilanHe
SilanHe temporarily deployed to ai-pr-review-runtime August 4, 2026 23:35 — with GitHub Actions Inactive
@SilanHe
SilanHe temporarily deployed to ai-pr-review-runtime August 4, 2026 23:35 — with GitHub Actions Inactive
@SilanHe
SilanHe marked this pull request as ready for review August 4, 2026 23:35
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@SilanHe
SilanHe temporarily deployed to ai-pr-review-runtime August 4, 2026 23:37 — with GitHub Actions Inactive
@SilanHe
SilanHe temporarily deployed to ai-pr-review-runtime August 4, 2026 23:37 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Claude AI review

The rename is correct and complete at the code level. All production and test references go through the MdcSpanEnricher.MDC_TRACE_ID / MDC_SPAN_ID / MDC_TRACE_SAMPLED constants (MdcSpanEnricher.java:41-51, ExecutionOtelPlugin.java:233, InvocationOtelPlugin.java:275,561, and all tests), so changing the constant values (traceId / spanId / otelTraceSampled) propagates cleanly with no dangling literals. The Javadoc in all three files was updated in the diff, and the new test mdcKeyNames_matchJsAndPythonSchema pins the exact key strings. The MDC key rename is a deliberate, documented breaking change. I could not independently verify the JS/Python key names (those live in other repos) and am trusting the PR description on cross-SDK alignment.

Finding (documentation, medium): otel-plugin/README.md still documents the old MDC key names and is now stale/incorrect as a direct result of this PR:

  • Line 12: Injects trace_id, span_id, and traceSampled ...
  • Lines 200–202: table rows trace_id / span_id / traceSampled
  • Line 204: The trace_id is also injected at invocation start ...
  • Lines 254 and 278: enableMdc descriptions reference trace_id/span_id/traceSampled

Fix: update these to traceId / spanId / otelTraceSampled to match the renamed constants. (These are unchanged lines, so no inline comment was attachable; flagging here per instructions.)

Residual test risk: low. The change is a pure constant rename covered by the updated/added tests. No correctness, concurrency, replay, or serialization semantics are affected. The only downstream risk is external log-parsing/field-mapping configs (CloudWatch/Datadog), which the PR body already calls out as breaking.

Reviewed commit 5ab6b814f3c546d20ec825b17517d2c6b2a9fffe. Workflow run

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codex AI review

  • [P2] Update the published MDC documentationotel-plugin/src/main/java/software/amazon/lambda/durable/otel/MdcSpanEnricher.java:36. The implementation now emits camel-case keys, but otel-plugin/README.md still documents trace_id, span_id, and traceSampled. Users following it will configure absent fields and lose log correlation. Update all README, example, and test-comment references to the new schema.

Reviewed commit 5ab6b814f3c546d20ec825b17517d2c6b2a9fffe. Workflow run

@SilanHe
SilanHe merged commit 62c825f into main Aug 4, 2026
16 checks passed
@SilanHe
SilanHe deleted the feat/otel-align-mdc-keys branch August 4, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants