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/vercel-edge/cloudflare): Switch to OTEL for performance monitoring #13889

Merged
merged 30 commits into from
Oct 24, 2024

Conversation

lforst
Copy link
Member

@lforst lforst commented Oct 7, 2024

This PR is a collection of PRs enabling OTEL tracing for @sentry/nextjs, @sentry/vercel-edge, and by extension @sentry/cloudflare.

Tasks:

**This PR is part of a stacked PR sequence as we need to do many changes
at once for #8105.
Merging this PR as is will create inconsistent data.**

---

This PR will make the `@sentry/vercel-edge` SDK use OpenTelemetry
performance under the hood.

We need to employ a few hacks so that OpenTelemetry works on a worker
runtime:
- We are vendoring the OTEL `AsyncLocalStorageContextManage` because the
original implementation depends on `AsyncLocalStorage` as exported from
`async_hooks` which is not available in workers. In our vendored version
we are taking it from `globalThis.AsyncLocalStorage`.
- We are polyfilling `performance` with `Date.now()` as that API is not
available in worker runtimes.

Resolves #13740
Copy link
Contributor

github-actions bot commented Oct 7, 2024

size-limit report 📦

Path Size % Change Change
@sentry/browser 22.73 KB - -
@sentry/browser - with treeshaking flags 21.53 KB - -
@sentry/browser (incl. Tracing) 35.12 KB - -
@sentry/browser (incl. Tracing, Replay) 71.86 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.26 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 76.21 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 88.99 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 90.82 KB - -
@sentry/browser (incl. metrics) 27 KB - -
@sentry/browser (incl. Feedback) 39.87 KB - -
@sentry/browser (incl. sendFeedback) 27.38 KB - -
@sentry/browser (incl. FeedbackAsync) 32.17 KB - -
@sentry/react 25.49 KB - -
@sentry/react (incl. Tracing) 38.09 KB - -
@sentry/vue 26.91 KB - -
@sentry/vue (incl. Tracing) 37.02 KB - -
@sentry/svelte 22.87 KB - -
CDN Bundle 24.11 KB - -
CDN Bundle (incl. Tracing) 36.96 KB - -
CDN Bundle (incl. Tracing, Replay) 71.65 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 76.99 KB - -
CDN Bundle - uncompressed 70.7 KB - -
CDN Bundle (incl. Tracing) - uncompressed 109.73 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 222.24 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 235.46 KB - -
@sentry/nextjs (client) 38.17 KB +0.3% +115 B 🔺
@sentry/sveltekit (client) 35.74 KB - -
@sentry/node 124.96 KB -0.16% -198 B 🔽
@sentry/node - without tracing 94.01 KB -0.26% -247 B 🔽
@sentry/aws-serverless 103.62 KB -0.19% -200 B 🔽

View base workflow run

…13890)

Simply moves all runtime agnostic instrumentation related to the pages
router into its own folder.
@AbhiPrasad AbhiPrasad self-requested a review October 7, 2024 12:50
chargome and others added 3 commits October 8, 2024 15:55
…13904)

Drop all spans/transactions emitted by Next.js for pages router API
routes because they are currently super buggy with wrong timestamps. Fix
pending: vercel/next.js#70908

This is just a bit of prep-work so we can at some point disable the
logic where we turn on all Next.js spans and still have high quality
data.
lforst added 4 commits October 9, 2024 17:00
Disables the instrumentation for incoming HTTP requests to be consistent
across Next.js versions for instrumentation.

Next 13 and 15 work with the HTTP instrumentation. 14 doesn't.
…time (#13919)

We need to hoist the isolation scope forking logic out of the build-time
instrumentation.
…runtime (#13921)

We need to hoist the isolation scope forking logic out of the build-time
instrumentation.
Copy link

codecov bot commented Oct 10, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
627 1 626 37
View the top 1 failed tests by shortest run time
server-components.test.ts Sends a transaction for a request to app router
Stack Traces | 0.464s run time
server-components.test.ts:4:5 Sends a transaction for a request to app router

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

lforst and others added 9 commits October 16, 2024 11:23
Emit proper spans for the edge runtime, even if we don't have any
build-time instrumentation.
We use the preprocessEvent hook to pass the most up to date data to
users event processors and also not to trigger the logic that sets the
transaction source to custom when the transaction name is updated in
event processors.
@lforst lforst merged commit fe639f4 into develop Oct 24, 2024
147 checks passed
@lforst lforst deleted the lforst-nextjs-otel branch October 24, 2024 13:19
alexandresoro pushed a commit to alexandresoro/ouca that referenced this pull request Nov 3, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@sentry/node](https://github.com/getsentry/sentry-javascript/tree/master/packages/node) ([source](https://github.com/getsentry/sentry-javascript)) | dependencies | minor | [`8.35.0` -> `8.36.0`](https://renovatebot.com/diffs/npm/@sentry%2fnode/8.35.0/8.36.0) |
| [@sentry/react](https://github.com/getsentry/sentry-javascript/tree/master/packages/react) ([source](https://github.com/getsentry/sentry-javascript)) | dependencies | minor | [`8.35.0` -> `8.36.0`](https://renovatebot.com/diffs/npm/@sentry%2freact/8.35.0/8.36.0) |

---

### Release Notes

<details>
<summary>getsentry/sentry-javascript (@&#8203;sentry/node)</summary>

### [`v8.36.0`](https://github.com/getsentry/sentry-javascript/blob/HEAD/CHANGELOG.md#8360)

[Compare Source](getsentry/sentry-javascript@8.35.0...8.36.0)

##### Important Changes

-   **feat(nextjs/vercel-edge/cloudflare): Switch to OTEL for performance monitoring ([#&#8203;13889](getsentry/sentry-javascript#13889

With this release, the Sentry Next.js, and Cloudflare SDKs will now capture performance data based on OpenTelemetry.
Some exceptions apply in cases where Next.js captures inaccurate data itself.

NOTE: You may experience minor differences in transaction names in Sentry.
Most importantly transactions for serverside pages router invocations will now be named `GET /[param]/my/route` instead of `/[param]/my/route`.
This means that those transactions are now better aligned with the OpenTelemetry semantic conventions.

##### Other Changes

-   deps: Bump bundler plugins and CLI to 2.22.6 and 2.37.0 respectively ([#&#8203;14050](getsentry/sentry-javascript#14050))
-   feat(deps): bump [@&#8203;opentelemetry/instrumentation-aws-sdk](https://github.com/opentelemetry/instrumentation-aws-sdk) from 0.44.0 to 0.45.0 ([#&#8203;14099](getsentry/sentry-javascript#14099))
-   feat(deps): bump [@&#8203;opentelemetry/instrumentation-connect](https://github.com/opentelemetry/instrumentation-connect) from 0.39.0 to 0.40.0 ([#&#8203;14101](getsentry/sentry-javascript#14101))
-   feat(deps): bump [@&#8203;opentelemetry/instrumentation-express](https://github.com/opentelemetry/instrumentation-express) from 0.43.0 to 0.44.0 ([#&#8203;14102](getsentry/sentry-javascript#14102))
-   feat(deps): bump [@&#8203;opentelemetry/instrumentation-fs](https://github.com/opentelemetry/instrumentation-fs) from 0.15.0 to 0.16.0 ([#&#8203;14098](getsentry/sentry-javascript#14098))
-   feat(deps): bump [@&#8203;opentelemetry/instrumentation-kafkajs](https://github.com/opentelemetry/instrumentation-kafkajs) from 0.3.0 to 0.4.0 ([#&#8203;14100](getsentry/sentry-javascript#14100))
-   feat(nextjs): Add method and url to route handler request data ([#&#8203;14084](getsentry/sentry-javascript#14084))
-   feat(node): Add breadcrumbs for `child_process` and `worker_thread` ([#&#8203;13896](getsentry/sentry-javascript#13896))
-   fix(core): Ensure standalone spans are not sent if SDK is disabled ([#&#8203;14088](getsentry/sentry-javascript#14088))
-   fix(nextjs): Await flush in api handlers ([#&#8203;14023](getsentry/sentry-javascript#14023))
-   fix(nextjs): Don't leak webpack types into exports ([#&#8203;14116](getsentry/sentry-javascript#14116))
-   fix(nextjs): Fix matching logic for file convention type for root level components ([#&#8203;14038](getsentry/sentry-javascript#14038))
-   fix(nextjs): Respect directives in value injection loader ([#&#8203;14083](getsentry/sentry-javascript#14083))
-   fix(nuxt): Only wrap `.mjs` entry files in rollup ([#&#8203;14060](getsentry/sentry-javascript#14060))
-   fix(nuxt): Re-export all exported bindings ([#&#8203;14086](getsentry/sentry-javascript#14086))
-   fix(nuxt): Server-side setup in readme ([#&#8203;14049](getsentry/sentry-javascript#14049))
-   fix(profiling-node): Always warn when running on incompatible major version of Node.js ([#&#8203;14043](getsentry/sentry-javascript#14043))
-   fix(replay): Fix `onError` callback ([#&#8203;14002](getsentry/sentry-javascript#14002))
-   perf(otel): Only calculate current timestamp once ([#&#8203;14094](getsentry/sentry-javascript#14094))
-   test(browser-integration): Add sentry DSN route handler by default ([#&#8203;14095](getsentry/sentry-javascript#14095))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xMzguNiIsInVwZGF0ZWRJblZlciI6IjM4LjEzOC42IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=-->

Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/289
Reviewed-by: Alexandre Soro <[email protected]>
Co-authored-by: renovate <[email protected]>
Co-committed-by: renovate <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants