-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(nitro): Nitro SDK #19224
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
base: develop
Are you sure you want to change the base?
feat(nitro): Nitro SDK #19224
Changes from all commits
cd76308
3149c41
abc20f7
7b73736
39fba11
2d0f13a
ab55d18
9ded4c9
5f43f63
ff579f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module.exports = { | ||
| env: { | ||
| browser: true, | ||
| node: true, | ||
| }, | ||
| extends: ['../../.eslintrc.js'], | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2023 Functional Software, Inc. dba Sentry | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the "Software"), to deal in | ||
| the Software without restriction, including without limitation the rights to | ||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
| of the Software, and to permit persons to whom the Software is furnished to do | ||
| so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,126 @@ | ||||||||||||||||||||||||||
| <p align="center"> | ||||||||||||||||||||||||||
| <a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank"> | ||||||||||||||||||||||||||
| <img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84"> | ||||||||||||||||||||||||||
| </a> | ||||||||||||||||||||||||||
| </p> | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Official Sentry SDK for Nitro | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [](https://www.npmjs.com/package/@sentry/nitro) | ||||||||||||||||||||||||||
| [](https://www.npmjs.com/package/@sentry/nitro) | ||||||||||||||||||||||||||
| [](https://www.npmjs.com/package/@sentry/nitro) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Links | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - [Official Nitro SDK Docs](https://docs.sentry.io/platforms/javascript/guides/nitro/) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Compatibility | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The minimum supported version of Nitro is `3.0.0-alpha.1`. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## General | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| This package is a wrapper around `@sentry/node` with added instrumentation for Nitro's features like: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - HTTP handlers and error capturing. | ||||||||||||||||||||||||||
| - [Middleware instrumentation](https://nitro.build/guide/routing#middleware). | ||||||||||||||||||||||||||
| <!-- - [Database instrumentation](https://nitro.build/guide/database). --> | ||||||||||||||||||||||||||
| <!-- - [KV Storage](https://nitro.build/guide/storage) and [Cache](https://nitro.build/guide/cache) instrumentation. --> | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Manual Setup | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### 1. Prerequisites & Installation | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 1. Install the Sentry Nitro SDK: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||
| # Using npm | ||||||||||||||||||||||||||
| npm install @sentry/nitro | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Using yarn | ||||||||||||||||||||||||||
| yarn add @sentry/nitro | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Using pnpm | ||||||||||||||||||||||||||
| pnpm add @sentry/nitro | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### 2. Nitro Config Setup | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| 1. Import `withSentryConfig` from `@sentry/nitro` and call it with your Nitro config. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #### In `nitro.config.ts` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| If you are using a dedicated `nitro.config.ts` file, you can import `withSentryConfig` from `@sentry/nitro` and call it with your Nitro config. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```javascript | ||||||||||||||||||||||||||
| import { defineNitroConfig } from 'nitro/config'; | ||||||||||||||||||||||||||
| import { withSentryConfig } from '@sentry/nitro'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const config = defineNitroConfig({ | ||||||||||||||||||||||||||
| // ... | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export default withSentryConfig(config, { | ||||||||||||||||||||||||||
| // Sentry Build Options | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #### In `vite.config.ts` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| If you are using nitro as a Vite plugin, you can import `withSentryConfig` from `@sentry/nitro` and call it with your Nitro config. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```ts | ||||||||||||||||||||||||||
| import { defineConfig } from 'vite'; | ||||||||||||||||||||||||||
| import { nitro } from 'nitro/vite'; | ||||||||||||||||||||||||||
| import { withSentryConfig } from '@sentry/nitro'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export default defineConfig({ | ||||||||||||||||||||||||||
| plugins: [nitro()], | ||||||||||||||||||||||||||
| nitro: withSentryConfig( | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| // Nitro options | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| // Sentry Build Options | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### 3. Sentry Config Setup | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Create an `instrument.mjs` file in your project root to initialize the Sentry SDK: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```javascript | ||||||||||||||||||||||||||
| import * as Sentry from '@sentry/nitro'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Sentry.init({ | ||||||||||||||||||||||||||
| dsn: '__YOUR_DSN__', | ||||||||||||||||||||||||||
| tracesSampleRate: 1.0, | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Then use `NODE_OPTIONS` to load the instrumentation before your app code: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||
| NODE_OPTIONS='--import ./instrument.mjs' npx nitro dev | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| This works with any Nitro command (`nitro dev`, `nitro preview`, or a production start script). | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Uploading Source Maps | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The `withSentryConfig` function automatically configures source map uploading when the `authToken`, `org`, and `project` | ||||||||||||||||||||||||||
| options are provided: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```javascript | ||||||||||||||||||||||||||
| export default withSentryConfig(config, { | ||||||||||||||||||||||||||
| org: 'your-sentry-org', | ||||||||||||||||||||||||||
| project: 'your-sentry-project', | ||||||||||||||||||||||||||
| authToken: process.env.SENTRY_AUTH_TOKEN, | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+111
to
+123
|
||||||||||||||||||||||||||
| ## Uploading Source Maps | |
| The `withSentryConfig` function automatically configures source map uploading when the `authToken`, `org`, and `project` | |
| options are provided: | |
| ```javascript | |
| export default withSentryConfig(config, { | |
| org: 'your-sentry-org', | |
| project: 'your-sentry-project', | |
| authToken: process.env.SENTRY_AUTH_TOKEN, | |
| }); | |
| ``` |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||||||||||||
| { | ||||||||||||||||
| "name": "@sentry/nitro", | ||||||||||||||||
| "version": "10.48.0", | ||||||||||||||||
| "description": "Official Sentry SDK for Nitro", | ||||||||||||||||
| "repository": "git://github.com/getsentry/sentry-javascript.git", | ||||||||||||||||
| "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/nitro", | ||||||||||||||||
| "author": "Sentry", | ||||||||||||||||
| "license": "MIT", | ||||||||||||||||
| "engines": { | ||||||||||||||||
| "node": ">=18.19.1" | ||||||||||||||||
| }, | ||||||||||||||||
| "files": [ | ||||||||||||||||
| "/build" | ||||||||||||||||
| ], | ||||||||||||||||
| "main": "build/esm/index.js", | ||||||||||||||||
| "module": "build/esm/index.js", | ||||||||||||||||
| "types": "build/types/index.d.ts", | ||||||||||||||||
| "typesVersions": { | ||||||||||||||||
| "*": { | ||||||||||||||||
| "plugins": [ | ||||||||||||||||
| "build/types/plugins.d.ts" | ||||||||||||||||
| ] | ||||||||||||||||
| } | ||||||||||||||||
| }, | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead
|
||||||||||||||||
| "typesVersions": { | |
| "*": { | |
| "plugins": [ | |
| "build/types/plugins.d.ts" | |
| ] | |
| } | |
| }, |
Copilot
AI
Apr 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related: the exports map doesn’t include a ./plugins entry, so consumers can’t import @sentry/nitro/plugins at runtime (and depending on TS settings, the typesVersions mapping may not help). Either add the ./plugins entrypoint (runtime + types) or remove the subpath mapping until it exists.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; | ||
|
|
||
| export default [ | ||
| ...makeNPMConfigVariants( | ||
| makeBaseNPMConfig({ | ||
| entrypoints: ['src/index.ts'], | ||
| packageSpecificConfig: { | ||
| external: [/^nitro/], | ||
| }, | ||
| }), | ||
| { emitCjs: false }, | ||
| ), | ||
| ]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| declare const __DEBUG_BUILD__: boolean; | ||
|
|
||
| /** | ||
| * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code. | ||
| * | ||
| * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking. | ||
| */ | ||
| export const DEBUG_BUILD = __DEBUG_BUILD__; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||||||||||||||
| import type { NitroConfig } from 'nitro/types'; | ||||||||||||||||||
| import { createNitroModule } from './module'; | ||||||||||||||||||
|
|
||||||||||||||||||
| type SentryNitroOptions = { | ||||||||||||||||||
| // TODO: Add options | ||||||||||||||||||
|
||||||||||||||||||
| // TODO: Add options | |
| org?: string; | |
| project?: string; | |
| authToken?: string; | |
| [key: string]: unknown; |
Copilot
AI
Apr 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring mentions “automatic build-time instrumentation”, but the current implementation only appends a (currently no-op) module and doesn’t use moduleOptions. Please adjust the wording to match the current behavior (or implement the described instrumentation in this PR).
| * Modifies the passed in Nitro configuration with automatic build-time instrumentation. | |
| * | |
| * @param config A Nitro configuration object, as usually exported in `nitro.config.ts` or `nitro.config.mjs`. | |
| * @returns The modified config to be exported | |
| * Modifies the passed in Nitro configuration by registering the Sentry Nitro module. | |
| * | |
| * @param config A Nitro configuration object, as usually exported in `nitro.config.ts` or `nitro.config.mjs`. | |
| * @returns The modified config to be exported with the Sentry Nitro module registered |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /* eslint-disable import/export */ | ||
| export * from './config'; | ||
| export * from '@sentry/node'; | ||
| export { init } from './sdk'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { NitroModule } from 'nitro/types'; | ||
|
|
||
| /** | ||
| * Creates a Nitro module to setup the Sentry SDK. | ||
| */ | ||
| export function createNitroModule(): NitroModule { | ||
| return { | ||
| name: 'sentry', | ||
| setup: _nitro => { | ||
| // TODO: Setup the Sentry SDK. | ||
| }, | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| import type { Integration } from '@sentry/core'; | ||||||
| import { applySdkMetadata } from '@sentry/core'; | ||||||
| import type { NodeClient, NodeOptions } from '@sentry/node'; | ||||||
| import { getDefaultIntegrations as getDefaultNodeIntegrations, init as nodeInit } from '@sentry/node'; | ||||||
|
|
||||||
| /** | ||||||
| * Initializes the Nitro SDK | ||||||
| */ | ||||||
| export function init(options: NodeOptions | undefined = {}): NodeClient | undefined { | ||||||
| const opts: NodeOptions = { | ||||||
| defaultIntegrations: getDefaultIntegrations(options), | ||||||
| ...options, | ||||||
| }; | ||||||
|
Comment on lines
+9
to
+13
|
||||||
|
|
||||||
| applySdkMetadata(opts, 'nitro'); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing
|
||||||
| applySdkMetadata(opts, 'nitro'); | |
| applySdkMetadata(opts, 'nitro', ['nitro', 'node']); |
Copilot
AI
Apr 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getDefaultIntegrations is declared to return Integration[] | undefined, but it always returns an array. Returning Integration[] avoids unnecessary undefined handling for callers and matches @sentry/node’s getDefaultIntegrations shape.
| export function getDefaultIntegrations(options: NodeOptions): Integration[] | undefined { | |
| export function getDefaultIntegrations(options: NodeOptions): Integration[] { |


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README states the minimum supported Nitro version is
3.0.0-alpha.1, butpeerDependenciesrequiresnitro >=3.0.260311-beta. Please align the README with the actual supported range (or adjust the peer dependency) to avoid confusing users.