getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.87k stars 1.55k forks source link

BrowserTracing id property missing in v7 #5647

Closed AbhiPrasad closed 1 year ago

AbhiPrasad commented 2 years ago

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'. Property 'id' is missing in type 'typeof BrowserTracing' but required in type 'IntegrationClass'. ``` Is there fix for this typescript error? I know the static property id is removed in v7 from BrowserTracing
AbhiPrasad commented 2 years ago

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.

lforst commented 2 years ago

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.