Skip to content

Allow explicit context for OpenTelemetry logs - #349

Closed
riensen wants to merge 1 commit into
SAP:opentelemetry-v8from
riensen:fix/otel-log-context-resolver
Closed

riensen wants to merge 1 commit into
SAP:opentelemetry-v8from
riensen:fix/otel-log-context-resolver

Conversation

@riensen

@riensen riensen commented Sep 9, 2026

Copy link
Copy Markdown

Summary

  • allow OpenTelemetryLogsOutputPlugin callers to provide either a fixed OpenTelemetry Context or a per-record context resolver
  • preserve the existing behavior when no context is configured, so the Logs SDK continues to capture context.active()
  • add library-local SDK tests for active non-recording context, explicit context, resolver override, severity, body, and attributes

Root cause

OpenTelemetryLogsOutputPlugin.writeRecord() currently calls Logger.emit() without a context. The OpenTelemetry Logs SDK therefore snapshots context.active() at emit time. In framework integrations, that active context can contain a non-recording span whose span ID is never exported, even when the consumer already has the recording HTTP SERVER span context available. The resulting log record is correlated to a span that cannot be found in the trace backend.

This change keeps the plugin framework-agnostic: consumers can supply the correct context directly or resolve it lazily for each log record. There is no xotel-specific behavior.

Validation

  • npm ci
  • npm run build
  • npx mocha src/test/unit-test/otel-output.test.js (3 passing)
  • npm run lint
  • git diff --check

The complete npm test run reaches 175 passing tests. Two existing dynamic-log-level acceptance tests fail because their checked-in JWT fixtures expired on 2026-07-02; the focused request-context test reproduces the same failures independently of this change.

@cla-assistant

cla-assistant Bot commented Sep 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@riensen
riensen force-pushed the fix/otel-log-context-resolver branch from c4d5c25 to 0a5274e Compare September 9, 2026 09:03
@riensen riensen closed this Sep 9, 2026
@riensen riensen reopened this Sep 9, 2026
@riensen riensen closed this Sep 9, 2026
@riensen
riensen deleted the fix/otel-log-context-resolver branch September 9, 2026 09:45
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.

2 participants