GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sentry-javascript/docs/v8-initializing.md at develop · getsentry/sentry-javascript

Expand file tree

/

v8-initializing.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
65 lines (49 loc) · 1.71 KB
/

v8-initializing.md

Copy path

File metadata and controls

65 lines (49 loc) · 1.71 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Initializing the SDK in v8

In v8, manual initialization of the SDK will work as follows.

Classic initialization

import * as Sentry from '@sentry/browser';

Sentry.init({
  dsn: 'xxx',
});

This will initialize the SDK with all defaults & make it the currently active Sentry instance. This will continue to use the existing global, isolation & current scope, and just bind the client to it.

Using multiple clients in Node

In an environment with multiple execution contexts (e.g. Node), you can setup multiple clients that are active for different contexts, like this:

import * as Sentry from '@sentry/node';

// Sets up the _default_ client
Sentry.init({
  dsn: 'xxx',
});

// One execution context with client A
Sentry.withScope(() => {
  const clientA = new Client();
  Sentry.setCurrentClient(clientA); // binds this client to the current execution context only!
  clientA.init();
});

// One execution context with client B
Sentry.withScope(() => {
  const clientB = new Client();
  Sentry.setCurrentClient(clientB); // binds this client to the current execution context only!
  clientB.init();
});

Using multiple clients in Browser

In environments without execution contexts, like the browser, you can only ever have a single active client. You can, however, create further clients and use them manually:

// Default client - this is used everywhere
Sentry.init({
  dsn: 'xxx',
});

// Setup a manual client
const clientA = new Client();
const scope = new Scope();
scope.setClient(clientA);
// You can capture exceptions manually for this client like this:
scope.captureException();

This is also necessary e.g. if you have a browser extension or some other code that runs in a shared environment.

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.