Skip to content
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

feat(nextjs): Use OpenTelemetry for performance monitoring and tracing #11016

Merged
merged 36 commits into from Mar 27, 2024

Conversation

lforst
Copy link
Member

@lforst lforst commented Mar 11, 2024

This PR moves the Next.js over to OpenTelemetry based performance monitoring.

Resolves #11042

Follow-up items:

  •  Find more robust logic to filter out sentry ingest spans
  •  Investigate noisy data
  •  Check if we can remove the 5 second timeout in node tests again

Copy link
Contributor

github-actions bot commented Mar 18, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) 80.55 KB (0%)
@sentry/browser (incl. Tracing, Replay) 71.89 KB (0%)
@sentry/browser (incl. Tracing, Replay with Canvas) 75.7 KB (0%)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 65.44 KB (0%)
@sentry/browser (incl. Tracing) 36.71 KB (0%)
@sentry/browser (incl. browserTracingIntegration) 36.71 KB (0%)
@sentry/browser (incl. feedbackIntegration) 31.35 KB (0%)
@sentry/browser (incl. feedbackModalIntegration) 31.46 KB (0%)
@sentry/browser (incl. feedbackScreenshotIntegration) 31.47 KB (0%)
@sentry/browser (incl. sendFeedback) 27.42 KB (0%)
@sentry/browser 22.58 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) 74.9 KB (0%)
CDN Bundle (incl. Tracing, Replay) 69.73 KB (0%)
CDN Bundle (incl. Tracing) 36.3 KB (0%)
CDN Bundle 23.94 KB (0%)
CDN Bundle (incl. Tracing, Replay) - uncompressed 219.01 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 109.57 KB (0%)
CDN Bundle - uncompressed 70.92 KB (0%)
@sentry/react (incl. Tracing, Replay) 71.87 KB (0%)
@sentry/react 22.61 KB (0%)

@lforst lforst force-pushed the lforst-nextjs-otel branch 2 times, most recently from 33a4f94 to 815b156 Compare March 19, 2024 15:55
AbhiPrasad added a commit that referenced this pull request Mar 19, 2024
In order to proceed with removing `Sentry.Integrations.X` as per
#8844, there's
still some places to clean up.

This does conflict with
#11016, but not sure
when that merges in, so opening this in the meantime to unblock the
integrations cleanup work. if we think the OTEL nextjs work will merge
in sooner then the next 1-2 days, I'm happy to leave this alone for now!
@lforst lforst changed the title feat(nextjs): Use OTEL tracing feat(nextjs): Use OpenTelemetry for performance monitoring and tracing Mar 21, 2024
@@ -26,8 +26,20 @@
"wait-port": "1.0.4"
},
"devDependencies": {
"@sentry-internal/feedback": "latest || *",
Copy link
Member

Choose a reason for hiding this comment

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

Do we need all of these?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so, at least I couldn't be bothered to filter them out. These are all deps that nextjs depends on or could ever depend on.

@@ -13,7 +13,7 @@ test('Should send a transaction with a fetch span', async ({ page }) => {
data: expect.objectContaining({
'http.method': 'GET',
'sentry.op': 'http.client',
'sentry.origin': 'auto.http.node.undici',
'next.span_type': 'AppRender.fetch', // This span is created by Next.js own fetch instrumentation
Copy link
Member

Choose a reason for hiding this comment

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

l: We could think about adding sentry.origin: 'auto.http.nextjs.fetch' or something like this if we detect this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have started a broader discussion around this topic last week because we need a generic decision in all SDKs for this. The important question being: "What sentry.origin do we give spans that are not generated through Sentry SDK API?" Right now it is manual - which is obv wrong. I'd argue we don't set anything, because sentry.origin doesn't make sense anymore.

Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

Looking great! Left some small nitty-comments, great work (the outcome always looks so simple...! "it just works, what do you mean this was tricky???")

// if (nextjsVersion !== 'latest' && nextjsVersion !== 'canary') {
// assert.doesNotMatch(buildStderr, /Import trace for requested module/); // This is Next.js/Webpack speech for "something is off"
// }
// Note(lforst): I disabled this for the time being to figure out OTEL + Next.js - Next.js is currently complaining about a critical import in the @opentelemetry/instrumentation package.
Copy link
Member

Choose a reason for hiding this comment

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

For reference, what exactly is it complaining about?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment with an example!

@@ -29,8 +29,20 @@
"@playwright/test": "^1.27.1"
},
"devDependencies": {
"@sentry-internal/feedback": "latest || *",
Copy link
Member

Choose a reason for hiding this comment

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

Do we need all of these?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -117,19 +113,67 @@ export function init(options: NodeOptions): void {

nodeInit(opts);

const filterTransactions: EventProcessor = event => {
return event.type === 'transaction' && event.transaction === '/404' ? null : event;
const filterLowQualityTransactions: EventProcessor = event => {
Copy link
Member

Choose a reason for hiding this comment

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

Is it on purpose that we are not filtering /404 transactions anymore here? (or do these not exist anymore?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I think I accidentally removed this - added it back!

@@ -117,19 +113,67 @@ export function init(options: NodeOptions): void {

nodeInit(opts);

const filterTransactions: EventProcessor = event => {
return event.type === 'transaction' && event.transaction === '/404' ? null : event;
const filterLowQualityTransactions: EventProcessor = event => {
Copy link
Member

Choose a reason for hiding this comment

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

l: This is fine, but could also possible be simplified to:

addEventListener(Object.assign((event: Event) => {
 // ...
}, { id: 'NextLowQualityTransactionsFilter' }));

Not sure how much better, but avoids some local variables - feel free to ignore or not :D

Copy link
Member Author

Choose a reason for hiding this comment

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

love it

// Filter out spans for Sentry event sends
const httpTargetAttribute: unknown = span.data?.['http.target'];
if (typeof httpTargetAttribute === 'string') {
// TODO: Find a more robust matching logic
Copy link
Member

Choose a reason for hiding this comment

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

We should use suppressTracing here 🤔 something to look into in the future!

Copy link
Member

Choose a reason for hiding this comment

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

to be clear, with "here" I mean in the transport :D

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I'll add a TODO to potentially revisit this in the future.


filterTransactions.id = 'NextServer404TransactionFilter';
addEventProcessor(
Object.assign(
Copy link
Member

Choose a reason for hiding this comment

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

should we add these as integrations?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe in a followup. I want this pr closed asap.

@lforst lforst enabled auto-merge (squash) March 26, 2024 16:31
@lforst lforst merged commit 0e9cdee into develop Mar 27, 2024
93 checks passed
@lforst lforst deleted the lforst-nextjs-otel branch March 27, 2024 08:04
AbhiPrasad added a commit that referenced this pull request Mar 27, 2024
With this change, there are two remaining references to
node-experimental.

1. nextjs, which is handled by
#11016
2. express integration tests, which I will address after
#11285 gets merged

Once those two are done, we can remove the old node packages entirely!
s1gr1d added a commit that referenced this pull request Apr 9, 2024
Next.js provides their own OTel http integration, which conflicts with
ours
ref #11016
added commit from this PR:
#11319

---------

Co-authored-by: Luca Forstner <luca.forstner@sentry.io>
Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
cadesalaberry pushed a commit to cadesalaberry/sentry-javascript that referenced this pull request Apr 19, 2024
In order to proceed with removing `Sentry.Integrations.X` as per
getsentry#8844, there's
still some places to clean up.

This does conflict with
getsentry#11016, but not sure
when that merges in, so opening this in the meantime to unblock the
integrations cleanup work. if we think the OTEL nextjs work will merge
in sooner then the next 1-2 days, I'm happy to leave this alone for now!
cadesalaberry pushed a commit to cadesalaberry/sentry-javascript that referenced this pull request Apr 19, 2024
cadesalaberry pushed a commit to cadesalaberry/sentry-javascript that referenced this pull request Apr 19, 2024
With this change, there are two remaining references to
node-experimental.

1. nextjs, which is handled by
getsentry#11016
2. express integration tests, which I will address after
getsentry#11285 gets merged

Once those two are done, we can remove the old node packages entirely!
cadesalaberry pushed a commit to cadesalaberry/sentry-javascript that referenced this pull request Apr 19, 2024
Next.js provides their own OTel http integration, which conflicts with
ours
ref getsentry#11016
added commit from this PR:
getsentry#11319

---------

Co-authored-by: Luca Forstner <luca.forstner@sentry.io>
Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
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.

[v8] Port @sentry/nextjs to be powered by OpenTelemetry
4 participants