Skip to content

Commit

Permalink
fix: Don't use direct-transport when full page
Browse files Browse the repository at this point in the history
  • Loading branch information
BYK committed Jan 17, 2025
1 parent 9606eb2 commit 34e0e36
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-teachers-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spotlightjs/overlay': patch
---

Fix direct transport init when sidecar transport is already enabled
2 changes: 1 addition & 1 deletion packages/overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function init(options: SpotlightOverlayOptions = {}) {
const finalExperiments = { ...DEFAULT_EXPERIMENTS, ...experiments };

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

const context: SpotlightContext = {
open: openSpotlight,
Expand Down
15 changes: 10 additions & 5 deletions packages/overlay/src/integrations/sentry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ function parseJSONFromBuffer(data: Uint8Array): object {
* @returns parsed envelope
*/
export function processEnvelope(rawEvent: RawEventContext) {
// Use this weird way of converting to Uint8Array as we use SSE
// which always uses utf-8 encoding but we can have envelopes with
// binary data such as screenshots or videos.
// Ideally we'd use base64 encoding for binary data but that requires
// a breaking change in the sidecar so skipping that for now.
let buffer =
typeof rawEvent.data === 'string'
? Uint8Array.from(Array.from(rawEvent.data, c => c.charCodeAt(0)))
Expand Down Expand Up @@ -243,8 +238,18 @@ function addSpotlightIntegrationToSentry(options: SentryIntegrationOptions) {
sentryClient._dsn = undefined;
// @ts-ignore
sentryClient._options.tracesSampler = () => 1;
// @ts-ignore
sentryClient._options.sampleRate = 1;

try {
// @ts-expect-error ts(2339) -- We're accessing a private property here
const existingIntegration = Object.keys(sentryClient._integrations).find(i => /spotlight/i.test(i));
if (existingIntegration) {
log(
`Skipping direct integration as there's already a Spotlight integration enabled in Sentry SDK: ${existingIntegration.name}`,
);
return;
}
const integration = spotlightIntegration();
sentryClient.addIntegration(integration);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import sentryDataCache from './data/sentryDataCache';
*/
export const spotlightIntegration = () => {
return {
name: 'SpotlightBrowser',
name: 'SpotlightBrowserDirect',
setupOnce: () => {
/* Empty function to ensure compatibility w/ JS SDK v7 >= 7.99.0 */
},
Expand Down

0 comments on commit 34e0e36

Please sign in to comment.