Skip to content

feat(winston): Add customLevelMap for winston transport#18922

Merged
JPeer264 merged 4 commits intodevelopfrom
jp/winston-custom-levels
Jan 27, 2026
Merged

feat(winston): Add customLevelMap for winston transport#18922
JPeer264 merged 4 commits intodevelopfrom
jp/winston-custom-levels

Conversation

@JPeer264
Copy link
Member

@JPeer264 JPeer264 commented Jan 21, 2026

closes #18868
closes JS-1498

ATM it is not possible to map custom levels to OpenTelemetry levels. The option customLevelMap has been added to make this possible. Which means that custom levels would have never been send to Sentry, as they were not mapped correctly.

Now when there are custom levels it can be used like this:

const customLevels = {
  levels: {
    customCritical: 0,
    customNotice: 2,
  },
};

const SentryWinstonTransport = Sentry.createSentryWinstonTransport(Transport, {
  customLevelMap: {
    customCritical: 'fatal',
    customNotice: 'info',
  },
});

const mappedLogger = winston.createLogger({
  levels: customLevels.levels,
  level: 'customNotice', // this needs to be added due to https://github.com/winstonjs/winston/issues/1491
  transports: [new SentryWinstonTransport()],
});

Merge checklist

  • Sentry Docs update issue has been created

@JPeer264 JPeer264 requested review from nicohrubec and s1gr1d January 21, 2026 13:56
@JPeer264 JPeer264 self-assigned this Jan 21, 2026
@linear
Copy link

linear bot commented Jan 21, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Jan 21, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,675 - 8,786 -1%
GET With Sentry 1,623 19% 1,657 -2%
GET With Sentry (error only) 6,045 70% 5,978 +1%
POST Baseline 1,207 - 1,181 +2%
POST With Sentry 592 49% 583 +2%
POST With Sentry (error only) 1,056 87% 1,039 +2%
MYSQL Baseline 3,221 - 3,229 -0%
MYSQL With Sentry 459 14% 422 +9%
MYSQL With Sentry (error only) 2,622 81% 2,665 -2%

View base workflow run

Copy link
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

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

Looks good, but I am wondering if we can auto-detect those levels so users don't have to manually add them 🤔

attributes[SPLAT_SYMBOL] = undefined;

const logSeverityLevel = WINSTON_LEVEL_TO_LOG_SEVERITY_LEVEL_MAP[levelFromSymbol as string] ?? 'info';
const customLevel = sentryWinstonOptions?.customLevelMap?.[levelFromSymbol as string];
Copy link
Member

@nicohrubec nicohrubec Jan 23, 2026

Choose a reason for hiding this comment

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

m: would it make sense to warn the user in case he provides a sentry level that does not exist?

Copy link
Member Author

Choose a reason for hiding this comment

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

That could actually make sense

Copy link
Member Author

Choose a reason for hiding this comment

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

@nicohrubec I added a debug warning now. This is however only then when levels are overwritten. In all other cases they will default to info already

@JPeer264
Copy link
Member Author

I am wondering if we can auto-detect those levels so users don't have to manually add them 🤔

That shouldn't be a problem. The main problem is what it should get mapped to. myCustomLevel would be impossible for us to identify if this is an error or info

@JPeer264 JPeer264 requested a review from nicohrubec January 26, 2026 12:02
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Copy link
Member

@nicohrubec nicohrubec left a comment

Choose a reason for hiding this comment

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

nice

@JPeer264 JPeer264 force-pushed the jp/winston-custom-levels branch from 2f4c56e to c2dece0 Compare January 27, 2026 08:34
@JPeer264 JPeer264 enabled auto-merge (squash) January 27, 2026 08:49
@JPeer264 JPeer264 merged commit 11f38a7 into develop Jan 27, 2026
153 checks passed
@JPeer264 JPeer264 deleted the jp/winston-custom-levels branch January 27, 2026 08: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.

Allow customization of level mapping in createSentryWinstonTransport

3 participants