Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(logs): Ensure client & scope can be passed to log functions #16874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mydea wants to merge 4 commits into develop
base: develop
Choose a base branch
Loading
from fn/browser-log-client

Conversation

Copy link
Member

@mydea mydea commented Jul 10, 2025

This adds support to provide a custom client & scope to log captureXX methods:

Sentry.logger.trace('log message', {}, client, scope);

This way, multi-client setups can work as well.

This also adds a size limit entry for browser + logs.

@mydea mydea requested a review from AbhiPrasad July 10, 2025 08:39
@mydea mydea self-assigned this Jul 10, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

github-actions bot commented Jul 10, 2025
edited
Loading

size-limit report 📦

⚠️ 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.

Path Size % Change Change
@sentry/browser 23.81 kB - -
@sentry/browser - with treeshaking flags 22.53 kB - -
@sentry/browser (incl. Tracing) 39.65 kB - -
@sentry/browser (incl. Tracing, Replay) 77.77 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.7 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 82.47 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 94.59 kB - -
@sentry/browser (incl. Feedback) 40.48 kB - -
@sentry/browser (incl. sendFeedback) 28.49 kB - -
@sentry/browser (incl. FeedbackAsync) 33.38 kB - -
@sentry/react 25.58 kB - -
@sentry/react (incl. Tracing) 41.62 kB - -
@sentry/vue 28.26 kB - -
@sentry/vue (incl. Tracing) 41.44 kB - -
@sentry/svelte 23.83 kB - -
CDN Bundle 25.36 kB - -
CDN Bundle (incl. Tracing) 39.61 kB - -
CDN Bundle (incl. Tracing, Replay) 75.55 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 81 kB - -
CDN Bundle - uncompressed 74.08 kB - -
CDN Bundle (incl. Tracing) - uncompressed 117.6 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.52 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 244.33 kB - -
@sentry/nextjs (client) 43.26 kB - -
@sentry/sveltekit (client) 40.09 kB - -
@sentry/node 167.85 kB +0.01% +1 B 🔺
@sentry/node - without tracing 100.59 kB +0.01% +1 B 🔺
@sentry/aws-serverless 128.69 kB - -
@sentry/browser (incl. Logs) 24.9 kB added added

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.

Bug: Type Guard Fails with Undefined or Array Arguments

The isTemplateArgs type guard, which relies on Array.isArray(args[1]), is flawed. If TypeScript types are bypassed at runtime, this can lead to incorrect argument classification:

  • If messageParams (the second argument for template logging) is undefined, it's incorrectly treated as parameterized arguments, causing argument misalignment where subsequent parameters are misinterpreted.
  • If attributes (the second argument for parameterized logging) is an array, it's incorrectly treated as template arguments, leading to runtime errors during destructuring.
packages/node-core/src/logs/capture.ts#L43-L46
function isTemplateArgs(args: CaptureLogArgs): args is CaptureLogsArgsTemplate {
return Array.isArray(args[1]);
}

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

mydea reacted with thumbs down emoji
Copy link
Collaborator

timfish commented Jul 10, 2025
edited
Loading

Should we make the additional args via an object so we can add args later without users needing to pass client/scope?

Sentry.logger.trace('log message', {}, { client, scope });

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

We need to update cloudflare and vercel-edge as well.

It's not ideal that this is duplicated so much, we'll eventually want to move things to @sentry/core, but right now there is an export collision with the sdk debug logger.

Copy link
Member Author

mydea commented Jul 11, 2025

Should we make the additional args via an object so we can add args later without users needing to pass client/scope?

Sentry.logger.trace('log message', {}, { client, scope });

No strong feelings, I have also thought about this a bit... WDYT @AbhiPrasad ?

Copy link
Member

No strong feelings, I have also thought about this a bit... WDYT

I would be open to an object, I think the bundle size hit is minuscule and it does make the API cleaner.

*/
function captureLog(
level: LogSeverityLevel,
message: ParameterizedString,
attributes?: Log['attributes'],
severityNumber?: Log['severityNumber'],
client?: Client,
scope?: Scope,
Copy link
Member

@AbhiPrasad AbhiPrasad Jul 17, 2025

Choose a reason for hiding this comment

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

I thought about this more, and I think we only need to accept a scope (because we can call scope.getClient() to get the client).

Maybe we can get this merged and backported to v9?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@AbhiPrasad AbhiPrasad AbhiPrasad left review comments

@cursor cursor[bot] cursor[bot] left review comments

At least 1 approving review is required to merge this pull request.

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /