Skip to content

Fix instrumentation hook awaiting for middleware with adapters#95357

Merged
mischnic merged 3 commits into
canaryfrom
mischnic/await-instrumentation-2
Jul 6, 2026
Merged

Fix instrumentation hook awaiting for middleware with adapters#95357
mischnic merged 3 commits into
canaryfrom
mischnic/await-instrumentation-2

Conversation

@mischnic

@mischnic mischnic commented Jul 1, 2026

Copy link
Copy Markdown
Member

#94306 fixes this for pages, but middleware was still broken when deployed via adapters

Coming from getsentry/sentry-javascript#21713

Now the instrumentation test suite takes 11m to run in deployment mode though....

mischnic commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: aba87c6

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Stats cancelled

Commit: aba87c6
View workflow run

@mischnic mischnic changed the title deploy all tests Fixup instrumentation hook awaiting Jul 1, 2026
@mischnic mischnic changed the title Fixup instrumentation hook awaiting Fix instrumentation hook awaiting Jul 1, 2026
Comment thread test/e2e/instrumentation-hook/with-esm-import/instrumentation.js Outdated
@mischnic mischnic force-pushed the mischnic/await-instrumentation-2 branch from dab1e59 to cba4ebf Compare July 1, 2026 13:29
@mischnic mischnic changed the title Fix instrumentation hook awaiting Fix instrumentation hook awaiting for middleware Jul 1, 2026
@mischnic mischnic changed the title Fix instrumentation hook awaiting for middleware Fix instrumentation hook awaiting for middleware with adapters Jul 1, 2026
@mischnic mischnic force-pushed the mischnic/await-instrumentation-2 branch 2 times, most recently from 76297f9 to 71c5a36 Compare July 2, 2026 18:20
@mischnic mischnic marked this pull request as ready for review July 2, 2026 20:28
@mischnic mischnic changed the base branch from canary to graphite-base/95357 July 3, 2026 06:36
@mischnic mischnic force-pushed the mischnic/await-instrumentation-2 branch from 71c5a36 to b516fd8 Compare July 3, 2026 06:36
@mischnic mischnic changed the base branch from graphite-base/95357 to mischnic/webpack-tempalte-require-rerwite July 3, 2026 06:36
vercel[bot]

This comment was marked as resolved.

@mischnic mischnic force-pushed the mischnic/await-instrumentation-2 branch from b516fd8 to 7f5b4c2 Compare July 3, 2026 07:57
@mischnic mischnic force-pushed the mischnic/webpack-tempalte-require-rerwite branch from 4f31060 to 3a82587 Compare July 3, 2026 07:57
Base automatically changed from mischnic/webpack-tempalte-require-rerwite to canary July 6, 2026 10:01
@mischnic mischnic force-pushed the mischnic/await-instrumentation-2 branch from 7f5b4c2 to aba87c6 Compare July 6, 2026 10:02
@mischnic mischnic merged commit 70165e9 into canary Jul 6, 2026
130 of 131 checks passed
@mischnic mischnic deleted the mischnic/await-instrumentation-2 branch July 6, 2026 12:21
mischnic added a commit that referenced this pull request Jul 6, 2026
Node.js Middleware was inheriting the wrong parent span (and behaved
differently compared to Edge runtime Middleware)

`Middleware.execute` and `BaseServer.handleRequest` should be sibling
spans (depending on context, both are root spans). Previously
`BaseServer.handleRequest` had a child span `Middleware.execute`

Depends on #95357 to make the
direct entrypoint test pass
mischnic added a commit that referenced this pull request Jul 7, 2026
Fixup for #95357

`.handler()` is used by adapters
but `.default()` (=`internalHandler`) is the legacy entrypoint and used
by the non-adapter setup

Also needs vercel/vercel#16944
chargome added a commit to getsentry/sentry-javascript that referenced this pull request Jul 7, 2026
#22013)

Middleware spans on node (`middelware/proxy`) now run in a detached otel
context making `Middleware.execute` become root spans.

We basically now mirror what we did in edge before by also calling
`enhanceMiddlewareRootSpan` on node. Additionally we had to fork
isolation scopes on span start for these spans as these would scope leak
otherwise.

ref vercel/next.js#95357
closes #22001
closes #22002
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.

2 participants