-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spotlight): Add Sentry SDK so we can monitor (#620)
Fixes #510. Also allows you to debug Spotlight, with Spotlight: ![image](https://github.com/user-attachments/assets/56ca2560-1c8f-42e7-b08e-6303fd3dab6f)
- Loading branch information
Showing
17 changed files
with
1,163 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@spotlightjs/spotlight': minor | ||
--- | ||
|
||
Add Sentry SDK for monitoring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
|
||
export { React, ReactDOM }; | ||
export { React, ReactDOM, useEffect }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as Sentry from '@sentry/react'; | ||
import { createRoutesFromChildren, matchRoutes, useLocation, useNavigationType } from 'react-router-dom'; | ||
import { useEffect } from '../react-instance'; | ||
|
||
export default function initSentry(initialTab: string, options: Sentry.BrowserOptions = {}) { | ||
const sentryTraceParent: Record<string, string> = {}; | ||
const navTiming = performance.getEntriesByType('navigation'); | ||
if (navTiming.length > 0) { | ||
const serverTiming = (navTiming[0] as PerformanceNavigationTiming).serverTiming; | ||
if (serverTiming && serverTiming.length > 0) { | ||
for (const { name, description } of serverTiming) { | ||
if (name === 'sentryTrace' || name === 'baggage') { | ||
sentryTraceParent[name] = description; | ||
} | ||
} | ||
} | ||
} | ||
const hasTraceParent = Object.keys(sentryTraceParent).length === 2; | ||
const integrations = [ | ||
// See docs for support of different versions of variation of react router | ||
// https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/ | ||
Sentry.reactRouterV6BrowserTracingIntegration({ | ||
instrumentPageLoad: !hasTraceParent, | ||
useEffect, | ||
useLocation, | ||
useNavigationType, | ||
createRoutesFromChildren, | ||
matchRoutes, | ||
}), | ||
Sentry.replayIntegration(), | ||
]; | ||
const hash = document.location.hash.slice(1); | ||
if (hash.startsWith('spotlight')) { | ||
const splitterPos = hash.indexOf('='); | ||
const sidecarUrl = splitterPos > -1 ? decodeURIComponent(hash.slice(splitterPos + 1)) : undefined; | ||
integrations.push(Sentry.spotlightBrowserIntegration({ sidecarUrl })); | ||
} | ||
|
||
const sentryClient = Sentry.init({ | ||
transport: Sentry.makeBrowserOfflineTransport(Sentry.makeFetchTransport), | ||
dsn: 'https://51bcd92dba1128934afd1c5726c84442@o1.ingest.us.sentry.io/4508404727283713', | ||
environment: process.env.NODE_ENV || 'development', | ||
release: process.env.npm_package_version, | ||
|
||
integrations, | ||
|
||
tracesSampleRate: 1, | ||
tracePropagationTargets: [/^\//, document.location.origin], | ||
|
||
// Capture Replay for 1% of all sessions, | ||
// plus for 100% of sessions with an error | ||
// Learn more at | ||
// https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration | ||
replaysSessionSampleRate: 0.01, | ||
replaysOnErrorSampleRate: 1.0, | ||
...options, | ||
}); | ||
|
||
if (hasTraceParent && sentryClient) { | ||
Sentry.startBrowserTracingPageLoadSpan(sentryClient, { name: initialTab }, sentryTraceParent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.