Skip to content

Commit 7953124

Browse files
committed
feat: init nitro SDK
1 parent df43cac commit 7953124

File tree

18 files changed

+1986
-46
lines changed

18 files changed

+1986
-46
lines changed

dev-packages/e2e-tests/verdaccio-config/config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ packages:
230230
unpublish: $all
231231
# proxy: npmjs # Don't proxy for E2E tests!
232232

233+
'@sentry/nitro':
234+
access: $all
235+
publish: $all
236+
unpublish: $all
237+
# proxy: npmjs # Don't proxy for E2E tests!
238+
233239
'@sentry-internal/*':
234240
access: $all
235241
publish: $all

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"packages/integration-shims",
6969
"packages/nestjs",
7070
"packages/nextjs",
71+
"packages/nitro",
7172
"packages/node",
7273
"packages/node-core",
7374
"packages/node-native",

packages/nitro/.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
node: true,
5+
},
6+
extends: ['../../.eslintrc.js'],
7+
};

packages/nitro/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Functional Software, Inc. dba Sentry
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/nitro/README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<p align="center">
2+
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
3+
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
4+
</a>
5+
</p>
6+
7+
# Official Sentry SDK for Nitro
8+
9+
[![npm version](https://img.shields.io/npm/v/@sentry/nitro.svg)](https://www.npmjs.com/package/@sentry/nitro)
10+
[![npm dm](https://img.shields.io/npm/dm/@sentry/nitro.svg)](https://www.npmjs.com/package/@sentry/nitro)
11+
[![npm dt](https://img.shields.io/npm/dt/@sentry/nitro.svg)](https://www.npmjs.com/package/@sentry/nitro)
12+
13+
## Links
14+
15+
- [Official Nitro SDK Docs](https://docs.sentry.io/platforms/javascript/guides/nitro/)
16+
17+
## Compatibility
18+
19+
The minimum supported version of Nitro is `3.0.0-alpha.1`.
20+
21+
## General
22+
23+
This package is a wrapper around `@sentry/node` with added instrumentation for Nitro's features like:
24+
25+
- HTTP handlers and error capturing.
26+
- [Middleware instrumentation](https://nitro.build/guide/routing#middleware).
27+
<!-- - [Database instrumentation](https://nitro.build/guide/database). -->
28+
<!-- - [KV Storage](https://nitro.build/guide/storage) and [Cache](https://nitro.build/guide/cache) instrumentation. -->
29+
30+
## Manual Setup
31+
32+
### 1. Prerequisites & Installation
33+
34+
1. Install the Sentry Nitro SDK:
35+
36+
```bash
37+
# Using npm
38+
npm install @sentry/nitro
39+
40+
# Using yarn
41+
yarn add @sentry/nitro
42+
43+
# Using pnpm
44+
pnpm add @sentry/nitro
45+
```
46+
47+
### 2. Nitro Config Setup
48+
49+
1. Import `withSentryConfig` from `@sentry/nitro` and call it with your Nitro config.
50+
51+
#### In `nitro.config.ts`
52+
53+
If you are using a dedicated `nitro.config.ts` file, you can import `withSentryConfig` from `@sentry/nitro` and call it with your Nitro config.
54+
55+
```javascript
56+
import { defineNitroConfig } from 'nitro/config';
57+
import { withSentryConfig } from '@sentry/nitro';
58+
59+
const config = defineNitroConfig({
60+
// ...
61+
});
62+
63+
export default withSentryConfig(config, {
64+
// Sentry Build Options
65+
});
66+
```
67+
68+
#### In `vite.config.ts`
69+
70+
If you are using nitro as a Vite plugin, you can import `withSentryConfig` from `@sentry/nitro` and call it with your Nitro config.
71+
72+
```ts
73+
import { defineConfig } from 'vite';
74+
import { nitro } from 'nitro/vite';
75+
import { withSentryConfig } from '@sentry/nitro';
76+
77+
export default defineConfig({
78+
plugins: [nitro()],
79+
nitro: withSentryConfig(
80+
{
81+
// Nitro options
82+
},
83+
{
84+
// Sentry Build Options
85+
},
86+
),
87+
});
88+
```
89+
90+
### 3. Sentry Config Setup
91+
92+
TODO: UPDATE THIS
93+
94+
## Uploading Source Maps
95+
96+
To upload source maps...
97+
98+
<!-- TODO: -->
99+
100+
## Troubleshoot
101+
102+
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.

packages/nitro/package.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "@sentry/nitro",
3+
"version": "10.32.1",
4+
"description": "Official Sentry SDK for Nitro",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/nitro",
7+
"author": "Sentry",
8+
"license": "MIT",
9+
"engines": {
10+
"node": ">=18.19.1"
11+
},
12+
"files": [
13+
"/build"
14+
],
15+
"main": "build/esm/index.js",
16+
"module": "build/esm/index.js",
17+
"types": "build/types/index.d.ts",
18+
"typesVersions": {
19+
"*": {
20+
"plugins": [
21+
"build/types/plugins.d.ts"
22+
]
23+
}
24+
},
25+
"exports": {
26+
"./package.json": "./package.json",
27+
".": {
28+
"types": "./build/types/index.d.ts",
29+
"node": {
30+
"import": "./build/esm/index.js"
31+
}
32+
}
33+
},
34+
"publishConfig": {
35+
"access": "public"
36+
},
37+
"peerDependencies": {
38+
"nitro": ">=3.0.1-alpha.1"
39+
},
40+
"dependencies": {
41+
"@sentry/core": "10.32.1",
42+
"@sentry/node": "10.32.1"
43+
},
44+
"devDependencies": {
45+
"nitro": "^3.0.1-alpha.1"
46+
},
47+
"scripts": {
48+
"build": "run-p build:transpile build:types",
49+
"build:dev": "yarn build",
50+
"build:transpile": "rollup -c rollup.npm.config.mjs",
51+
"build:types": "run-s build:types:core",
52+
"build:types:core": "tsc -p tsconfig.types.json",
53+
"build:watch": "run-p build:transpile:watch build:types:watch",
54+
"build:dev:watch": "yarn build:watch",
55+
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
56+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
57+
"build:tarball": "npm pack",
58+
"clean": "rimraf build coverage sentry-nitro-*.tgz",
59+
"fix": "eslint . --format stylish --fix",
60+
"lint": "eslint . --format stylish",
61+
"lint:es-compatibility": "es-check es2022 ./build/esm/*.js --module",
62+
"test": "vitest run",
63+
"test:watch": "vitest --watch",
64+
"yalc:publish": "yalc publish --push --sig"
65+
},
66+
"volta": {
67+
"extends": "../../package.json"
68+
},
69+
"sideEffects": false
70+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';
2+
3+
export default [
4+
...makeNPMConfigVariants(
5+
makeBaseNPMConfig({
6+
entrypoints: ['src/index.ts'],
7+
packageSpecificConfig: {
8+
external: [/^nitro/],
9+
},
10+
}),
11+
{ emitCjs: false },
12+
),
13+
];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare const __DEBUG_BUILD__: boolean;
2+
3+
/**
4+
* 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.
5+
*
6+
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
7+
*/
8+
export const DEBUG_BUILD = __DEBUG_BUILD__;

packages/nitro/src/config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { NitroConfig } from 'nitro/types';
2+
import { createNitroModule } from './module';
3+
4+
type SentryNitroOptions = {
5+
// TODO: Add options
6+
};
7+
8+
/**
9+
* Modifies the passed in Nitro configuration with automatic build-time instrumentation.
10+
*
11+
* @param config A Nitro configuration object, as usually exported in `nitro.config.ts` or `nitro.config.mjs`.
12+
* @returns The modified config to be exported
13+
*/
14+
export function withSentryConfig(config: NitroConfig, moduleOptions?: SentryNitroOptions): NitroConfig {
15+
setupSentryNitroModule(config, moduleOptions);
16+
17+
return config;
18+
}
19+
20+
/**
21+
* Sets up the Sentry Nitro module, useful for meta framework integrations.
22+
*/
23+
export function setupSentryNitroModule(
24+
config: NitroConfig,
25+
moduleOptions?: SentryNitroOptions,
26+
serverConfigFile?: string,
27+
): NitroConfig {
28+
config.modules = config.modules || [];
29+
config.modules.push(createNitroModule());
30+
31+
return config;
32+
}

packages/nitro/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* eslint-disable import/export */
2+
export * from './config';
3+
export * from '@sentry/node';
4+
export { init } from './sdk';

0 commit comments

Comments
 (0)