Skip to content

Conversation

@lforst
Copy link
Contributor

@lforst lforst commented Jan 13, 2023

Ref #6120
Ref #4206

This PR adds two wrappers, withSentryAPI and withSentryMiddleware, to the mini Edge Runtime SDK for Next.js that allow users to wrap their Edge routes and middleware with error and performance instrumentation.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 13, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.84 KB (-0.02% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 61.46 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.61 KB (+0.01% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 55 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.37 KB (0%)
@sentry/browser - Webpack (minified) 66.54 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.4 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.63 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.82 KB (+0.02% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.25 KB (-0.01% 🔽)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 43.35 KB (-0.84% 🔽)
@sentry/replay - Webpack (gzipped + minified) 38.58 KB (-0.97% 🔽)

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.

🫡


span?.setStatus('internal_error');

captureException(objectifiedErr);
Copy link
Member

Choose a reason for hiding this comment

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

l: passing in the event processor above through capture context might help if we have scope bleeding issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah nice I like that - 1835aae

/**
* Wraps a Next.js edge route handler with Sentry error and performance instrumentation.
*/
export function withSentryAPI<H extends EdgeRouteHandler>(
Copy link
Member

Choose a reason for hiding this comment

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

l: Could we get some unit tests for this logic? In particular for the dynamic nature of spanLabel and spanOp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 76e4815

// We cannot make any assumptions about what users define as their handler except maybe that it is a function
export interface EdgeRouteHandler {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(req: any): any | Promise<any>;
Copy link
Member

Choose a reason for hiding this comment

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

l: Should we use unknown?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, we have to go with any here because making it unknown would cause TS errors when people pass in their original functions into the wrappers.

*/
export function withEdgeWrapping<H extends EdgeRouteHandler>(
handler: H,
options: { spanLabel: string; spanOp: string; mechanismFunctionName: string },
Copy link
Member

Choose a reason for hiding this comment

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

m: why don't we use spanDescription instead of spanLabel here? I think we should keep the span option naming consistent.

Though spans having descriptions and transactions having names is still something I feel we gotta fix somehow.

applies to the other uses as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, agree 924850f

@lforst lforst enabled auto-merge (squash) January 16, 2023 10:56
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.

3 participants