-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
size-limit report 📦
|
There was a problem hiding this 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) isundefined
, 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
sentry-javascript/packages/node-core/src/logs/capture.ts
Lines 43 to 46 in bff9360
function isTemplateArgs(args: CaptureLogArgs): args is CaptureLogsArgsTemplate { | |
return Array.isArray(args[1]); | |
} |
Was this report helpful? Give feedback by reacting with 👍 or 👎
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 }); |
There was a problem hiding this 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
.
No strong feelings, I have also thought about this a bit... WDYT @AbhiPrasad ? |
I would be open to an object, I think the bundle size hit is minuscule and it does make the API cleaner. |
attributes?: Log['attributes'], | ||
severityNumber?: Log['severityNumber'], | ||
client?: Client, | ||
scope?: Scope, |
There was a problem hiding this comment.
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?
any updates on this PR? we really want to use logging in our Chrome Extension and we're stuck because this PR hasn't been merged. Anything we can do to help expedite merging this PR? @mydea @timfish @AbhiPrasad |
This is a bit stale, opened #17698 to tackle this on a new branch. |
…ds (#17698) Supercedes #16874 This PR makes two changes 1. It adds `logger` as an export to `@sentry/core`, and then refactors the `browser`, `cloudflare` and `vercel-edge` packages to just re-export `@sentry/core`'s logger. This change makes it easy to use logging in an isomorphic way, and reduces duplication between our various packages. We couldn't change the export from `node-core` because it has a different type signature than the standard logger. 2. It expands the logger exports to accept an optional scope argument. This allows for users to provide their own custom clients to the methods, which helps with standalone client cases. ```js import * as Sentry from "@sentry/browser"; const client = createMySentryClient(); const scope = new Sentry.Scope(); scope.setClient(client); Sentry.logger.info("Hello World!", {}, { scope }); ```
This adds support to provide a custom client & scope to log
captureXX
methods:This way, multi-client setups can work as well.
This also adds a size limit entry for browser + logs.