Skip to content

Problems with Next.js SDK + OTEL #11046

Closed
Closed
@lforst

Description

@lforst

Just a collection of things I noticed when trying out the Next.js SDK with our newest OTEL implementation. This list is WIP:

Findings:

  • Next.js is creating spans by itself as soon as we call Sentry.init().
  • Apparently, the @vercel/otel package has support for Edge runtime fetch instrumentation. We need to try this out.

Problems:

  • Root spans have garbage names and will therefore pollute the Performance tab
    • ✅ Kind of solved by setting forceTransaction: true for our own spans.
  • Not using instrument.ts to init the SDK will destroy parent-child relationships between Next.js spans and Sentry SDK spans. No friggin idea what is going on here.
    • ✅ Solved by forcing users to use instrumentation.ts
  • Since Next.js now creates root spans, the root span doesn't have much data at all (No headers, no tags, no anything).
  • Next.js created a lot of timed events which the SDK turned into error events
  • Flushing on Vercel doesn't work properly for spans created by OTEL.
    • Apparently, there is a waitUntil coming in Next.js which could solve this. Right now I don't have an idea on how to fix this. I tried
      adding a SIGTERM handler, I tried adding a custom spanprocessor that flushes. Nothing works.
    • ✅ We are using the waitUntil successfully now
  • For the time being we will still need out own auto-instrumentation for Edge API routes, and Edge Server components
  • Next.js crashes with the --turbo flag: require-in-the-middle is resolved to import-in-the-middle and crashing with turbopack vercel/next.js#64022
  • There is very weird log output when building and in the dev-server.
  • Dev server symbolification requests start traces (needs some mechanism to opt out of tracing for edge, browser, and node)
    • ✅ We suppress tracing for those
  • Edge runtime doesn't use otel yet, however we have runtime agnostic code that runs on edge and node, causing problems if we depend on Next.js creating spans, for example for API routes
  • Tracing doesn't work on Next.js 14 from version 14.0.1-canary.1, if we disable the Http integration (which we kinda have to). This PR in Next.js introduced this bug OpenTelemetry: propagate a configured context(s) to root requests vercel/next.js#57084
    • ✅ The httpIntegration doesn't work on Next.js 14. This seems to be somewhat fine though since Next.js itself creates http.server spans we can use
  • We need to filter server transactions for all kinds of static resources: CSS, Favicon, Fonts, ...
    • ✅ We employ a event processor
  • Suspended server components seem to be breaking out of the async context of the parent server component
    • ✅ We were just ending spans before the children are finished.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions