Skip to content

Conversation

logaretm
Copy link
Collaborator

@logaretm logaretm commented Sep 26, 2025

This pull request introduces instrumentation for Nuxt middleware, ensuring that all middleware handlers are automatically wrapped with tracing and error reporting functionality. The integration is achieved through build-time transformation.

recap:

  • Adds a new build-time Rollup plugin (middlewareInstrumentationPlugin) that automatically wraps all detected middleware handlers with Sentry instrumentation during the Nitro build process.
  • Implements the wrapMiddlewareHandler utility, which wraps middleware handlers to start a Sentry span, capture request data, record exceptions, and flush events in serverless environments.
  • Updates the Nuxt module setup to inject Sentry middleware imports and instrumentation hooks during initialization, ensuring the new tracing logic is included in server builds.

Note

Adds build-time wrapping of Nuxt server middleware with Sentry spans and error capture, plus Nuxt 3/4 e2e and unit tests.

  • SDK/Runtime:
    • Implement wrapMiddlewareHandlerWithSentry in packages/nuxt/src/runtime/hooks/wrapMiddlewareHandler.ts to start spans, set attributes (op, origin, route, method, headers), handle hook arrays (onRequest, onBeforeResponse), and capture errors.
    • Add middleware build-time transformation via packages/nuxt/src/vite/middlewareConfig.ts (server import + Rollup plugin to wrap defineEventHandler/eventHandler).
    • Integrate instrumentation in packages/nuxt/src/module.ts by calling addMiddlewareImports and addMiddlewareInstrumentation during Nitro init when server config is present.
  • Tests:
    • Add e2e apps and Playwright tests for Nuxt 3 and Nuxt 4 (dev-packages/e2e-tests/test-applications/nuxt-{3,4}) covering span creation, attributes, parent-child relationships, and error propagation across hooks and arrays.
    • Add unit tests for wrapper behavior in packages/nuxt/test/runtime/hooks/wrapMiddlewareHandler.test.ts.

Written by Cursor Bugbot for commit 9a4a1f3. This will update automatically on new commits. Configure here.

@logaretm logaretm changed the title feat: implement nuxt server middleware instrumentation feat(nuxt): implement server middleware instrumentation Sep 26, 2025
Copy link
Contributor

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,588 - 8,926 -4%
GET With Sentry 1,338 16% 1,388 -4%
GET With Sentry (error only) 6,109 71% 6,167 -1%
POST Baseline 1,197 - 1,192 +0%
POST With Sentry 528 44% 521 +1%
POST With Sentry (error only) 1,063 89% 1,034 +3%
MYSQL Baseline 3,338 - 3,366 -1%
MYSQL With Sentry 513 15% 468 +10%
MYSQL With Sentry (error only) 2,754 83% 2,732 +1%

View base workflow run

@logaretm logaretm force-pushed the awad/instrument-nuxt-nitro-middlewares branch from e7b0353 to a8ce604 Compare September 26, 2025 14:00
@mydea mydea changed the title feat(nuxt): implement server middleware instrumentation feat(nuxt): Implement server middleware instrumentation Sep 29, 2025
@logaretm logaretm force-pushed the awad/instrument-nuxt-nitro-middlewares branch from e62e50c to 2523f18 Compare September 29, 2025 13:43
@logaretm logaretm marked this pull request as ready for review September 29, 2025 14:01
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

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

Super nice! I like this approach.

@logaretm logaretm force-pushed the awad/instrument-nuxt-nitro-middlewares branch from 2523f18 to f79850e Compare September 30, 2025 08:32
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@logaretm logaretm merged commit 264ad0b into develop Sep 30, 2025
68 of 69 checks passed
@logaretm logaretm deleted the awad/instrument-nuxt-nitro-middlewares branch September 30, 2025 09:42
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