Skip to content

feat(consola): Enhance Consola integration to extract first-param object as searchable attributes#19534

Open
s1gr1d wants to merge 4 commits intodevelopfrom
sig/consola-obj-keys
Open

feat(consola): Enhance Consola integration to extract first-param object as searchable attributes#19534
s1gr1d wants to merge 4 commits intodevelopfrom
sig/consola-obj-keys

Conversation

@s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Feb 26, 2026

Aligns the Consola integration so object-first logs are structured and fallback logs get template + parameters.

Universal principle

  • Object-first (first argument is a plain object): object keys become log attributes, second argument (if string) is the message, remaining arguments → sentry.message.parameter.{0, 1, 2, ...}.
  • Fallback (first argument is not an object): message = formatted(all args), args[1:] → sentry.message.template and sentry.message.parameter.{0, 1, 2, ...} (same as console integration).

Consola-specific behavior

  • Consola-merged: For consola.log({ message: "x", userId, action }) Consola passes args: ["x"] and spreads the rest on the log object. We detect this (single string in args + extra keys on logObj) and treat it as one logical object: message = args[0], attributes = extra keys.
  • Object-first now applies to any plain object as first arg (including objects with message or args keys), so e.g. consola.log.raw({ message: "raw-hello" }) produces attributes from the object and an empty message.
  • Fallback uses the same template/parameter pattern as the console integration (no extraction of objects into top-level attributes; all post-first args go into the formatted message and sentry.message.parameter.*).

Example

// Object-first
consola.log({ userId: 123, action: "login" }, "User logged in");
// → message: "User logged in", attributes: { userId: 123, action: "login" }

// With extra parameters
consola.log({ userId: 123 }, "User action", requestId, timestamp);
// → message: "User action", userId: 123, sentry.message.parameter.0: requestId, .1: timestamp

// Fallback (non-object first)
consola.log("Legacy log", { data: 1 }, 123);
// → message: "Legacy log {\"data\":1} 123", sentry.message.template: "Legacy log {} {}", sentry.message.parameter.0/1

Console String substitutions are not added as a template attribute because parsing is too complicated on the client-side (see here: #17703)

Closes #18593

@s1gr1d s1gr1d changed the title Sig/consola obj keys feat(consola): Enhance Consola integration to extract first-param object as searchable attributes Feb 26, 2026
@s1gr1d s1gr1d force-pushed the sig/consola-obj-keys branch from c71c835 to fcfd91c Compare February 26, 2026 13:51
/**
* Extracts structured attributes from console arguments. If the first argument is a plain object, its properties are extracted as attributes.
*/
function defaultExtractAttributes(
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a function that could be theoretically added by users (as a future feature). That's why this function is extra from the processExtractedAttributes. In theory, it could just be one function.

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.62 kB - -
@sentry/browser - with treeshaking flags 24.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 flags 70.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/react 27.37 kB - -
@sentry/react (incl. Tracing) 44.76 kB - -
@sentry/vue 30.07 kB - -
@sentry/vue (incl. Tracing) 44.27 kB - -
@sentry/svelte 25.64 kB - -
CDN Bundle 28.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) 80.99 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 85.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.53 kB - -
CDN Bundle - uncompressed 82.34 kB - -
CDN Bundle (incl. Tracing) - uncompressed 128.06 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.18 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.89 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.84 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.94 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.76 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.66 kB - -
@sentry/nextjs (client) 47.17 kB - -
@sentry/sveltekit (client) 42.88 kB - -
@sentry/node-core 52.18 kB +0.02% +10 B 🔺
@sentry/node 174.48 kB +0.01% +5 B 🔺
@sentry/node - without tracing 97.33 kB +0.02% +10 B 🔺
@sentry/aws-serverless 113.13 kB +0.01% +8 B 🔺

View base workflow run

@github-actions
Copy link
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.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,168 - 9,319 -2%
GET With Sentry 1,655 18% 1,636 +1%
GET With Sentry (error only) 6,001 65% 5,856 +2%
POST Baseline 1,172 - 1,156 +1%
POST With Sentry 572 49% 557 +3%
POST With Sentry (error only) 1,012 86% 1,029 -2%
MYSQL Baseline 3,139 - 3,178 -1%
MYSQL With Sentry 365 12% 381 -4%
MYSQL With Sentry (error only) 2,597 83% 2,569 +1%

View base workflow run

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

@chargome chargome left a comment

Choose a reason for hiding this comment

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

🚀

/**
* Result of extracting structured attributes from console arguments.
*/
export interface ExtractAttributesResult {
Copy link
Member

Choose a reason for hiding this comment

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

l: I would not export this as long as the functions stays internal.

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.

Consola logging add object as extra data/context

2 participants