Skip to content

feat(consola): Enhance Consola integration to extract objects as searchable attributes - #18602

Closed
s1gr1d wants to merge 6 commits into
developfrom
sig/consola-objects
Closed

feat(consola): Enhance Consola integration to extract objects as searchable attributes#18602
s1gr1d wants to merge 6 commits into
developfrom
sig/consola-objects

Conversation

@s1gr1d

@s1gr1ds1gr1d commented Dec 22, 2025

Copy link
Copy Markdown
Member

⚠️Note to reviewers: This is a WIP and I will probably close/update this PR based on what we internally decide how to deal with variadic loggers.


When logging with Consola, objects passed as arguments were being serialized into the log message string, making the data non-searchable in Sentry:

consola.info('User logged in',{userId: 123,sessionId: 'abc-123'});

Before

Message = "User logged in {\"userId\":123,\"sessionId\":\"abc-123\"}"
Screenshot from Sentry (Consola vs Pino vs Winston)image

After

Extract object properties as individual log attributes, making them searchable and filterable in Sentry:

Message = "User logged in"
Attributes = { userId: 123, sessionId: 'abc-123', ... }

  • Arrays: stored as consola.args.N attributes
  • Set/Map: stringify their content
  • Primitives: remain in the message for readability
  • Conflicts with existing consola attributes are prevented

Aligns with how the Pino integration handles structured data. Example:

body: 'hello world',
trace_id: expect.any(String),
severity_number: 9,
attributes: {
name: {value: 'myapp',type: 'string'},
'pino.logger.level': {value: 30,type: 'integer'},
user: {value: 'user-id',type: 'string'},
something: {
type: 'string',
value: '{"more":3,"complex":"nope"}',
},

Now with the Consola integration in Sentry:

image

Closes#18593

Comment threadpackages/core/src/integrations/consola.ts Outdated
Comment threadpackages/core/src/integrations/consola.ts Outdated
Comment threadpackages/core/src/integrations/consola.ts Outdated
@github-actions

github-actionsBot commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

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.

ScenarioRequests/s% of BaselinePrev. Requests/sChange %
GET Baseline8,903-8,672+3%
GET With Sentry1,76620%1,656+7%
GET With Sentry (error only)6,08668%5,970+2%
POST Baseline1,213-1,188+2%
POST With Sentry60850%551+10%
POST With Sentry (error only)1,03685%1,052-2%
MYSQL Baseline3,327-3,240+3%
MYSQL With Sentry46214%400+16%
MYSQL With Sentry (error only)2,70181%2,650+2%

View base workflow run

Comment threadpackages/core/src/integrations/consola.ts Outdated
// Non-plain objects (Date, Error, Map, Set, etc.) and arrays: Store as args attribute so they get properly serialized
// Special handling for Map and Set to preserve their data
attributes[`consola.args.${contextIndex++}`] =
arg instanceof Map ? Object.fromEntries(arg) : arg instanceof Set ? Array.from(arg) : arg;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Non-plain objects can overwrite existing attribute keys

When storing non-plain objects (arrays, Date, Error, etc.), the code unconditionally sets attributes[\consola.args.${contextIndex++}`]without checking if the key already exists. This is inconsistent with the conflict prevention at lines 241-245 for plain objects. If a plain object contains a key like'consola.args.0'and is followed by an array in the args, the plain object's value will be silently overwritten by the array. This could cause unexpected data loss in edge cases where users happen to use keys matching theconsola.args.N` pattern.

Fix in CursorFix in Web

'server.address': { value: expect.any(String), type: 'string' },
'consola.type': { value: 'info', type: 'string' },
'consola.level': { value: 3, type: 'integer' },
key: { value: 'value', type: 'string' },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test missing assertion for array attribute extraction (Bugbot Rules)

Per the review rules: "Check that tests actually test the newly added behaviour. When checking on sent payloads by the SDK, ensure that the newly added data is asserted thoroughly." The test subject at subject-args.ts line 24 includes an array [1, 2, 3] in the args, which per the new feature should be stored as consola.args.0. However, the test's expected attributes at lines 285-295 only assert key: 'value' but not the consola.args.0 attribute for the array, leaving the array extraction behavior unverified in this test case.

Fix in CursorFix in Web

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser25.62 kB--
@sentry/browser - with treeshaking flags24.12 kB--
@sentry/browser (incl. Tracing)42.42 kB--
@sentry/browser (incl. Tracing, Profiling)47.09 kB--
@sentry/browser (incl. Tracing, Replay)81.24 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags70.86 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)85.94 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)98.2 kB--
@sentry/browser (incl. Feedback)42.43 kB--
@sentry/browser (incl. sendFeedback)30.29 kB--
@sentry/browser (incl. FeedbackAsync)35.34 kB--
@sentry/browser (incl. Metrics)26.79 kB--
@sentry/browser (incl. Logs)26.93 kB--
@sentry/browser (incl. Metrics & Logs)27.61 kB--
@sentry/react27.37 kB--
@sentry/react (incl. Tracing)44.76 kB--
@sentry/vue30.07 kB--
@sentry/vue (incl. Tracing)44.27 kB--
@sentry/svelte25.64 kB--
CDN Bundle28.16 kB--
CDN Bundle (incl. Tracing)43.25 kB--
CDN Bundle (incl. Logs, Metrics)29 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)44.09 kB--
CDN Bundle (incl. Replay, Logs, Metrics)68.08 kB--
CDN Bundle (incl. Tracing, Replay)80.13 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)81 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)85.65 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)86.53 kB--
CDN Bundle - uncompressed82.34 kB--
CDN Bundle (incl. Tracing) - uncompressed128.06 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed85.18 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed130.89 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed208.84 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed244.94 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed247.76 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed257.85 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed260.66 kB--
@sentry/nextjs (client)47.17 kB--
@sentry/sveltekit (client)42.89 kB--
@sentry/node-core52.18 kB+0.02%+9 B 🔺
@sentry/node173.45 kB+0.01%+8 B 🔺
@sentry/node - without tracing97.33 kB+0.01%+9 B 🔺
@sentry/aws-serverless113.13 kB+0.01%+7 B 🔺

View base workflow run

s1gr1d added a commit that referenced this pull request Feb 26, 2026
…`it.each`) (#19517)
Some small refactoring to make test cases better readable. Part of this PR (to make things easier reviewable):
#18602Closes#19518 (added automatically)
@s1gr1d

Copy link
Copy Markdown
MemberAuthor

Closing this in favor of this PR: #19534

@s1gr1ds1gr1d closed this Feb 26, 2026
s1gr1d added a commit that referenced this pull request Feb 26, 2026
The JS doc states that extra keys are added as `consola.` log
attributes. However, this is not the case.
Extra keys can be added by, for example, calling the Consola reporter
directly or by calling `consola.[type]({ message: '', ... })`.
Part of this PR (split up for better reviewing):
#18602Closes#19512 (added automatically)
Sign up for freeto 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.

Consola logging add object as extra data/context

1 participant

@s1gr1d