diff --git a/docs/platforms/javascript/common/configuration/async-context.mdx b/docs/platforms/javascript/common/configuration/async-context.mdx index 07a5fa12d9f2f..5b9a114fe12bb 100644 --- a/docs/platforms/javascript/common/configuration/async-context.mdx +++ b/docs/platforms/javascript/common/configuration/async-context.mdx @@ -17,6 +17,7 @@ supported: By default, the Sentry SDK will automatically isolate each request's scope and breadcrumbs. This means that any breadcrumbs or tags added will be isolated to the request. This is useful if you are finding that breadcrumbs and scope are leaking across requests. Take the following example: + ```js const Sentry = require("@sentry/node"); @@ -34,11 +35,32 @@ app.get("/my-route-2", function () { // do something }); ``` + + +```js +const Sentry = require("@sentry/nestjs"); + +app.get("/my-route", function () { + Sentry.addBreadcrumb({ + message: "This breadcrumb should only be attached to this request", + }); + // do something +}); + + app.get("/my-route-2", function () { + Sentry.addBreadcrumb({ + message: "This breadcrumb should only be attached to this request", + }); + // do something +}); +``` + Each request will have its own breadcrumbs, and they will not be shared between requests. If you want to manually isolate some code, such as for a background job, you can use the `withIsolationScope` method. This will ensure that any breadcrumbs or tags added will be isolated inside of the provided callback: + ```js const Sentry = require("@sentry/node"); @@ -49,5 +71,18 @@ async function backgroundJob() { }); } ``` + + +```js +const Sentry = require("@sentry/nestjs"); + +async function backgroundJob() { + return await Sentry.withIsolationScope(async () => { + // Everything inside of this will be isolated + await doSomething(); +}); +} +``` + Under the hood, the SDK uses Node's [AsyncLocalStorage API](https://nodejs.org/api/async_context.html#class-asynclocalstorage) to perform the isolation. diff --git a/docs/platforms/javascript/common/configuration/integrations/trpc.mdx b/docs/platforms/javascript/common/configuration/integrations/trpc.mdx index 2947726f52273..24c296393c5e8 100644 --- a/docs/platforms/javascript/common/configuration/integrations/trpc.mdx +++ b/docs/platforms/javascript/common/configuration/integrations/trpc.mdx @@ -33,6 +33,7 @@ The Sentry tRPC middleware creates spans for your and improves error capturing f The `trpcMiddleware` is not a traditional SDK integration in the sense that your are **not** supposed to add it to the `integrations` option. Instead, add it as a middleware to your tRPC router. + ```javascript import * as Sentry from "@sentry/node"; import { initTRPC } from "@trpc/server"; @@ -47,6 +48,23 @@ const sentryMiddleware = t.middleware( const sentrifiedProcedure = t.procedure.use(sentryMiddleware); ``` + + +```javascript +import * as Sentry from "@sentry/nestjs"; +import { initTRPC } from "@trpc/server"; + +const t = initTRPC.context().create(); + +const sentryMiddleware = t.middleware( + Sentry.trpcMiddleware({ + attachRpcInput: true, + }) +); + +const sentrifiedProcedure = t.procedure.use(sentryMiddleware); +``` + ## Options diff --git a/docs/platforms/javascript/common/configuration/tree-shaking.mdx b/docs/platforms/javascript/common/configuration/tree-shaking.mdx index 8fa76c4cce4f5..cd8e9946d1814 100644 --- a/docs/platforms/javascript/common/configuration/tree-shaking.mdx +++ b/docs/platforms/javascript/common/configuration/tree-shaking.mdx @@ -304,6 +304,7 @@ SDK functionality. You can also add [additional](../integrations) or [custom](.. integrations to your SDK configuration. If you don't want to include default integrations in your config, you can use `Sentry.initWithoutDefaultIntegrations()` and pass the integrations you want manually: + ```javascript const Sentry = require("@sentry/node"); @@ -318,11 +319,29 @@ Sentry.initWithoutDefaultIntegrations({ ], }); ``` + + +```javascript +const Sentry = require("@sentry/nestjs"); + +// This will not add _any_ integrations by default! +Sentry.initWithoutDefaultIntegrations({ + dsn: "___PUBLIC_DSN___", + integrations: [ + Sentry.httpIntegration(), + Sentry.consoleIntegration(), + Sentry.dedupeIntegration(), + Sentry.inboundFiltersIntegration(), + ], +}); +``` + ## Setting up Sentry without Performance Integrations If you want to use Sentry only for error monitoring, and do not care about any performance monitoring features, you can use the following initialization method to ensure that any performance-specific integrations are not included in your bundle and can be tree-shaken away by a bundler: + ```javascript const Sentry = require("@sentry/node"); @@ -336,5 +355,21 @@ Sentry.initWithoutDefaultIntegrations({ ], }); ``` + + +```javascript +const Sentry = require("@sentry/nestjs"); + +// This will not add _any_ integrations by default! +Sentry.initWithoutDefaultIntegrations({ + dsn: "___PUBLIC_DSN___", + integrations: [ + // Adds all default integrations + // except the ones that are only relevant for performance + ...Sentry.getDefaultIntegrationsWithoutPerformance(), + ], +}); +``` + diff --git a/docs/platforms/javascript/common/install/esm-without-import.mdx b/docs/platforms/javascript/common/install/esm-without-import.mdx index 10ca4f7633432..870f8f599322b 100644 --- a/docs/platforms/javascript/common/install/esm-without-import.mdx +++ b/docs/platforms/javascript/common/install/esm-without-import.mdx @@ -30,6 +30,8 @@ You need to create a file named `instrument.mjs` that imports and initializes Se + + ```javascript {tabTitle:ESM} {filename: instrument.mjs} import * as Sentry from "@sentry/node"; @@ -42,6 +44,21 @@ Sentry.init({ tracesSampleRate: 1.0, }); ``` + + +```javascript {tabTitle:ESM} {filename: instrument.mjs} +import * as Sentry from "@sentry/nestjs"; + +// Ensure to call this before importing any other modules! +Sentry.init({ + dsn: "___PUBLIC_DSN___", + + // Add Tracing by setting tracesSampleRate + // We recommend adjusting this value in production + tracesSampleRate: 1.0, +}); +``` + You need to import the `instrument.mjs` file before importing any other modules in your application. This is necessary to ensure that Sentry can automatically instrument all modules in your application: diff --git a/docs/platforms/javascript/common/install/esm.mdx b/docs/platforms/javascript/common/install/esm.mdx index 3d6d37a9c14fd..75667c0ee92a5 100644 --- a/docs/platforms/javascript/common/install/esm.mdx +++ b/docs/platforms/javascript/common/install/esm.mdx @@ -21,6 +21,7 @@ When running your application in ESM mode, you can't use `require()` to load mod You need to create a file named `instrument.mjs` that imports and initializes Sentry: + ```javascript {tabTitle:ESM} {filename: instrument.mjs} import * as Sentry from "@sentry/node"; @@ -33,6 +34,21 @@ Sentry.init({ tracesSampleRate: 1.0, }); ``` + + +```javascript {tabTitle:ESM} {filename: instrument.mjs} +import * as Sentry from "@sentry/nestjs"; + +// Ensure to call this before importing any other modules! +Sentry.init({ + dsn: "___PUBLIC_DSN___", + + // Add Tracing by setting tracesSampleRate + // We recommend adjusting this value in production + tracesSampleRate: 1.0, +}); +``` + Adjust the Node.js call for your application to use the [--import](https://nodejs.org/api/cli.html#--importmodule) parameter and point it at `instrument.js`, which contains your `Sentry.init()` code: diff --git a/docs/platforms/javascript/common/install/late-initializtion.mdx b/docs/platforms/javascript/common/install/late-initializtion.mdx index 0d7e35ab1e2a5..5696ef49d76c3 100644 --- a/docs/platforms/javascript/common/install/late-initializtion.mdx +++ b/docs/platforms/javascript/common/install/late-initializtion.mdx @@ -39,6 +39,7 @@ node --require @sentry/node/preload app.js Then, in your application you can call `Sentry.init()` at a later point: + ```javascript {filename: main.js} const startApp = require("./app"); const fetchDsn = require("./utils/fetchDsn"); @@ -58,6 +59,28 @@ Sentry.init({ // From now on, Sentry is initialized, // but the app is still auto-instrumented ``` + + +```javascript {filename: main.js} +const startApp = require("./app"); +const fetchDsn = require("./utils/fetchDsn"); +const Sentry = require("@sentry/nestjs"); + +startApp(); + +const dsn = fetchDsn(); +Sentry.init({ + dsn, + + // Add Tracing by setting tracesSampleRate + // We recommend adjusting this value in production + tracesSampleRate: 1.0, +}); + + // From now on, Sentry is initialized, + // but the app is still auto-instrumented + ``` + ## Late Initialization with ESM @@ -70,6 +93,7 @@ node --import @sentry/node/preload app.js Then, in your application you can call `Sentry.init()` at a later point: + ```javascript {filename: main.js} import startApp from "./app"; import fetchDsn from "./utils/fetchDsn"; @@ -89,6 +113,28 @@ Sentry.init({ // From now on, Sentry is initialized, // but the app is still auto-instrumented ``` + + +```javascript {filename: main.js} +import startApp from "./app"; +import fetchDsn from "./utils/fetchDsn"; +import * as Sentry from "@sentry/nestjs"; + +startApp(); + +const dsn = fetchDsn(); +Sentry.init({ + dsn, + + // Add Tracing by setting tracesSampleRate + // We recommend adjusting this value in production + tracesSampleRate: 1.0, +}); + +// From now on, Sentry is initialized, +// but the app is still auto-instrumented +``` + ## What does Preloading mean? diff --git a/docs/platforms/javascript/common/tracing/instrumentation/opentelemetry.mdx b/docs/platforms/javascript/common/tracing/instrumentation/opentelemetry.mdx index 1d328f8abe831..ca77a60bef881 100644 --- a/docs/platforms/javascript/common/tracing/instrumentation/opentelemetry.mdx +++ b/docs/platforms/javascript/common/tracing/instrumentation/opentelemetry.mdx @@ -24,6 +24,7 @@ The Sentry SDK uses [OpenTelemetry](https://opentelemetry.io/) under the hood. T While the Sentry SDK includes some OpenTelemetry instrumentation out of the box, you may want to add additional instrumentation to your application. This can be done by registering the instrumentation through OpenTelemetry like this: + ```js const Sentry = require("@sentry/node"); const { @@ -40,6 +41,25 @@ Sentry.init({ // Afterwards, you can add additional instrumentation: Sentry.addOpenTelemetryInstrumentation(new GenericPoolInstrumentation()); ``` + + +```js +const Sentry = require("@sentry/nestjs"); +const { + GenericPoolInstrumentation, +} = require("@opentelemetry/instrumentation-generic-pool"); + +Sentry.init({ + dsn: "__DSN__", + + // The SentrySampler will use this to determine which traces to sample + tracesSampleRate: 1.0, +}); + +// Afterwards, you can add additional instrumentation: +Sentry.addOpenTelemetryInstrumentation(new GenericPoolInstrumentation()); +``` + Any instrumentation added like this will be automatically picked up by Sentry. diff --git a/platform-includes/capture-error/javascript.nestjs.mdx b/platform-includes/capture-error/javascript.nestjs.mdx new file mode 100644 index 0000000000000..50e5dd149665b --- /dev/null +++ b/platform-includes/capture-error/javascript.nestjs.mdx @@ -0,0 +1,11 @@ +You can pass an `Error` object to `captureException()` to have it captured as event. It's also possible to pass non-`Error` objects and strings, but be aware that the resulting events in Sentry may be missing a stack trace. + +```javascript +import * as Sentry from "@sentry/nestjs"; + +try { + aFunctionThatMightFail(); +} catch (e) { + Sentry.captureException(e); +} +``` diff --git a/platform-includes/configuration/capture-console/javascript.nestjs.mdx b/platform-includes/configuration/capture-console/javascript.nestjs.mdx new file mode 100644 index 0000000000000..c2cd2a6bc9c5a --- /dev/null +++ b/platform-includes/configuration/capture-console/javascript.nestjs.mdx @@ -0,0 +1,10 @@ + + +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.captureConsoleIntegration()], +}); +``` diff --git a/platform-includes/configuration/contextlines/javascript.nestjs.mdx b/platform-includes/configuration/contextlines/javascript.nestjs.mdx new file mode 100644 index 0000000000000..c2cd2a6bc9c5a --- /dev/null +++ b/platform-includes/configuration/contextlines/javascript.nestjs.mdx @@ -0,0 +1,10 @@ + + +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.captureConsoleIntegration()], +}); +``` diff --git a/platform-includes/configuration/debug/javascript.nestjs.mdx b/platform-includes/configuration/debug/javascript.nestjs.mdx new file mode 100644 index 0000000000000..c7570760fea28 --- /dev/null +++ b/platform-includes/configuration/debug/javascript.nestjs.mdx @@ -0,0 +1,10 @@ + + +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.debugIntegration()], +}); +``` diff --git a/platform-includes/configuration/dedupe/javascript.nestjs.mdx b/platform-includes/configuration/dedupe/javascript.nestjs.mdx new file mode 100644 index 0000000000000..f4ea13f927cb4 --- /dev/null +++ b/platform-includes/configuration/dedupe/javascript.nestjs.mdx @@ -0,0 +1,11 @@ + + +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.dedupeIntegration()], +}); +``` +ing diff --git a/platform-includes/configuration/enable-pluggable-integrations-lazy/javascript.nestjs.mdx b/platform-includes/configuration/enable-pluggable-integrations-lazy/javascript.nestjs.mdx new file mode 100644 index 0000000000000..0fed029859a47 --- /dev/null +++ b/platform-includes/configuration/enable-pluggable-integrations-lazy/javascript.nestjs.mdx @@ -0,0 +1,10 @@ + + +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "https://examplePublicKey@o0.ingest.sentry.io/0", + integrations: [Sentry.captureConsoleIntegration()], +}); +``` diff --git a/platform-includes/configuration/enable-pluggable-integrations/javascript.nestjs.mdx b/platform-includes/configuration/enable-pluggable-integrations/javascript.nestjs.mdx new file mode 100644 index 0000000000000..c3eaf5f99d800 --- /dev/null +++ b/platform-includes/configuration/enable-pluggable-integrations/javascript.nestjs.mdx @@ -0,0 +1,12 @@ + + +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "https://examplePublicKey@o0.ingest.sentry.io/0", + integrations: [], +}); + +Sentry.addIntegration(Sentry.captureConsoleIntegration()); +``` diff --git a/platform-includes/configuration/extra-error-data/javascript.nestjs.mdx b/platform-includes/configuration/extra-error-data/javascript.nestjs.mdx new file mode 100644 index 0000000000000..9675b24a6a9aa --- /dev/null +++ b/platform-includes/configuration/extra-error-data/javascript.nestjs.mdx @@ -0,0 +1,10 @@ + + +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.extraErrorDataIntegration()], +}); +``` diff --git a/platform-includes/configuration/integrations/javascript.nestjs.mdx b/platform-includes/configuration/integrations/javascript.nestjs.mdx new file mode 100644 index 0000000000000..9d77b34fc2da0 --- /dev/null +++ b/platform-includes/configuration/integrations/javascript.nestjs.mdx @@ -0,0 +1,34 @@ +### Integrations + +| | **Auto Enabled** | **Errors** | **Performance** | **Additional Context** | +| --------------------------------------------------------- | :--------------: | :--------: | :-------------: | :--------------------: | +| [`consoleIntegration`](./console) | ✓ | | | ✓ | +| [`contextLinesIntegration`](./contextlines) | ✓ | ✓ | | | +| [`dedupeIntegration`](./dedupe) | ✓ | ✓ | | | +| [`functionToStringIntegration`](./functiontostring) | ✓ | | | | +| [`graphqlIntegration`](./graphql) | ✓ | | ✓ | | +| [`httpIntegration`](./http) | ✓ | ✓ | ✓ | ✓ | +| [`inboundFiltersIntegration`](./inboundfilters) | ✓ | ✓ | | | +| [`linkedErrorsIntegration`](./linkederrors) | ✓ | ✓ | | | +| [`modulesIntegration`](./modules) | ✓ | | | ✓ | +| [`mongoIntegration`](./mongo) | ✓ | | ✓ | | +| [`mongooseIntegration`](./mongoose) | ✓ | | ✓ | | +| [`mysqlIntegration`](./mysql) | ✓ | | ✓ | | +| [`mysql2Integration`](./mysql2) | ✓ | | ✓ | | +| [`nodeContextIntegration`](./nodecontext) | ✓ | | | ✓ | +| [`nativeNodeFetchIntegration`](./nodefetch) | ✓ | | ✓ | ✓ | +| [`onUncaughtExceptionIntegration`](./onuncaughtexception) | ✓ | ✓ | | | +| [`onUnhandledRejectionIntegration`](./unhandledrejection) | ✓ | ✓ | | | +| [`postgresIntegration`](./postgres) | ✓ | | ✓ | | +| [`prismaIntegration`](./prisma) | | | ✓ | | +| [`redisIntegration`](./redis) | ✓ | | ✓ | | +| [`requestDataIntegration`](./requestdata) | ✓ | | ✓ | | +| [`anrIntegration`](./anr) | | ✓ | | | +| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ | +| [`debugIntegration`](./debug) | | | | | +| [`extraErrorDataIntegration`](./extraerrordata) | | | | ✓ | +| [`localVariablesIntegration`](./localvariables) | | ✓ | | | +| [`nodeProfilingIntegration`](./nodeprofiling) | | | ✓ | | +| [`rewriteFramesIntegration`](./rewriteframes) | | ✓ | | | +| [`sessionTimingIntegration`](./sessiontiming) | | | | ✓ | +| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | ✓ | diff --git a/platform-includes/configuration/requestdata/javascript.nestjs.mdx b/platform-includes/configuration/requestdata/javascript.nestjs.mdx new file mode 100644 index 0000000000000..4e66e7c8a5837 --- /dev/null +++ b/platform-includes/configuration/requestdata/javascript.nestjs.mdx @@ -0,0 +1,10 @@ + + +```javascript {tabTitle: npm} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.requestDataIntegration()], +}); +``` diff --git a/platform-includes/configuration/rewrite-frames/javascript.nestjs.mdx b/platform-includes/configuration/rewrite-frames/javascript.nestjs.mdx new file mode 100644 index 0000000000000..7f2e7a93082e1 --- /dev/null +++ b/platform-includes/configuration/rewrite-frames/javascript.nestjs.mdx @@ -0,0 +1,21 @@ + + +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.rewriteFramesIntegration( + { + // root path that will be stripped from the current frame's filename by the default iteratee if the filename is an absolute path + root: string; + + // a custom prefix that will be used by the default iteratee (default: `app://`) + prefix: string; + + // function that takes the frame, applies a transformation, and returns it + iteratee: (frame) => frame; + } + )], +}); +``` diff --git a/platform-includes/configuration/sessiontiming/javascript.nestjs.mdx b/platform-includes/configuration/sessiontiming/javascript.nestjs.mdx new file mode 100644 index 0000000000000..2946c4c27ea74 --- /dev/null +++ b/platform-includes/configuration/sessiontiming/javascript.nestjs.mdx @@ -0,0 +1,10 @@ + + +```javascript {tabTitle: JavaScript} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [Sentry.sessionTimingIntegration()], +}); +``` diff --git a/platform-includes/enriching-events/import/javascript.nestjs.mdx b/platform-includes/enriching-events/import/javascript.nestjs.mdx new file mode 100644 index 0000000000000..794f3e9c92485 --- /dev/null +++ b/platform-includes/enriching-events/import/javascript.nestjs.mdx @@ -0,0 +1,3 @@ +```javascript +import * as Sentry from "@sentry/nestjs"; +``` diff --git a/platform-includes/getting-started-verify/javascript.nestjs.mdx b/platform-includes/getting-started-verify/javascript.nestjs.mdx new file mode 100644 index 0000000000000..13ea70cf0ebe7 --- /dev/null +++ b/platform-includes/getting-started-verify/javascript.nestjs.mdx @@ -0,0 +1,14 @@ +```javascript +Sentry.startSpan({ + op: "test", + name: "My First Test Transaction", +}, () => { + setTimeout(() => { + try { + foo(); + } catch (e) { + Sentry.captureException(e); + } + }, 99); +}); +``` diff --git a/platform-includes/set-environment/javascript.nestjs.mdx b/platform-includes/set-environment/javascript.nestjs.mdx new file mode 100644 index 0000000000000..dda78e88ce7dd --- /dev/null +++ b/platform-includes/set-environment/javascript.nestjs.mdx @@ -0,0 +1,9 @@ +```javascript +import * as Sentry from "@sentry/nestjs"; +// or using CommonJS +// const Sentry = require('@sentry/nestjs'); + +Sentry.init({ + environment: "production", +}); +``` diff --git a/platform-includes/user-feedback/sdk-api-example/javascript.nestjs.mdx b/platform-includes/user-feedback/sdk-api-example/javascript.nestjs.mdx new file mode 100644 index 0000000000000..b892752163039 --- /dev/null +++ b/platform-includes/user-feedback/sdk-api-example/javascript.nestjs.mdx @@ -0,0 +1,33 @@ +```javascript +import * as Sentry from "@sentry/nestjs"; + +const eventId = Sentry.captureMessage("User Feedback"); +// OR: const eventId = Sentry.lastEventId(); + +const userFeedback = { + name: "John Doe", + email: "john@doe.com", + message: "I really like your App, thanks!", + associatedEventId: eventId, +}; +Sentry.captureFeedback(userFeedback); +``` + +You can also attach further data to the feedback event by passing a hint as a second argument. This is similar to other `capture` methods: + +```javascript +Sentry.captureFeedback( + { message: "I really like your App, thanks!" }, + { + captureContext: { + tags: { key: "value" }, + }, + attachments: [ + { + filename: "screenshot.png", + data: "base64-encoded-image", + }, + ], + } +); +``` diff --git a/platform-includes/user-feedback/sdk-api-example/javascript.node.mdx b/platform-includes/user-feedback/sdk-api-example/javascript.node.mdx new file mode 100644 index 0000000000000..0e80c8c80efe2 --- /dev/null +++ b/platform-includes/user-feedback/sdk-api-example/javascript.node.mdx @@ -0,0 +1,33 @@ +```javascript +import * as Sentry from "@sentry/node"; + +const eventId = Sentry.captureMessage("User Feedback"); +// OR: const eventId = Sentry.lastEventId(); + +const userFeedback = { + name: "John Doe", + email: "john@doe.com", + message: "I really like your App, thanks!", + associatedEventId: eventId, +}; +Sentry.captureFeedback(userFeedback); +``` + +You can also attach further data to the feedback event by passing a hint as a second argument. This is similar to other `capture` methods: + +```javascript +Sentry.captureFeedback( + { message: "I really like your App, thanks!" }, + { + captureContext: { + tags: { key: "value" }, + }, + attachments: [ + { + filename: "screenshot.png", + data: "base64-encoded-image", + }, + ], + } +); +```