Skip to content

Commit 21fbf37

Browse files
BYKdcramer
authored andcommitted
fix: Always try to use sidecar along with direct SDK transport (#672)
Fixes #669
1 parent 2d3c759 commit 21fbf37

File tree

8 files changed

+84
-62
lines changed

8 files changed

+84
-62
lines changed

.changeset/cyan-gifts-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@spotlightjs/overlay': patch
3+
---
4+
5+
fix: Always try to use sidecar along with direct SDK transport

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"notarytool",
2020
"outro",
2121
"pageload",
22+
"platformicons",
2223
"postject",
24+
"raleway",
2325
"rcodesign",
2426
"spotlightjs",
2527
"svgr",

packages/overlay/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
"devDependencies": {
3030
"@fontsource/raleway": "^5.1.0",
3131
"@microlink/react-json-view": "^1.23.4",
32-
"@sentry/react": "^8.43.0",
33-
"@sentry/types": "^8.33.1",
34-
"@sentry/utils": "^8.33.1",
32+
"@sentry/browser": "^8.51.0",
33+
"@sentry/react": "^8.51.0",
34+
"@sentry/types": "^8.51.0",
35+
"@sentry/core": "^8.51.0",
3536
"@spotlightjs/sidecar": "workspace:*",
3637
"@spotlightjs/tsconfig": "workspace:*",
3738
"@types/beautify": "^0.0.3",

packages/overlay/src/integrations/sentry/data/sentryDataCache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Envelope } from '@sentry/types';
1+
import type { Envelope } from '@sentry/types';
22
import { CONTEXT_LINES_ENDPOINT } from '@spotlightjs/sidecar/constants';
33
import { DEFAULT_SIDECAR_URL } from '~/constants';
4-
import { RawEventContext } from '~/integrations/integration';
4+
import type { RawEventContext } from '~/integrations/integration';
55
import { log } from '../../../lib/logger';
66
import { generateUuidv4 } from '../../../lib/uuid';
7-
import { Sdk, SentryErrorEvent, SentryEvent, SentryTransactionEvent, Span, Trace } from '../types';
7+
import type { Sdk, SentryErrorEvent, SentryEvent, SentryTransactionEvent, Span, Trace } from '../types';
88
import { getNativeFetchImplementation } from '../utils/fetch';
99
import { sdkToPlatform } from '../utils/sdkToPlatform';
1010
import { groupSpans } from '../utils/traces';

packages/overlay/src/integrations/sentry/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import InsightsTab from './tabs/InsightsTab';
1111
import PerformanceTab from './tabs/PerformanceTab';
1212
import type { SentryErrorEvent, SentryEvent } from './types';
1313

14+
import { spotlightBrowserIntegration } from '@sentry/browser';
15+
1416
const HEADER = 'application/x-sentry-envelope';
1517

1618
type SentryIntegrationOptions = {
@@ -28,10 +30,13 @@ export default function sentryIntegration(options: SentryIntegrationOptions = {}
2830
if (options.retries == null) {
2931
options.retries = 10;
3032
}
33+
let baseSidecarUrl: string | undefined = undefined;
3134
if (sidecarUrl) {
32-
sentryDataCache.setSidecarUrl(removeURLSuffix(sidecarUrl, '/stream'));
35+
baseSidecarUrl = removeURLSuffix(sidecarUrl, '/stream');
36+
sentryDataCache.setSidecarUrl(baseSidecarUrl);
3337
}
34-
addSpotlightIntegrationToSentry(options);
38+
log('Setting up Sentry integration for Spotlight');
39+
addSpotlightIntegrationToSentry(options, baseSidecarUrl && new URL('/stream', baseSidecarUrl).href);
3540

3641
if (options.openLastError) {
3742
sentryDataCache.subscribe('event', (e: SentryEvent) => {
@@ -197,7 +202,7 @@ type WindowWithSentry = Window & {
197202
*
198203
* @param options options of the Sentry integration for Spotlight
199204
*/
200-
function addSpotlightIntegrationToSentry(options: SentryIntegrationOptions) {
205+
function addSpotlightIntegrationToSentry(options: SentryIntegrationOptions, sidecarUrl?: string) {
201206
if (options.injectIntoSDK === false) {
202207
return;
203208
}
@@ -211,7 +216,7 @@ function addSpotlightIntegrationToSentry(options: SentryIntegrationOptions) {
211216
log(`Will retry ${options.retries} more time(s) at 100ms intervals...`);
212217
options.retries--;
213218
setTimeout(() => {
214-
addSpotlightIntegrationToSentry(options);
219+
addSpotlightIntegrationToSentry(options, sidecarUrl);
215220
}, 500);
216221
}
217222
return;
@@ -243,12 +248,12 @@ function addSpotlightIntegrationToSentry(options: SentryIntegrationOptions) {
243248
const existingIntegration = Object.keys(sentryClient._integrations).find(i => /spotlight/i.test(i));
244249
if (existingIntegration) {
245250
log(
246-
`Skipping direct integration as there's already a Spotlight integration enabled in Sentry SDK: ${existingIntegration}`,
251+
`Skipping adding integration as there's already a Spotlight integration enabled in Sentry SDK: ${existingIntegration}`,
247252
);
248253
return;
249254
}
250-
const integration = spotlightIntegration();
251-
sentryClient.addIntegration(integration);
255+
sentryClient.addIntegration(spotlightIntegration());
256+
sentryClient.addIntegration(spotlightBrowserIntegration({ sidecarUrl }));
252257
} catch (e) {
253258
warn('Failed to add Spotlight integration to Sentry', e);
254259
log('Please open an issue with the error at: https://github.com/getsentry/spotlight/issues/new/choose');

packages/overlay/src/integrations/sentry/sentry-integration.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Client, Envelope, Event, Integration } from '@sentry/types';
2-
import { serializeEnvelope } from '@sentry/utils';
2+
import { serializeEnvelope } from '@sentry/core';
33
import { trigger } from '../../lib/eventTarget';
44
import { log } from '../../lib/logger';
55
import sentryDataCache from './data/sentryDataCache';
@@ -20,14 +20,13 @@ export const spotlightIntegration = () => {
2020
setupOnce: () => {
2121
/* Empty function to ensure compatibility w/ JS SDK v7 >= 7.99.0 */
2222
},
23-
setup: () => {
24-
log('Setting up the *direct* Sentry SDK integration for Spotlight');
25-
},
23+
setup: () => {},
2624
processEvent: (event: Event) => {
2725
// We don't want to send interaction transactions/root spans created from
2826
// clicks within Spotlight to Sentry. Neither do we want them to be sent to
2927
// spotlight.
3028
if (isSpotlightInteraction(event)) {
29+
log('Dropping transaction created from Spotlight interaction');
3130
return null;
3231
}
3332

packages/overlay/src/sidecar.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type React from 'react';
21
import { log } from './lib/logger';
32

43
export function connectToSidecar(
54
sidecarUrl: string,
65
// Content Type to listener
76
contentTypeListeners: Record<string, (event: { data: string | Uint8Array }) => void>,
8-
setOnline: React.Dispatch<React.SetStateAction<boolean>>,
7+
setOnline: (online: boolean) => void,
98
): () => void {
109
log('Connecting to sidecar at', sidecarUrl);
1110
const sidecarStreamUrl = new URL('/stream', sidecarUrl);
@@ -18,12 +17,12 @@ export function connectToSidecar(
1817

1918
source.addEventListener('open', () => {
2019
setOnline(true);
21-
log('Open');
20+
log('Sidecar connected.');
2221
});
2322

2423
source.addEventListener('error', err => {
2524
setOnline(false);
26-
console.error('EventSource failed:', err);
25+
console.error('Sidecar connection error:', err);
2726
});
2827

2928
return () => {

pnpm-lock.yaml

Lines changed: 52 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)