Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ targets:
- name: npm
id: '@sentry/react-router'
includeNames: /^sentry-react-router-\d.*\.tgz$/
- name: npm
id: '@sentry/nitro'
includeNames: /^sentry-nitro-\d.*\.tgz$/

## 7. Other Packages
## 7.1
Expand Down Expand Up @@ -256,3 +259,9 @@ targets:
packageUrl: 'https://www.npmjs.com/package/@sentry/elysia'
mainDocsUrl: 'https://docs.sentry.io/platforms/javascript/guides/elysia/'
onlyIfPresent: /^sentry-elysia-\d.*\.tgz$/
'npm:@sentry/nitro':
name: 'Sentry Nitro SDK'
sdkName: 'sentry.javascript.nitro'
packageUrl: 'https://www.npmjs.com/package/@sentry/nitro'
mainDocsUrl: 'https://docs.sentry.io/platforms/javascript/guides/nitro/'
onlyIfPresent: /^sentry-nitro-\d.*\.tgz$/
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ body:
- '@sentry/google-cloud-serverless'
- '@sentry/nestjs'
- '@sentry/nextjs'
- '@sentry/nitro'
- '@sentry/nuxt'
- '@sentry/react'
- '@sentry/react-router'
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/issue-package-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ jobs:
"@sentry.nestjs": {
"label": "Nest.js"
},
"@sentry.nitro": {
"label": "Nitro"
},
"@sentry.nextjs": {
"label": "Next.js"
},
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ package. Please refer to the README and instructions of those SDKs for more deta
- [`@sentry/gatsby`](https://github.com/getsentry/sentry-javascript/tree/master/packages/gatsby): SDK for Gatsby
- [`@sentry/nestjs`](https://github.com/getsentry/sentry-javascript/tree/master/packages/nestjs): SDK for NestJS
- [`@sentry/nextjs`](https://github.com/getsentry/sentry-javascript/tree/master/packages/nextjs): SDK for Next.js
- [`@sentry/nitro`](https://github.com/getsentry/sentry-javascript/tree/master/packages/nitro): SDK for Nitro
- [`@sentry/remix`](https://github.com/getsentry/sentry-javascript/tree/master/packages/remix): SDK for Remix
- [`@sentry/tanstackstart-react`](https://github.com/getsentry/sentry-javascript/tree/master/packages/tanstackstart-react): SDK for TanStack Start React
- [`@sentry/aws-serverless`](https://github.com/getsentry/sentry-javascript/tree/master/packages/aws-serverless): SDK
Expand Down
6 changes: 6 additions & 0 deletions dev-packages/e2e-tests/verdaccio-config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ packages:
unpublish: $all
# proxy: npmjs # Don't proxy for E2E tests!

'@sentry/nitro':
access: $all
publish: $all
unpublish: $all
# proxy: npmjs # Don't proxy for E2E tests!

'@sentry-internal/*':
access: $all
publish: $all
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"packages/integration-shims",
"packages/nestjs",
"packages/nextjs",
"packages/nitro",
"packages/node",
"packages/node-core",
"packages/node-native",
Expand Down
7 changes: 7 additions & 0 deletions packages/nitro/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
env: {
browser: true,
node: true,
},
extends: ['../../.eslintrc.js'],
};
21 changes: 21 additions & 0 deletions packages/nitro/LICENSE
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.
126 changes: 126 additions & 0 deletions packages/nitro/README.md
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

[![npm version](https://img.shields.io/npm/v/@sentry/nitro.svg)](https://www.npmjs.com/package/@sentry/nitro)
[![npm dm](https://img.shields.io/npm/dm/@sentry/nitro.svg)](https://www.npmjs.com/package/@sentry/nitro)
[![npm dt](https://img.shields.io/npm/dt/@sentry/nitro.svg)](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`.
Copy link

Copilot AI Apr 15, 2026

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, but peerDependencies requires nitro >=3.0.260311-beta. Please align the README with the actual supported range (or adjust the peer dependency) to avoid confusing users.

Suggested change
The minimum supported version of Nitro is `3.0.0-alpha.1`.
The minimum supported version of Nitro is `3.0.260311-beta`.

Copilot uses AI. Check for mistakes.

## 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
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

This section claims withSentryConfig automatically configures source map uploading when authToken/org/project are provided, but that functionality (and option typings) isn’t implemented in this PR. As-is, the docs are misleading; consider removing this section for now or clearly marking it as upcoming work in the stacked PRs.

Suggested change
## 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,
});
```

Copilot uses AI. Check for mistakes.
## Troubleshoot

If you encounter any issues with error tracking or integrations, refer to the official [Sentry Nitro SDK documentation](https://docs.sentry.io/platforms/javascript/guides/nitro/). If the documentation does not provide the necessary information, consider opening an issue on GitHub.
70 changes: 70 additions & 0 deletions packages/nitro/package.json
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"
]
}
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dead typesVersions entry references non-existent plugins path

Low Severity

The typesVersions field maps "plugins" to build/types/plugins.d.ts, but no src/plugins.ts source file exists in the package, and there's no corresponding ./plugins entry in the exports field. This is a copy-paste artifact from another package template. It advertises a non-existent subpath to TypeScript, which could confuse consumers trying to import @sentry/nitro/plugins.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ff579f3. Configure here.

Comment on lines +18 to +24
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

typesVersions adds a plugins subpath mapped to build/types/plugins.d.ts, but this PR doesn’t add any source that would emit that declaration file. This leaves a dangling mapping and will break TS resolution for @sentry/nitro/plugins.

Suggested change
"typesVersions": {
"*": {
"plugins": [
"build/types/plugins.d.ts"
]
}
},

Copilot uses AI. Check for mistakes.
"exports": {
"./package.json": "./package.json",
".": {
"types": "./build/types/index.d.ts",
"node": {
Comment on lines +25 to +29
Copy link

Copilot AI Apr 15, 2026

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.

Copilot uses AI. Check for mistakes.
"import": "./build/esm/index.js"
}
}
},
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"nitro": ">=3.0.260311-beta"
},
"dependencies": {
"@sentry/core": "10.48.0",
"@sentry/node": "10.48.0"
},
"devDependencies": {
"nitro": "^3.0.260311-beta"
},
"scripts": {
"build": "run-p build:transpile build:types",
"build:dev": "yarn build",
"build:transpile": "rollup -c rollup.npm.config.mjs",
"build:types": "run-s build:types:core",
"build:types:core": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:transpile:watch build:types:watch",
"build:dev:watch": "yarn build:watch",
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:tarball": "npm pack",
"clean": "rimraf build coverage sentry-nitro-*.tgz",
"fix": "eslint . --format stylish --fix",
"lint": "eslint . --format stylish",
"lint:es-compatibility": "es-check es2022 ./build/esm/*.js --module",
"test": "vitest run",
"test:watch": "vitest --watch",
"yalc:publish": "yalc publish --push --sig"
},
"volta": {
"extends": "../../package.json"
},
"sideEffects": false
}
13 changes: 13 additions & 0 deletions packages/nitro/rollup.npm.config.mjs
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 },
),
];
8 changes: 8 additions & 0 deletions packages/nitro/src/common/debug-build.ts
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__;
32 changes: 32 additions & 0 deletions packages/nitro/src/config.ts
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
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

SentryNitroOptions is an empty object type, which means the README examples passing { org, project, authToken } will fail TS excess-property checks, and callers can’t actually configure anything yet. Consider defining the intended option shape (even if partial) or using a permissive placeholder type (e.g. Record<string, unknown>) until the real options land.

Suggested change
// TODO: Add options
org?: string;
project?: string;
authToken?: string;
[key: string]: unknown;

Copilot uses AI. Check for mistakes.
};

/**
* 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
Comment on lines +9 to +12
Copy link

Copilot AI Apr 15, 2026

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).

Suggested change
* 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

Copilot uses AI. Check for mistakes.
*/
export function withSentryConfig(config: NitroConfig, moduleOptions?: SentryNitroOptions): NitroConfig {
setupSentryNitroModule(config, moduleOptions);

return config;
}

/**
* Sets up the Sentry Nitro module, useful for meta framework integrations.
*/
export function setupSentryNitroModule(
config: NitroConfig,
_moduleOptions?: SentryNitroOptions,
_serverConfigFile?: string,
): NitroConfig {
config.modules = config.modules || [];
config.modules.push(createNitroModule());

return config;
}
4 changes: 4 additions & 0 deletions packages/nitro/src/index.ts
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';
13 changes: 13 additions & 0 deletions packages/nitro/src/module.ts
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.
},
};
}
29 changes: 29 additions & 0 deletions packages/nitro/src/sdk.ts
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
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

options is typed as NodeOptions | undefined, but getDefaultIntegrations currently requires NodeOptions, so this call won’t type-check under strict TS. Either change init to take options: NodeOptions = {} or pass options ?? {} and update getDefaultIntegrations accordingly (and keep the types aligned with @sentry/node).

Copilot uses AI. Check for mistakes.

applySdkMetadata(opts, 'nitro');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing 'node' in SDK metadata packages list

Medium Severity

The applySdkMetadata call passes only 'nitro', which means names defaults to ['nitro']. Every other Node-wrapping SDK in the monorepo (nestjs, nuxt, sveltekit, solidstart, astro, aws-serverless, google-cloud-serverless) passes the names array explicitly to include 'node', e.g. applySdkMetadata(opts, 'nitro', ['nitro', 'node']). Without this, the SDK telemetry metadata won't list @sentry/node as a package dependency, making the Nitro SDK inconsistent with all peer SDKs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ff579f3. Configure here.

Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

For wrapper SDKs around @sentry/node, we typically include both the wrapper and node package names in applySdkMetadata so events show the full package chain (e.g. Remix uses ['remix', 'node']). Consider using applySdkMetadata(opts, 'nitro', ['nitro', 'node']) for consistency.

Suggested change
applySdkMetadata(opts, 'nitro');
applySdkMetadata(opts, 'nitro', ['nitro', 'node']);

Copilot uses AI. Check for mistakes.

const client = nodeInit(opts);

return client;
}

/**
* Get the default integrations for the Nitro SDK.
*
* @returns The default integrations for the Nitro SDK.
*/
export function getDefaultIntegrations(options: NodeOptions): Integration[] | undefined {
Copy link

Copilot AI Apr 15, 2026

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.

Suggested change
export function getDefaultIntegrations(options: NodeOptions): Integration[] | undefined {
export function getDefaultIntegrations(options: NodeOptions): Integration[] {

Copilot uses AI. Check for mistakes.
return [...getDefaultNodeIntegrations(options)];
}
Loading
Loading