Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nicohrubec committed Jun 27, 2024
1 parent fa227dc commit e6b5097
Show file tree
Hide file tree
Showing 24 changed files with 438 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/platforms/javascript/common/configuration/async-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<PlatformSection notSupported={["javascript.nestjs"]}>
```js
const Sentry = require("@sentry/node");

Expand All @@ -34,11 +35,32 @@ app.get("/my-route-2", function () {
// do something
});
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```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
});
```
</PlatformSection>

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:

<PlatformSection notSupported={["javascript.nestjs"]}>
```js
const Sentry = require("@sentry/node");

Expand All @@ -49,5 +71,18 @@ async function backgroundJob() {
});
}
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```js
const Sentry = require("@sentry/nestjs");

async function backgroundJob() {
return await Sentry.withIsolationScope(async () => {
// Everything inside of this will be isolated
await doSomething();
});
}
```
</PlatformSection>

Under the hood, the SDK uses Node's [AsyncLocalStorage API](https://nodejs.org/api/async_context.html#class-asynclocalstorage) to perform the isolation.
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<PlatformSection notSupported={["javascript.nestjs"]}>
```javascript
import * as Sentry from "@sentry/node";
import { initTRPC } from "@trpc/server";
Expand All @@ -47,6 +48,23 @@ const sentryMiddleware = t.middleware(

const sentrifiedProcedure = t.procedure.use(sentryMiddleware);
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```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);
```
</PlatformSection>

## Options

Expand Down
35 changes: 35 additions & 0 deletions docs/platforms/javascript/common/configuration/tree-shaking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<PlatformSection notSupported={["javascript.nestjs"]}>
```javascript
const Sentry = require("@sentry/node");

Expand All @@ -318,11 +319,29 @@ Sentry.initWithoutDefaultIntegrations({
],
});
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```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(),
],
});
```
</PlatformSection>

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

<PlatformSection notSupported={["javascript.nestjs"]}>
```javascript
const Sentry = require("@sentry/node");

Expand All @@ -336,5 +355,21 @@ Sentry.initWithoutDefaultIntegrations({
],
});
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```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(),
],
});
```
</PlatformSection>

</PlatformSection>
17 changes: 17 additions & 0 deletions docs/platforms/javascript/common/install/esm-without-import.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ You need to create a file named `instrument.mjs` that imports and initializes Se

<SignInNote />


<PlatformSection notSupported={["javascript.nestjs"]}>
```javascript {tabTitle:ESM} {filename: instrument.mjs}
import * as Sentry from "@sentry/node";

Expand All @@ -42,6 +44,21 @@ Sentry.init({
tracesSampleRate: 1.0,
});
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```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,
});
```
</PlatformSection>

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:

Expand Down
16 changes: 16 additions & 0 deletions docs/platforms/javascript/common/install/esm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<PlatformSection notSupported={["javascript.nestjs"]}>
```javascript {tabTitle:ESM} {filename: instrument.mjs}
import * as Sentry from "@sentry/node";

Expand All @@ -33,6 +34,21 @@ Sentry.init({
tracesSampleRate: 1.0,
});
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```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,
});
```
</PlatformSection>

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:

Expand Down
46 changes: 46 additions & 0 deletions docs/platforms/javascript/common/install/late-initializtion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ node --require @sentry/node/preload app.js

Then, in your application you can call `Sentry.init()` at a later point:

<PlatformSection notSupported={["javascript.nestjs"]}>
```javascript {filename: main.js}
const startApp = require("./app");
const fetchDsn = require("./utils/fetchDsn");
Expand All @@ -58,6 +59,28 @@ Sentry.init({
// From now on, Sentry is initialized,
// but the app is still auto-instrumented
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```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
```
</PlatformSection>

## Late Initialization with ESM

Expand All @@ -70,6 +93,7 @@ node --import @sentry/node/preload app.js

Then, in your application you can call `Sentry.init()` at a later point:

<PlatformSection notSupported={["javascript.nestjs"]}>
```javascript {filename: main.js}
import startApp from "./app";
import fetchDsn from "./utils/fetchDsn";
Expand All @@ -89,6 +113,28 @@ Sentry.init({
// From now on, Sentry is initialized,
// but the app is still auto-instrumented
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```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
```
</PlatformSection>

## What does Preloading mean?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<PlatformSection notSupported={["javascript.nestjs"]}>
```js
const Sentry = require("@sentry/node");
const {
Expand All @@ -40,6 +41,25 @@ Sentry.init({
// Afterwards, you can add additional instrumentation:
Sentry.addOpenTelemetryInstrumentation(new GenericPoolInstrumentation());
```
</PlatformSection>
<PlatformSection supported={["javascript.nestjs"]}>
```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());
```
</PlatformSection>

Any instrumentation added like this will be automatically picked up by Sentry.

Expand Down
11 changes: 11 additions & 0 deletions platform-includes/capture-error/javascript.nestjs.mdx
Original file line number Diff line number Diff line change
@@ -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);
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<SignInNote />

```javascript {tabTitle: JavaScript}
import * as Sentry from "@sentry/nestjs";

Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [Sentry.captureConsoleIntegration()],
});
```
10 changes: 10 additions & 0 deletions platform-includes/configuration/contextlines/javascript.nestjs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<SignInNote />

```javascript {tabTitle: JavaScript}
import * as Sentry from "@sentry/nestjs";

Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [Sentry.captureConsoleIntegration()],
});
```
10 changes: 10 additions & 0 deletions platform-includes/configuration/debug/javascript.nestjs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<SignInNote />

```javascript {tabTitle: JavaScript}
import * as Sentry from "@sentry/nestjs";

Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [Sentry.debugIntegration()],
});
```
11 changes: 11 additions & 0 deletions platform-includes/configuration/dedupe/javascript.nestjs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<SignInNote />

```javascript {tabTitle: JavaScript}
import * as Sentry from "@sentry/nestjs";

Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [Sentry.dedupeIntegration()],
});
```
ing
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<SignInNote />

```javascript {tabTitle: JavaScript}
import * as Sentry from "@sentry/nestjs";

Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
integrations: [Sentry.captureConsoleIntegration()],
});
```
Loading

0 comments on commit e6b5097

Please sign in to comment.