@@ -11,6 +11,8 @@ import InsightsTab from './tabs/InsightsTab';
1111import PerformanceTab from './tabs/PerformanceTab' ;
1212import type { SentryErrorEvent , SentryEvent } from './types' ;
1313
14+ import { spotlightBrowserIntegration } from '@sentry/browser' ;
15+
1416const HEADER = 'application/x-sentry-envelope' ;
1517
1618type 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 ) => {
@@ -181,6 +186,11 @@ type WindowWithSentry = Window & {
181186 __SENTRY__ ?: LegacyCarrier & VersionedCarrier ;
182187} ;
183188
189+ let sidecarConnected = false ;
190+ on ( 'sidecar:connectivity' , evt => {
191+ sidecarConnected = ( evt as CustomEvent ) . detail . connected ;
192+ } ) ;
193+
184194/**
185195 * Takes care of injecting spotlight-specific behavior into the Sentry SDK by
186196 * accessing the global __SENTRY__ carrier object.
@@ -197,7 +207,7 @@ type WindowWithSentry = Window & {
197207 *
198208 * @param options options of the Sentry integration for Spotlight
199209 */
200- function addSpotlightIntegrationToSentry ( options : SentryIntegrationOptions ) {
210+ function addSpotlightIntegrationToSentry ( options : SentryIntegrationOptions , sidecarUrl ?: string ) {
201211 if ( options . injectIntoSDK === false ) {
202212 return ;
203213 }
@@ -211,7 +221,7 @@ function addSpotlightIntegrationToSentry(options: SentryIntegrationOptions) {
211221 log ( `Will retry ${ options . retries } more time(s) at 100ms intervals...` ) ;
212222 options . retries -- ;
213223 setTimeout ( ( ) => {
214- addSpotlightIntegrationToSentry ( options ) ;
224+ addSpotlightIntegrationToSentry ( options , sidecarUrl ) ;
215225 } , 500 ) ;
216226 }
217227 return ;
@@ -247,8 +257,8 @@ function addSpotlightIntegrationToSentry(options: SentryIntegrationOptions) {
247257 ) ;
248258 return ;
249259 }
250- const integration = spotlightIntegration ( ) ;
251- sentryClient . addIntegration ( integration ) ;
260+ sentryClient . addIntegration ( spotlightIntegration ( sidecarConnected ) ) ;
261+ sentryClient . addIntegration ( spotlightBrowserIntegration ( { sidecarUrl } ) ) ;
252262 } catch ( e ) {
253263 warn ( 'Failed to add Spotlight integration to Sentry' , e ) ;
254264 log ( 'Please open an issue with the error at: https://github.com/getsentry/spotlight/issues/new/choose' ) ;
0 commit comments