From 69dc0df6710318e781023010ca3f06ba5976493f Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Thu, 4 Jul 2024 14:16:03 +0200 Subject: [PATCH 1/3] feat(nuxt): Add sentry config with plugin template --- packages/nuxt/README.md | 22 +- packages/nuxt/package.json | 6 +- packages/nuxt/rollup.npm.config.mjs | 2 +- packages/nuxt/src/common/snippets.ts | 47 - packages/nuxt/src/common/utils.ts | 28 + packages/nuxt/src/index.server.ts | 2 +- packages/nuxt/src/index.types.ts | 18 +- packages/nuxt/src/module.ts | 49 +- packages/nuxt/src/server/index.ts | 3 + packages/nuxt/src/server/sdk.ts | 19 + packages/nuxt/test/common/snippets.test.ts | 98 -- yarn.lock | 1657 +++++++++----------- 12 files changed, 886 insertions(+), 1065 deletions(-) delete mode 100644 packages/nuxt/src/common/snippets.ts create mode 100644 packages/nuxt/src/common/utils.ts create mode 100644 packages/nuxt/src/server/index.ts create mode 100644 packages/nuxt/src/server/sdk.ts delete mode 100644 packages/nuxt/test/common/snippets.test.ts diff --git a/packages/nuxt/README.md b/packages/nuxt/README.md index e33201b21518..db277a337f68 100644 --- a/packages/nuxt/README.md +++ b/packages/nuxt/README.md @@ -62,7 +62,9 @@ export default defineNuxtConfig({ }); ``` -2. Add a `sentry.client.config.(js|ts)` file to the root of your project: +### 3. Client-side setup + +Add a `sentry.client.config.(js|ts)` file to the root of your project: ```javascript import * as Sentry from '@sentry/nuxt'; @@ -70,17 +72,25 @@ import * as Sentry from '@sentry/nuxt'; if (!import.meta.env.SSR) { Sentry.init({ dsn: env.DSN, - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0, }); } ``` -### 3. Server-side Setup +### 4. Server-side setup + +Add a `sentry.server.config.(js|ts)` file to the root of your project: + +```javascript +import * as Sentry from '@sentry/nuxt'; -todo: add server-side setup +if (import.meta.env.SSR) { + Sentry.init({ + dsn: env.DSN, + }); +} +``` -### 4. Vite Setup +### 5. Vite Setup todo: add vite setup diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index 141335277238..88242c2756de 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -42,7 +42,7 @@ "nuxt": "3.x" }, "dependencies": { - "@nuxt/kit": "^3.12.2", + "@nuxt/kit": "^3.12.3", "@sentry/browser": "8.14.0", "@sentry/core": "8.14.0", "@sentry/node": "8.14.0", @@ -53,8 +53,8 @@ "@sentry/vue": "8.14.0" }, "devDependencies": { - "@nuxt/module-builder": "0.8.0", - "nuxt": "^3.12.2" + "@nuxt/module-builder": "0.8.1", + "nuxt": "^3.12.3" }, "scripts": { "build": "run-p build:transpile build:types build:nuxt-module", diff --git a/packages/nuxt/rollup.npm.config.mjs b/packages/nuxt/rollup.npm.config.mjs index e800fdbba474..a672e9e43eb3 100644 --- a/packages/nuxt/rollup.npm.config.mjs +++ b/packages/nuxt/rollup.npm.config.mjs @@ -2,6 +2,6 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu export default makeNPMConfigVariants( makeBaseNPMConfig({ - entrypoints: ['src/index.client.ts', 'src/client/index.ts'], + entrypoints: ['src/index.server.ts', 'src/index.client.ts', 'src/client/index.ts', 'src/server/index.ts'], }), ); diff --git a/packages/nuxt/src/common/snippets.ts b/packages/nuxt/src/common/snippets.ts deleted file mode 100644 index 5b8a3f1f3ea1..000000000000 --- a/packages/nuxt/src/common/snippets.ts +++ /dev/null @@ -1,47 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; - -/** Returns an import snippet */ -export function buildSdkInitFileImportSnippet(filePath: string): string { - const posixPath = filePath.split(path.sep).join(path.posix.sep); - - // normalize to forward slashed for Windows-based systems - const normalizedPath = posixPath.replace(/\\/g, '/'); - - return `import '${normalizedPath}';`; -} - -/** - * Script tag inside `nuxt-root.vue` (root component we get from NuxtApp) - */ -export const SCRIPT_TAG = '