Skip to content
Merged
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
14 changes: 12 additions & 2 deletions src/platforms/javascript/common/troubleshooting/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,13 @@ This also helps to prevent tracking of any parent application errors in case you
inside of it. In this example we use `@sentry/browser` but it's also applicable to `@sentry/node`.

```javascript
import { BrowserClient } from "@sentry/browser";
import { BrowserClient, defaultStackParser, defaultIntegrations, makeFetchTransport } from "@sentry/browser";

const client = new BrowserClient({
dsn: "___PUBLIC_DSN___",
transport: makeFetchTransport,
stackParser: defaultStackParser,
integrations: defaultIntegrations,
});

client.captureException(new Error("example"));
Expand All @@ -278,10 +281,13 @@ client.captureException(new Error("example"));
While the above sample should work perfectly fine, some methods like `configureScope` and `withScope` are missing on the `Client` because the `Hub` takes care of the state management. That's why it may be easier to create a new `Hub` and bind your `Client` to it. The result is the same but you will also get state management with it.

```javascript
import { BrowserClient, Hub } from "@sentry/browser";
import { BrowserClient, defaultStackParser, defaultIntegrations, makeFetchTransport } from "@sentry/browser";

const client = new BrowserClient({
dsn: "___PUBLIC_DSN___",
transport: makeFetchTransport,
stackParser: defaultStackParser,
integrations: defaultIntegrations,
});

const hub = new Hub(client);
Expand Down Expand Up @@ -335,6 +341,8 @@ HappyIntegration.id = "HappyIntegration";

const client1 = new Sentry.BrowserClient({
dsn: "___PUBLIC_DSN___",
transport: Sentry.makeFetchTransport,
stackParser: Sentry.defaultStackParser,
integrations: [...Sentry.defaultIntegrations, new HappyIntegration()],
beforeSend(event) {
console.log("client 1", event);
Expand All @@ -345,6 +353,8 @@ const hub1 = new Sentry.Hub(client1);

const client2 = new Sentry.BrowserClient({
dsn: "___PUBLIC_DSN___", // Can be a different DSN
transport: Sentry.makeFetchTransport,
stackParser: Sentry.defaultStackParser,
integrations: [...Sentry.defaultIntegrations, new HappyIntegration()],
beforeSend(event) {
console.log("client 2", event);
Expand Down