Skip to content

Conversation

AbhiPrasad
Copy link
Member

ref #16737

Right now if users use console.log like so:

console.log("here", "is", "my", "log", "statement");

The console logging integration will emit a log with log message "here is my log statement".

Some users would like it if we automatically paramaterized this into a template, given there are separate arguments being sent into the logging statement. So the above log statement would generate

{
  "sentry.message.template": "here {} {} {} {}",
  "sentry.message.parameter.0": "is",
  "sentry.message.parameter.1": "my",
  "sentry.message.parameter.2": "log",
  "sentry.message.parameter.3": "statement",
}

This paramaterization is what this PR does, which provides a much better user experience.

One edge case that we need to watch out for is console substitution patterns like %s, %d, %i, %f, %o, %O, %c. Read more about this in the MDN docs. When encountering a console substitution pattern in the string, we elect to not generate string templates, as parsing the string to evaluate it gets too complicated client side.

@AbhiPrasad AbhiPrasad requested a review from a team September 18, 2025 20:24
@AbhiPrasad AbhiPrasad self-assigned this Sep 18, 2025
@AbhiPrasad AbhiPrasad requested review from mydea and RulaKhaled and removed request for a team September 18, 2025 20:24
@AbhiPrasad AbhiPrasad changed the title feat(core): Create template attributes in consoleLoggingIntegration feat(core): Create template attributes in consoleLoggingIntegration Sep 18, 2025
Copy link
Contributor

github-actions bot commented Sep 18, 2025

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.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,813 - 9,201 -4%
GET With Sentry 1,378 16% 1,325 +4%
GET With Sentry (error only) 6,148 70% 6,064 +1%
POST Baseline 1,189 - 1,188 +0%
POST With Sentry 513 43% 528 -3%
POST With Sentry (error only) 1,072 90% 1,046 +2%
MYSQL Baseline 3,336 - 3,332 +0%
MYSQL With Sentry 472 14% 405 +17%
MYSQL With Sentry (error only) 2,721 82% 2,720 +0%

View base workflow run

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Can see how this is useful. Sounds like a good change to me!

@AbhiPrasad AbhiPrasad enabled auto-merge (squash) September 19, 2025 15:48
});

return attributes;
}
Copy link

Choose a reason for hiding this comment

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

Bug: Console Template Attributes Formatting Issues

The createConsoleTemplateAttributes function has two issues. The sentry.message.template attribute includes an unintended trailing space when no followingArgs are present. Additionally, sentry.message.parameter attributes are stored as raw values instead of structured objects with value/type, and null/undefined values are not converted to their expected string representations.

Fix in Cursor Fix in Web

@AbhiPrasad AbhiPrasad merged commit 0e0c711 into develop Sep 19, 2025
189 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-template-in-console branch September 19, 2025 16:06
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