Skip to content

Commit 8bed105

Browse files
authored
fix: Don't use direct-transport when full page (#658)
1 parent 9606eb2 commit 8bed105

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

.changeset/cold-teachers-tell.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 direct transport init when sidecar transport is already enabled

packages/overlay/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export async function init(options: SpotlightOverlayOptions = {}) {
138138
const finalExperiments = { ...DEFAULT_EXPERIMENTS, ...experiments };
139139

140140
// Sentry is enabled by default
141-
const defaultIntegrations = () => [sentry({ injectIntoSDK: !isLoadedFromSidecar })];
141+
const defaultIntegrations = () => [sentry({ injectIntoSDK: !isLoadedFromSidecar && !fullPage })];
142142

143143
const context: SpotlightContext = {
144144
open: openSpotlight,

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ function parseJSONFromBuffer(data: Uint8Array): object {
118118
* @returns parsed envelope
119119
*/
120120
export function processEnvelope(rawEvent: RawEventContext) {
121-
// Use this weird way of converting to Uint8Array as we use SSE
122-
// which always uses utf-8 encoding but we can have envelopes with
123-
// binary data such as screenshots or videos.
124-
// Ideally we'd use base64 encoding for binary data but that requires
125-
// a breaking change in the sidecar so skipping that for now.
126121
let buffer =
127122
typeof rawEvent.data === 'string'
128123
? Uint8Array.from(Array.from(rawEvent.data, c => c.charCodeAt(0)))
@@ -243,8 +238,18 @@ function addSpotlightIntegrationToSentry(options: SentryIntegrationOptions) {
243238
sentryClient._dsn = undefined;
244239
// @ts-ignore
245240
sentryClient._options.tracesSampler = () => 1;
241+
// @ts-ignore
242+
sentryClient._options.sampleRate = 1;
246243

247244
try {
245+
// @ts-expect-error ts(2339) -- We're accessing a private property here
246+
const existingIntegration = Object.keys(sentryClient._integrations).find(i => /spotlight/i.test(i));
247+
if (existingIntegration) {
248+
log(
249+
`Skipping direct integration as there's already a Spotlight integration enabled in Sentry SDK: ${existingIntegration}`,
250+
);
251+
return;
252+
}
248253
const integration = spotlightIntegration();
249254
sentryClient.addIntegration(integration);
250255
} catch (e) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import sentryDataCache from './data/sentryDataCache';
1616
*/
1717
export const spotlightIntegration = () => {
1818
return {
19-
name: 'SpotlightBrowser',
19+
name: 'SpotlightBrowserDirect',
2020
setupOnce: () => {
2121
/* Empty function to ensure compatibility w/ JS SDK v7 >= 7.99.0 */
2222
},

0 commit comments

Comments
 (0)