GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(cloudflare): Add `withSentry` method by AbhiPrasad · Pull Request #13025 · getsentry/sentry-javascript Conversation
Contributor
ref #12620 before reviewing this PR, I recommend reading through a writeup I did: #13007 This PR adds The implementation of
Usage looks something like so: import * as Sentry from '@sentry/cloudflare'; export default withSentry( (env) => ({ dsn: env.SENTRY_DSN, tracesSampleRate: 1.0, }), { async fetch(request, env, ctx) { return new Response('Hello World!'); }, } satisfies ExportedHandler<Env>, ); Next step here is to add more robust e2e tests, and then release an initial version!
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
AbhiPrasad
requested review from
andreiborza and
lforst
and removed request for
a team
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was an error while loading. Please reload this page.
size-limit report 📦
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| npm install @sentry/cloudflare | ||
| ``` | ||
|
|
||
| Then set either the `nodejs_compat` or `nodejs_als` compatibility flags in your `wrangler.toml`: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
l: Could we add a sentence of why this is needed? I saw Because we require tracing support as top-of-mind priority, AsyncLocalStorage support is a requirement of the SDK. in the issue you made.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done in 5671b7b
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Set user information, as well as tags and further extras | ||
| Sentry.setExtra('battery', 0.7); | ||
| Sentry.setTag('user_mode', 'admin'); | ||
| Sentry.setUser({ id: '4711' }); | ||
|
|
||
| // Add a breadcrumb for future events | ||
| Sentry.addBreadcrumb({ | ||
| message: 'My Breadcrumb', | ||
| // ... | ||
| }); | ||
|
|
||
| // Capture exceptions, messages or manual events | ||
| Sentry.captureMessage('Hello, world!'); | ||
| Sentry.captureException(new Error('Good bye')); | ||
| Sentry.captureEvent({ | ||
| message: 'Manual', | ||
| stacktrace: [ | ||
| // ... | ||
| ], | ||
| }); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
q: From your issue:
This needs to be done because workers can change their bindings (env) without re-deploying the entire worker, so a top-level Sentry.init call would become stale.
Wouldn't these suffer from the same issue of going stale?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nope, because under the hood they call getClient() which should always have the current client in the handler execution context, therefore will stay up-to-date.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| setHttpStatus(span, res.status); | ||
| return res; | ||
| } catch (e) { | ||
| captureException(e, { mechanism: { handled: false } }); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
q: I've seen some sdks add additional keys to mechanism, e.g. type: 'bun', do we want that here too? why or why not?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As per the develop docs
Required unique identifier of this mechanism determining rendering and processing of the mechanism data.
In the Python SDK this is merely the name of the framework integration that produced the exception, while for native it is e.g. "minidump" or "applecrashreport".
Changed with 309c05a
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,300 @@ | |||
| // Note: These tests run the handler in Node.js, which is has some differences to the cloudflare workers runtime. | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| // Note: These tests run the handler in Node.js, which is has some differences to the cloudflare workers runtime. | |
| // Note: These tests run the handler in Node.js, which has some differences to the cloudflare workers runtime. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Changed with 61ad09f
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const handler = { | ||
| async fetch(_request, _env, _context) { | ||
| expect(SentryCore.getClient() instanceof CloudflareClient).toBe(true); | ||
| return new Response('test'); | ||
| }, | ||
| } satisfies ExportedHandler; | ||
|
|
||
| const context = createMockExecutionContext(); | ||
| const wrappedHandler = withSentry(() => ({}), handler); | ||
| await wrappedHandler.fetch(new Request('https://example.com'), MOCK_ENV, context); | ||
|
|
||
| expect.assertions(1); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
m: I think a robuster way to write this is to create a vi.fn that gets called with SentryCore.getClient() and assert that it has been called with that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Good call!
Changed with 61ad09f
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const handler = { | ||
| async fetch(_request, _env, _context) { | ||
| SentryCore.captureMessage('test'); | ||
| return new Response('test'); | ||
| }, | ||
| } satisfies ExportedHandler; | ||
|
|
||
| let sentryEvent: Event = {}; | ||
| const wrappedHandler = withSentry( | ||
| (env: any) => ({ | ||
| dsn: env.MOCK_DSN, | ||
| beforeSend(event) { | ||
| sentryEvent = event; | ||
| return null; | ||
| }, | ||
| }), | ||
| handler, | ||
| ); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
l: can we extract this into a helper just call that in the next few tests?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'll come back to take a look at this after this PR merges, good suggestion.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| import * as SentryCore from '@sentry/core'; | ||
| import { init } from '../src/sdk'; | ||
|
|
||
| describe('init', () => { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
m: could we add a test for init returning a client?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Changed with 87b4fa1
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| export default withSentry( | ||
| (env) => ({ | ||
| dsn: env.SENTRY_DSN, | ||
| tracesSampleRate: 1.0, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment explaining this value?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done in 5671b7b
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
very nice!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
87b4fa1 to
e02e283
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.