-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(bun): Instrument Bun.serve #9080
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
Bun tests are so crazy fast...
|
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.
clean <3
* Instruments Bun.serve by patching it's options. | ||
*/ | ||
export function instrumentBunServe(): void { | ||
Bun.serve = new Proxy(Bun.serve, { |
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.
dayum we're lucky this is just a field on a global - let's pray this never changes 🙏
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 don't think they'll break this for a while, but let's see.
|
||
const request = fetchArgs[0]; | ||
const upperCaseMethod = request.method.toUpperCase(); | ||
if (!options || upperCaseMethod === 'OPTIONS' || upperCaseMethod === 'HEAD') { |
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.
m: I might be blind but why do we check for the non-existence of options here? Is there anything preventing us from early-returning all the way at the top on requests with OPTIONS
and HEAD
?
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.
will adjust.
// In case we have a primitive, wrap it in the equivalent wrapper class (string -> String, etc.) so that we can | ||
// store a seen flag on it. | ||
const objectifiedErr = objectify(e); |
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.
m: Doesn't captureException already do this?
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 copied what we were doing in SvelteKit, but I think our event processing pipeline does do this. Let me adjust.
import { instrumentBunServe } from '../../src/integrations/bunserver'; | ||
import { getDefaultBunClientOptions } from '../helpers'; | ||
|
||
// Fun fact: Bun = 2 21 14 :) |
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.
:)
type: 'bun', | ||
handled: false, | ||
data: { | ||
function: 'serve', |
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.
Wasn't sure if serve
or fetch
is more correct but w/e
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.
yeah debated this too, will stick with serve for now, but we can always adjust later.
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.
pretty sweet! 🚀
ref #9042
Add automatic instrumentation for
Bun.serve
Simply do something like so:
and then get:
Link: https://sentry-sdks.sentry.io/discover/abhi-sentry-bun:f2e553067c7f49d58624963ca5e544ae/?field=title&field=event.type&field=project&field=user.display&field=timestamp&field=replayId&homepage=true&name=All+Events&project=4505841905238016&query=&sort=-timestamp&statsPeriod=1h&yAxis=count%28%29
Follow up note. We probably want to export a set of utilities for dealing with fetch + plain
Response
andRequest
web APIs for Sentry. For now decided to not do that so we can ship this faster.