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

BrowserTracing id property missing in v7 #5635

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

Hi, I am trying to check if Sentry's APM is initialized with this line of code.

import * as Sentry from '@sentry/react';
import {Integrations as TracingIntegrations} from '@sentry/tracing';
Sentry.getCurrentHub()
 .getClient()
 ?.getIntegration(TracingIntegrations.BrowserTracing)

This worked in v6, but while migrating to v7 BrowserTracing removed it's ID property and now Typescript is giving me this error:

Argument of type 'typeof BrowserTracing' is not assignable to parameter of type 'IntegrationClass<BrowserTracing>'.
 Property 'id' is missing in type 'typeof BrowserTracing' but required in type 'IntegrationClass<BrowserTracing>'.

Is there fix for this typescript error? I know the static property id is removed in v7 from BrowserTracing

You must be logged in to vote

For now though, you can use the hasTracingEnabled util from @sentry/tracing to check if Sentry's APM is initialized. We recommend using sampleRate to decide to turn on tracing or not.

import { hasTracingEnabled } from '@sentry/tracing';
/**
* Determines if tracing is currently enabled.
*
* Tracing is enabled when at least one of `tracesSampleRate` and `tracesSampler` is defined in the SDK config.
*/
export function hasTracingEnabled(
maybeOptions?: Pick<Options, 'tracesSampleRate' | 'tracesSampler'> | undefined,
): boolean {
const client = getCurrentHub().getCl...

Replies: 2 comments 4 replies

Comment options

Ah this is a bug! Will fix: #5647

You must be logged in to vote
0 replies
Comment options

For now though, you can use the hasTracingEnabled util from @sentry/tracing to check if Sentry's APM is initialized. We recommend using sampleRate to decide to turn on tracing or not.

import { hasTracingEnabled } from '@sentry/tracing';
/**
* Determines if tracing is currently enabled.
*
* Tracing is enabled when at least one of `tracesSampleRate` and `tracesSampler` is defined in the SDK config.
*/
export function hasTracingEnabled(
maybeOptions?: Pick<Options, 'tracesSampleRate' | 'tracesSampler'> | undefined,
): boolean {
const client = getCurrentHub().getClient();
const options = maybeOptions || (client && client.getOptions());
return !!options && ('tracesSampleRate' in options || 'tracesSampler' in options);
}
You must be logged in to vote
4 replies
Comment options

Thanks, using hasTracingEnabled() looks like it works as a workaround. What do you mean by using sampleRate to decide to turn on tracing or not?

Comment options

Ah, that if tracesSampleRate or tracesSampler is defined in init, then you enable tracing. For example:

const initSettings = {
 dsn: ...
}
if (shouldEnableTracing()) {
 initSettings.tracesSampleRate = 1.0
}
Sentry.init(initSettings);
Comment options

Don't you have to define either tracesSampleRate or tracesSampler in order to enable tracing? So if they are defined in init, tracing is turn on already?

Comment options

Don't you have to define either tracesSampleRate or tracesSampler in order to enable tracing? So if they are defined in init, tracing is turn on already?

Yup exactly. My example was more to show how you would turn off/on tracing during SDK init.

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

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