-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add spotlightBrowser integration #13263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Lms24
merged 14 commits into
getsentry:develop
from
BYK:byk/feat/spotlight-browser-extension
Aug 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1b83a36
feat: Add spotlightBrowser integration
81c7ba2
rename to sentryBrowserIntegration
0deb983
remove obsolete setupOnce() method
2954e41
remove obsolete lines from processEvent
fdf4eac
Merge branch 'develop' into byk/feat/spotlight-browser-extension
f88efc5
revert spotlight:true related changes
5965324
Merge branch 'develop' into byk/feat/spotlight-browser-extension
2097073
fix spotlight browser init when no DSN was set
f31f7d8
bump size limit for next.js client by 30 bytes
074dccd
Merge branch 'develop' into byk/feat/spotlight-browser-extension
cf26dad
try to fix node 14 integration tests
50fcda5
Merge branch 'develop' into byk/feat/spotlight-browser-extension
ff233c7
align SpotlightBrowser fail reset with node version
f89533f
fix logic error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 +1,2 @@ | ||
export { debugIntegration } from '@sentry/core'; | ||
export { spotlightBrowser } from '../integrations/spotlight'; |
This file contains hidden or 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,100 @@ | ||
import { getNativeImplementation } from '@sentry-internal/browser-utils'; | ||
import { defineIntegration } from '@sentry/core'; | ||
import type { Client, Envelope, Event, IntegrationFn } from '@sentry/types'; | ||
import { logger, serializeEnvelope } from '@sentry/utils'; | ||
import type { WINDOW } from '../helpers'; | ||
|
||
import { DEBUG_BUILD } from '../debug-build'; | ||
|
||
export type SpotlightConnectionOptions = { | ||
/** | ||
* Set this if the Spotlight Sidecar is not running on localhost:8969 | ||
* By default, the Url is set to http://localhost:8969/stream | ||
*/ | ||
sidecarUrl?: string; | ||
}; | ||
|
||
export const INTEGRATION_NAME = 'SpotlightBrowser'; | ||
|
||
const _spotlightIntegration = ((options: Partial<SpotlightConnectionOptions> = {}) => { | ||
const sidecarUrl = options.sidecarUrl || 'http://localhost:8969/stream'; | ||
|
||
return { | ||
name: INTEGRATION_NAME, | ||
setupOnce: () => { | ||
/* Empty function to ensure compatibility w/ JS SDK v7 >= 7.99.0 */ | ||
}, | ||
setup: () => { | ||
DEBUG_BUILD && logger.log('Using Sidecar URL', sidecarUrl); | ||
}, | ||
processEvent: event => { | ||
// We don't want to send interaction transactions/root spans created from | ||
// clicks within Spotlight to Sentry. Neither do we want them to be sent to | ||
// spotlight. | ||
if (isSpotlightInteraction(event)) { | ||
return null; | ||
} | ||
|
||
if (event.type || !event.exception || !event.exception.values) { | ||
return event; | ||
} | ||
|
||
return event; | ||
BYK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
afterAllSetup: (client: Client) => { | ||
BYK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setupSidecarForwarding(client, sidecarUrl); | ||
}, | ||
}; | ||
}) satisfies IntegrationFn; | ||
|
||
function setupSidecarForwarding(client: Client, sidecarUrl: string): void { | ||
const makeFetch: typeof WINDOW.fetch | undefined = getNativeImplementation('fetch'); | ||
let failCount = 0; | ||
|
||
client.on('beforeEnvelope', (envelope: Envelope) => { | ||
if (failCount > 3) { | ||
logger.warn('[Spotlight] Disabled Sentry -> Spotlight integration due to too many failed requests:', failCount); | ||
return; | ||
} | ||
|
||
makeFetch(sidecarUrl, { | ||
method: 'POST', | ||
body: serializeEnvelope(envelope), | ||
headers: { | ||
'Content-Type': 'application/x-sentry-envelope', | ||
}, | ||
mode: 'cors', | ||
}).then( | ||
// Reset fail count on success | ||
() => (failCount = 0), | ||
err => { | ||
failCount++; | ||
logger.error( | ||
"Sentry SDK can't connect to Sidecar is it running? See: https://spotlightjs.com/sidecar/npx/", | ||
err, | ||
); | ||
}, | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* Use this integration to send errors and transactions to Spotlight. | ||
* | ||
* Learn more about spotlight at https://spotlightjs.com | ||
*/ | ||
export const spotlightBrowser = defineIntegration(_spotlightIntegration); | ||
BYK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Flags if the event is a transaction created from an interaction with the spotlight UI. | ||
*/ | ||
export function isSpotlightInteraction(event: Event): boolean { | ||
return Boolean( | ||
event.type === 'transaction' && | ||
event.spans && | ||
event.contexts && | ||
event.contexts.trace && | ||
event.contexts.trace.op === 'ui.action.click' && | ||
event.spans.some(({ description }) => description && description.includes('#sentry-spotlight')), | ||
); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.