Skip to content

Conversation

@trentm
Copy link
Contributor

@trentm trentm commented Jul 23, 2025

Before this change the "log sending" feature of instr-winston would
incorrectly include ANSI color codes in the severityText for emitted
OTel LogRecords when the winston logger being instrumented was
configured with the colorize() formatter, e.g.:

const logger = winston.createLogger({
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.colorize(),
    winston.format.simple()
  ),
  ...

This is because the winston-transport.OpenTelemetryTransportV3 was using
the Winston log info's "level" attribute... which was tweaked by
colorize(). Winston log info objects have a Symbol.for("info")
property which has the unchanged level name:
https://github.com/winstonjs/winston#streams-objectmode-and-info-objects

This commit also changes (fix) what npm test runs in the
instrumentation-winston package. Before this, npm test was attempting
to test against winston@2 and winston@3 -- presumably for better
coverage. However, it ended up only ever testing with winston@2
(test-v1-v2 would install winston@2 and test, then test-v3 would
run the same test again with whatever current version is installed,
which is now winston@2).

The (IMO) correct answer here is:

  • npm test tests against the latest ver of the target module (winston@3)
  • npm run test-all-versions handles testing against other versions
  • coverage can take a back seat. (Aside: changes coming as part of
    chore: improve test workflow and coverage reports #2866
    will, IIUC, provide coverage from test-all-versions runs.)

Closes: #2952

…rityText and severityNumber with winston.format.colorize() is used

Before this change the "log sending" feature of instr-winston would
incorrectly include ANSI color codes in the `severityText` for emitted
OTel LogRecords when the winston logger being instrumented was
configured with the `colorize()` formatter, e.g.:

    const logger = winston.createLogger({
      format: winston.format.combine(
        winston.format.timestamp(),
        winston.format.colorize(),
        winston.format.simple()
      ),
      ...

This is because the winston-transport.OpenTelemetryTransportV3 was using
the Winston log info's "level" attribute... which was tweaked by
`colorize()`. Winston log `info` objects have a `Symbol.for("info")`
property which has the unchanged level name:
  https://github.com/winstonjs/winston#streams-objectmode-and-info-objects

This commit *also* changes (fix) what `npm test` runs in the
instrumentation-winston package. Before this, `npm test` was attempting
to test against winston@2 and winston@3 -- presumably for better
coverage. However, it ended up only ever testing with winston@2
(`test-v1-v2` would install winston@2 and test, then `test-v3` would
run the same test again with whatever current version is installed,
which is now winston@2).

The (IMO) correct answer here is:
- `npm test` tests against the latest ver of the target module (winston@3)
- `npm run test-all-versions` handles testing against other versions
- coverage can take a back seat. (Aside: changes coming as part of
  open-telemetry#2866
  will, IIUC, provide coverage from test-all-versions runs.)
@trentm
Copy link
Contributor Author

trentm commented Jul 23, 2025

Before this, npm test was attempting
to test against winston@2 and winston@3 -- presumably for better
coverage.

Yup.
My changes here are undoing what was done in #2684

@codecov
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@215c2b5). Learn more about missing BASE report.
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2956   +/-   ##
=======================================
  Coverage        ?   89.90%           
=======================================
  Files           ?      188           
  Lines           ?     9222           
  Branches        ?     1900           
=======================================
  Hits            ?     8291           
  Misses          ?      931           
  Partials        ?        0           
Files with missing lines Coverage Δ
packages/winston-transport/src/utils.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@hectorhdzg hectorhdzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for taking care of this

…n the info object passed to OpenTelemetryTransportV3 for testing
@trentm trentm merged commit 952abc7 into open-telemetry:main Jul 30, 2025
23 checks passed
@trentm trentm deleted the trentm-winston-issue-2952 branch July 30, 2025 16:05
@dyladan dyladan mentioned this pull request Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected ANSI color codes appearing in the severityText field

4 participants