Skip to content

feat: add flatten: 'otel' and otelAttributesFormat for winston-transport 0.29+ (2.3.0) - #155

Merged
cuzzlor merged 2 commits into
mainfrom
feat/otel-attributes-format
Oct 16, 2026
Merged

cuzzlor merged 2 commits into
mainfrom
feat/otel-attributes-format

Conversation

@cuzzlor

@cuzzlor cuzzlor commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Lands #154 on main. #154 was approved and merged, but into its stacked base fix/date-metadata — it was merged two minutes after #153 and before GitHub retargeted it — so its commit never reached main and 2.3.0 was never published (latest is 2.2.1).

This branch has exactly the tree #154 merged (git diff origin/fix/date-metadata origin/feat/otel-attributes-format is empty); against main it is that one commit. The description, rationale and test plan are on #154.

Test plan

cuzzlor and others added 2 commits October 16, 2026 12:19
…ort 0.29+

From 0.29, @opentelemetry/winston-transport lifts an `err`/`error` value off
the record and hands it to the logs SDK as the exception, which keeps only
name, message, stack and a cause's message. So:

- `flatten: true` stringifies the error first, and the SDK records the whole
  JSON as one `exception.message`, with no type or stack trace.
- No flattening records the exception but drops the rest of the error
  (status, provider data, cause chain), and 0.32+ sends other objects as
  nested maps that Log Analytics does not index.

`otelAttributesFormat` keeps the error an object with only the fields the
SDK reads, moves the rest to `<key>Detail` as JSON (code too, since the SDK
prefers a truthy code over name for exception.type), and stringifies every
other object value; a Date becomes its unquoted ISO string. It can sit on
the transport, keeping other transports nested, or be applied for every
transport with `createLogger({ flatten: 'otel' })` — the only option with
WinstonInstrumentation, which constructs its transport without a format.

`flatten: true` is unchanged and documented as the mode for transports
before 0.29. The README gains a transport-line matrix. A new spec drives
the real transport at 0.27, 0.31 and 0.34 (npm aliases) into the logs SDK
and asserts the exported attributes, including the two failure modes above.
@cuzzlor
cuzzlor merged commit c5dc96e into main Oct 16, 2026
1 check passed
@cuzzlor
cuzzlor deleted the feat/otel-attributes-format branch October 16, 2026 05:24
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.

1 participant