Skip to content
Draft
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
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 @@ -230,6 +230,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 @@ -68,6 +68,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.
102 changes: 102 additions & 0 deletions packages/nitro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<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`.

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

TODO: UPDATE THIS

## Uploading Source Maps

To upload source maps...

<!-- TODO: -->

## 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.
71 changes: 71 additions & 0 deletions packages/nitro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "@sentry/nitro",
"private": true,
"version": "10.38.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"
]
}
},
"exports": {
"./package.json": "./package.json",
".": {
"types": "./build/types/index.d.ts",
"node": {
"import": "./build/esm/index.js"
}
}
},
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"nitro": ">=3.0.1-alpha.1"
},
"dependencies": {
"@sentry/core": "10.38.0",
"@sentry/node": "10.38.0"
},
"devDependencies": {
"nitro": "^3.0.1-alpha.1"
},
"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
};

/**
* 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
*/
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,
};

applySdkMetadata(opts, 'nitro');

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 {
return [...getDefaultNodeIntegrations(options)];
}
9 changes: 9 additions & 0 deletions packages/nitro/src/utils/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Nitro } from 'nitro/types';

/**
* Adds a Nitro plugin
*/
export function addPlugin(nitro: Nitro, plugin: string): void {
nitro.options.plugins = nitro.options.plugins || [];
nitro.options.plugins.push(plugin);
}
25 changes: 25 additions & 0 deletions packages/nitro/src/utils/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

export interface Resolver {
resolve(...path: string[]): string;
}

/**
* Creates a resolver for the given base path.
* @example
* ```ts
* const resolver = createResolver(import.meta.url);
* resolver.resolve('foo/bar.js');
* ```
*/
export function createResolver(base: string): Resolver {
let resolvedBase = base;
if (base.startsWith('file://')) {
resolvedBase = dirname(fileURLToPath(base));
}

return {
resolve: (...path) => resolve(resolvedBase, ...path),
};
}
11 changes: 11 additions & 0 deletions packages/nitro/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",

"include": ["src/**/*"],

"compilerOptions": {
// package-specific options
"module": "esnext",
"moduleResolution": "bundler"
}
}
10 changes: 10 additions & 0 deletions packages/nitro/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",

"include": ["test/**/*"],

"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["node"]
}
}
Loading
Loading