Skip to content
Closed
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/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ jobs:
- test-application: 'nestjs-microservices'
build-command: 'test:build-latest'
label: 'nestjs-microservices (latest)'
- test-application: 'nitro-3'
build-command: 'test:build-canary'
label: 'nitro-3 (canary)'

steps:
- name: Check out current commit
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
30 changes: 27 additions & 3 deletions packages/nitro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,37 @@ export default defineConfig({

### 3. Sentry Config Setup

TODO: UPDATE THIS
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

To upload source maps...
The `withSentryConfig` function automatically configures source map uploading when the `authToken`, `org`, and `project`
options are provided:

<!-- TODO: -->
```javascript
export default withSentryConfig(config, {
org: 'your-sentry-org',
project: 'your-sentry-project',
authToken: process.env.SENTRY_AUTH_TOKEN,
});
```

## Troubleshoot

Expand Down
68 changes: 23 additions & 45 deletions packages/nitro/test/sourceMaps.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { debug } from '@sentry/core';
import type { NitroConfig } from 'nitro/types';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { SentryNitroOptions } from '../src/config';
import { setupSentryNitroModule } from '../src/config';
import { getPluginOptions, setupSourceMaps } from '../src/sourceMaps';
import { configureSourcemapSettings, getPluginOptions, setupSourceMaps } from '../src/sourceMaps';

vi.mock('../src/instruments/instrumentServer', () => ({
instrumentServer: vi.fn(),
Expand Down Expand Up @@ -131,102 +132,71 @@
});
});

describe('setupSentryNitroModule', () => {
describe('configureSourcemapSettings', () => {
it('enables sourcemap generation on the config', () => {
const config: NitroConfig = {};
setupSentryNitroModule(config);
configureSourcemapSettings(config);

expect(config.sourcemap).toBe(true);
});

it('forces sourcemap to true even when user set it to false', () => {
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const debugSpy = vi.spyOn(debug, 'warn').mockImplementation(() => {});
const config: NitroConfig = { sourcemap: false };
setupSentryNitroModule(config);
configureSourcemapSettings(config);

expect(config.sourcemap).toBe(true);
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('overriding this to `true`'));
consoleSpy.mockRestore();
expect(debugSpy).toHaveBeenCalledWith(expect.stringContaining('overriding this to `true`'));
debugSpy.mockRestore();
});

it('keeps sourcemap true when user already set it', () => {
const config: NitroConfig = { sourcemap: true };
setupSentryNitroModule(config);
configureSourcemapSettings(config);

expect(config.sourcemap).toBe(true);
});

it('disables experimental sourcemapMinify', () => {
const config: NitroConfig = {};
setupSentryNitroModule(config);
configureSourcemapSettings(config);

expect(config.experimental?.sourcemapMinify).toBe(false);
});

it('sets sourcemapExcludeSources to false in rollupConfig', () => {
const config: NitroConfig = {};
setupSentryNitroModule(config);

expect(config.rollupConfig?.output?.sourcemapExcludeSources).toBe(false);
});

it('preserves existing experimental config', () => {
const config: NitroConfig = {
experimental: {
sourcemapMinify: undefined,
},
};
setupSentryNitroModule(config);
configureSourcemapSettings(config);

expect(config.experimental?.sourcemapMinify).toBe(false);
});

it('preserves existing rollupConfig', () => {
const config: NitroConfig = {
rollupConfig: {
output: {
format: 'esm' as const,
},
},
};
setupSentryNitroModule(config);

expect(config.rollupConfig?.output?.format).toBe('esm');
expect(config.rollupConfig?.output?.sourcemapExcludeSources).toBe(false);
});

it('skips sourcemap config when sourcemaps.disable is true', () => {
const config: NitroConfig = { sourcemap: false };
setupSentryNitroModule(config, { sourcemaps: { disable: true } });
configureSourcemapSettings(config, { sourcemaps: { disable: true } });

// Should NOT override the user's sourcemap: false
expect(config.sourcemap).toBe(false);
expect(config.rollupConfig).toBeUndefined();
});

it('skips sourcemap config when disable is true', () => {
const config: NitroConfig = { sourcemap: false };
setupSentryNitroModule(config, { disable: true });
configureSourcemapSettings(config, { disable: true });

// Should NOT override the user's sourcemap: false
expect(config.sourcemap).toBe(false);
expect(config.rollupConfig).toBeUndefined();
});

it('still adds module when sourcemaps are disabled', () => {
const config: NitroConfig = {};
setupSentryNitroModule(config, { sourcemaps: { disable: true } });

expect(config.modules).toBeDefined();
expect(config.modules?.length).toBe(1);
});
});

describe('setupSentryNitroModule', () => {
it('enables tracing', () => {
const config: NitroConfig = {};
setupSentryNitroModule(config);

// @ts-expect-error -- Nitro tracing config is not out yet
expect(config.tracing).toBe(true);

Check failure on line 199 in packages/nitro/test/sourceMaps.test.ts

View workflow job for this annotation

GitHub Actions / Node (20) Unit Tests

test/sourceMaps.test.ts > setupSentryNitroModule > enables tracing

AssertionError: expected undefined to be true // Object.is equality - Expected: true + Received: undefined ❯ test/sourceMaps.test.ts:199:28

Check failure on line 199 in packages/nitro/test/sourceMaps.test.ts

View workflow job for this annotation

GitHub Actions / Node (22) Unit Tests

test/sourceMaps.test.ts > setupSentryNitroModule > enables tracing

AssertionError: expected undefined to be true // Object.is equality - Expected: true + Received: undefined ❯ test/sourceMaps.test.ts:199:28

Check failure on line 199 in packages/nitro/test/sourceMaps.test.ts

View workflow job for this annotation

GitHub Actions / Node (18) Unit Tests

test/sourceMaps.test.ts > setupSentryNitroModule > enables tracing

AssertionError: expected undefined to be true // Object.is equality - Expected: true + Received: undefined ❯ test/sourceMaps.test.ts:199:28

Check failure on line 199 in packages/nitro/test/sourceMaps.test.ts

View workflow job for this annotation

GitHub Actions / Node (24) Unit Tests

test/sourceMaps.test.ts > setupSentryNitroModule > enables tracing

AssertionError: expected undefined to be true // Object.is equality - Expected: true + Received: undefined ❯ test/sourceMaps.test.ts:199:28
});

it('adds the sentry module', () => {
Expand All @@ -236,6 +206,14 @@
expect(config.modules).toBeDefined();
expect(config.modules?.length).toBe(1);
});

it('still adds module when sourcemaps are disabled', () => {
const config: NitroConfig = {};
setupSentryNitroModule(config, { sourcemaps: { disable: true } });

expect(config.modules).toBeDefined();
expect(config.modules?.length).toBe(1);
});
});

describe('setupSourceMaps', () => {
Expand Down
Loading
Loading