diff --git a/.changeset/cold-kings-rush.md b/.changeset/cold-kings-rush.md
new file mode 100644
index 00000000..8585f286
--- /dev/null
+++ b/.changeset/cold-kings-rush.md
@@ -0,0 +1,6 @@
+---
+'@spotlightjs/spotlight': patch
+'@spotlightjs/overlay': patch
+---
+
+added a check for spotlight v1.x.x to not load sentry sdk >= v8
diff --git a/.changeset/ninety-days-tie.md b/.changeset/ninety-days-tie.md
new file mode 100644
index 00000000..086c307c
--- /dev/null
+++ b/.changeset/ninety-days-tie.md
@@ -0,0 +1,5 @@
+---
+'@spotlightjs/overlay': patch
+---
+
+updated the logic to retrieve the version of browser sentry sdk.
diff --git a/packages/overlay/src/components/Overview.tsx b/packages/overlay/src/components/Overview.tsx
index 4a694a52..fc4a6612 100644
--- a/packages/overlay/src/components/Overview.tsx
+++ b/packages/overlay/src/components/Overview.tsx
@@ -51,7 +51,11 @@ export default function Overview({
- Not Found - How'd you manage to get here?} key={'not-found'}>
+ Not Found - How'd you manage to get here?
}
+ key={'not-found'}
+ >
{tabs.map(tab => {
const TabContent = tab.content && tab.content;
diff --git a/packages/overlay/src/integrations/sentry/constants.ts b/packages/overlay/src/integrations/sentry/constants.ts
index 37a3f3b3..9ed8477c 100644
--- a/packages/overlay/src/integrations/sentry/constants.ts
+++ b/packages/overlay/src/integrations/sentry/constants.ts
@@ -190,3 +190,5 @@ export const PERFORMANCE_SCORE_PROFILES = {
// }
],
};
+
+export const SDK_VERSION_SUPPORT_REGEX = /^[0-7]\.\d+\.\d+$/;
diff --git a/packages/overlay/src/integrations/sentry/index.ts b/packages/overlay/src/integrations/sentry/index.ts
index 29c31ee9..2927b85f 100644
--- a/packages/overlay/src/integrations/sentry/index.ts
+++ b/packages/overlay/src/integrations/sentry/index.ts
@@ -1,14 +1,17 @@
import type { Envelope } from '@sentry/types';
import { getSpotlightEventTarget } from '../../lib/eventTarget';
-import { log } from '../../lib/logger';
+import { log, warn } from '../../lib/logger';
import type { Integration, RawEventContext } from '../integration';
import sentryDataCache from './data/sentryDataCache';
import { Spotlight } from './sentry-integration';
import DeveloperInfo from './tabs/DeveloperInfo';
import ErrorsTab from './tabs/ErrorsTab';
+import InfoTab from './tabs/InfoTab';
import PerformanceTab from './tabs/PerformanceTab';
import SdksTab from './tabs/SdksTab';
import TracesTab from './tabs/TracesTab';
+import { LegacyCarrier, WindowWithSentry } from './types';
+import { checkBrowserSDKVersion } from './utils/sdkValidation';
const HEADER = 'application/x-sentry-envelope';
@@ -17,7 +20,7 @@ type SentryIntegrationOptions = {
injectIntoSDK?: boolean;
};
-export default function sentryIntegration(options?: SentryIntegrationOptions) {
+function _sentryIntegration(options?: SentryIntegrationOptions) {
return {
name: 'sentry',
forwardedContentType: [HEADER],
@@ -96,19 +99,36 @@ export default function sentryIntegration(options?: SentryIntegrationOptions) {
} satisfies Integration;
}
-type WindowWithSentry = Window & {
- __SENTRY__?: {
- hub: {
- getClient: () =>
- | {
- setupIntegrations: (force: boolean) => void;
- addIntegration(integration: Integration): void;
- on: (event: string, callback: (envelope: Envelope) => void) => void;
- }
- | undefined;
- };
- };
-};
+function _fallbackSentryIntegration() {
+ return {
+ name: 'sentry',
+ forwardedContentType: [],
+ setup: () => {},
+ processEvent: () => undefined,
+ tabs: () => {
+ return [
+ {
+ id: 'info',
+ title: 'Info',
+ content: () =>
+ InfoTab({
+ info: 'This version of Spotlight supports Sentry browser SDK version less than 8.x.x. Check out Spotlight v2.x.x',
+ }),
+ },
+ ];
+ },
+ reset: () => {},
+ } satisfies Integration;
+}
+
+export default function sentryIntegration(options?: SentryIntegrationOptions) {
+ if (checkBrowserSDKVersion()) {
+ return _sentryIntegration(options);
+ } else {
+ warn(`This version of Spotlight only supports Sentry browser SDK versions below 8.x.x. Check out Spotlight v2.x.x`);
+ return _fallbackSentryIntegration();
+ }
+}
export function processEnvelope(rawEvent: RawEventContext) {
const { data } = rawEvent;
@@ -150,12 +170,14 @@ function addSpotlightIntegrationToSentry(options?: SentryIntegrationOptions) {
if (options?.injectIntoSDK === false) return;
// A very hacky way to hook into Sentry's SDK
// but we love hacks
- const sentryHub = (window as WindowWithSentry).__SENTRY__?.hub;
- const sentryClient = sentryHub?.getClient();
- if (sentryClient) {
- const spotlightIntegration = new Spotlight({
- sidecarUrl: options?.sidecarUrl,
- });
- sentryClient.addIntegration(spotlightIntegration);
+ const sentryHub = ((window as WindowWithSentry).__SENTRY__ as LegacyCarrier)?.hub;
+ if (sentryHub) {
+ const sentryClient = sentryHub?.getClient();
+ if (sentryClient) {
+ const spotlightIntegration = new Spotlight({
+ sidecarUrl: options?.sidecarUrl,
+ });
+ sentryClient.addIntegration(spotlightIntegration);
+ }
}
}
diff --git a/packages/overlay/src/integrations/sentry/tabs/InfoTab.tsx b/packages/overlay/src/integrations/sentry/tabs/InfoTab.tsx
new file mode 100644
index 00000000..922970e9
--- /dev/null
+++ b/packages/overlay/src/integrations/sentry/tabs/InfoTab.tsx
@@ -0,0 +1,3 @@
+export default function InfoTab({ info }: { info?: string }) {
+ return {info}
;
+}
diff --git a/packages/overlay/src/integrations/sentry/types.ts b/packages/overlay/src/integrations/sentry/types.ts
index 15e1a616..c09a2759 100644
--- a/packages/overlay/src/integrations/sentry/types.ts
+++ b/packages/overlay/src/integrations/sentry/types.ts
@@ -1,4 +1,5 @@
-import { Measurements } from '@sentry/types';
+import { Client, Envelope, Measurements } from '@sentry/types';
+import { Integration } from '../integration';
export type FrameVars = {
[key: string]: string;
@@ -212,3 +213,37 @@ export type MetricWeightsProps = {
fid: number;
ttfb: number;
};
+
+type V8Carrier = {
+ stack: {
+ getScope?: () => {
+ getClient?: () => Client | undefined;
+ };
+ };
+};
+
+export type LegacyCarrier = {
+ /** pre-v8 way of accessing client (v7 and earlier) */
+ hub: {
+ getClient: () =>
+ | {
+ setupIntegrations: (force: boolean) => void;
+ addIntegration(integration: Integration): void;
+ on: (event: string, callback: (envelope: Envelope) => void) => void;
+ getOptions: () => {
+ _metadata: {
+ sdk: {
+ version: string;
+ };
+ };
+ };
+ }
+ | undefined;
+ };
+};
+
+export type VersionedCarrier = { version: string } & Record, V8Carrier>;
+
+export type WindowWithSentry = Window & {
+ __SENTRY__?: LegacyCarrier | VersionedCarrier;
+};
diff --git a/packages/overlay/src/integrations/sentry/utils/sdkValidation.ts b/packages/overlay/src/integrations/sentry/utils/sdkValidation.ts
new file mode 100644
index 00000000..3065e7a0
--- /dev/null
+++ b/packages/overlay/src/integrations/sentry/utils/sdkValidation.ts
@@ -0,0 +1,15 @@
+import { SDK_VERSION_SUPPORT_REGEX } from '../constants';
+import { LegacyCarrier, VersionedCarrier, WindowWithSentry } from '../types';
+
+export function checkBrowserSDKVersion() {
+ const sentrySDKVersionPreV8 = ((window as WindowWithSentry).__SENTRY__ as LegacyCarrier)?.hub
+ ?.getClient()
+ ?.getOptions()?._metadata?.sdk?.version;
+
+ const sentrySDKVersionPostV8 = ((window as WindowWithSentry).__SENTRY__ as VersionedCarrier)?.version;
+
+ // if browser SDK verion not found, return true to load the events from server side.
+ return sentrySDKVersionPreV8 || sentrySDKVersionPostV8
+ ? new RegExp(SDK_VERSION_SUPPORT_REGEX).test(sentrySDKVersionPreV8 || sentrySDKVersionPostV8)
+ : true;
+}
diff --git a/packages/overlay/src/lib/logger.ts b/packages/overlay/src/lib/logger.ts
index ae54419c..de9867ac 100644
--- a/packages/overlay/src/lib/logger.ts
+++ b/packages/overlay/src/lib/logger.ts
@@ -13,3 +13,21 @@ export function log(...args: unknown[]) {
console.log('🔎 [Spotlight]', ...args);
}
}
+
+export function warn(...args: unknown[]) {
+ if (loggerActive) {
+ console.warn('🔎 [Spotlight]', ...args);
+ }
+}
+
+export function info(...args: unknown[]) {
+ if (loggerActive) {
+ console.info('🔎 [Spotlight]', ...args);
+ }
+}
+
+export function error(...args: unknown[]) {
+ if (loggerActive) {
+ console.error('🔎 [Spotlight]', ...args);
+ }
+}
diff --git a/packages/website/src/components/InstallCommand.mdx b/packages/website/src/components/InstallCommand.mdx
index ce764a62..9c6c4b83 100644
--- a/packages/website/src/components/InstallCommand.mdx
+++ b/packages/website/src/components/InstallCommand.mdx
@@ -7,17 +7,17 @@ import { Tabs, TabItem } from '@astrojs/starlight/components';
```sh
- npm add @spotlightjs/spotlight
+ npm i @spotlightjs/spotlight --save-dev
```
```sh
- pnpm add @spotlightjs/spotlight
+ pnpm add -D @spotlightjs/spotlight
```
```sh
- yarn add @spotlightjs/spotlight
+ yarn add -D @spotlightjs/spotlight
```
\ No newline at end of file