Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BrowserClient constructor demands many properties contra documentation #5293

Answered by AbhiPrasad
cefn asked this question in Q&A
Discussion options

How should I create a BrowserClient for our microfrontend in a type-safe way? There is already a call to Sentry.init() happening outside our microfrontend. Any errors we are able to catch that originate in our microfrontend code should be routed to our own dsn (with only uncaught errors propagating to the main hub).

I attempted to create a BrowserClient as below in some typescript code (I randomised the DSN numbers)...

 const client = new BrowserClient({
 dsn: 'https://2345890734523459087@w2239374.ingest.sentry.io/23459345',
 environment: NODE_ENV,
 release: version,
 });

However, the BrowserClient interface seems to demand a surprising number of elements, not all of which I know how to fulfil. It fails to compile as follows...

TS2345: Argument of type '{ dsn: string; environment: string; release: string; }' is not assignable to parameter of type 'BrowserClientOptions'.  Type '{ dsn: string; environment: string; release: string; }' is missing the following properties from type 'BrowserClientOptions': integrations, transport, stackParser

Needing to fulfil integrations, transport and stackParser seems over-complex and contrasts with the documentation, in which only a dsn is needed (e.g. https://docs.sentry.io/platforms/javascript/troubleshooting/#using-a-client-directly ).

What am I doing wrong, or is the typing of the call to the BrowserClient constructor flawed?

You must be logged in to vote

Changing the client constructor was on purpose, as it allowed for us to enable tree shaking for the SDKs. Please see our docs for more details: https://docs.sentry.io/platforms/javascript/configuration/tree-shaking/#tree-shaking-default-integrations. If you look at the tree shaking docs, you can see that creation of a browser client is quite simple, and that you can abstract it into a function if you need multiple clients.

We know the docs are out of date, and we will fix them up! This is being tracked in #5298.

Replies: 1 comment

Comment options

Changing the client constructor was on purpose, as it allowed for us to enable tree shaking for the SDKs. Please see our docs for more details: https://docs.sentry.io/platforms/javascript/configuration/tree-shaking/#tree-shaking-default-integrations. If you look at the tree shaking docs, you can see that creation of a browser client is quite simple, and that you can abstract it into a function if you need multiple clients.

We know the docs are out of date, and we will fix them up! This is being tracked in #5298.

You must be logged in to vote
0 replies
Answer selected by AbhiPrasad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /