sentry-javascript
sentry-javascript copied to clipboard
BrowserTracing id property missing in v7
Discussed in https://github.com/getsentry/sentry-javascript/discussions/5635
Originally posted by martinkwan August 26, 2022 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
So - we intentionally don't use the id here for treeshaking purposes: https://github.com/getsentry/sentry-javascript/blob/f563eae7e032f2b3d71147be922f95d98babdcb1/packages/tracing/src/browser/browsertracing.ts#L124-L127
We should find a workaround though to unblock the user.
Of course, this is very dirty but just to unblock: We have getIntegrationById() on the BaseClient, meaning if we applied a sprinkle of @ts-ignore we could do Sentry.getCurrentHub().getClient()?.getIntegrationById('BrowserTracing').
I knew this change would bite us in the butt some day - sorry about that.