From 87ba9ff9bd3e2634c599e123ee2fd11c26ba5ab6 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 20 Aug 2024 17:24:33 +0200 Subject: [PATCH 1/4] feat(overlay): Allow to directly add sentry envelopes via trigger --- .changeset/blue-trees-repeat.md | 5 +++++ packages/overlay/src/integrations/sentry/index.ts | 11 +++++++++++ .../website/src/content/docs/reference/sentry.mdx | 10 +++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .changeset/blue-trees-repeat.md diff --git a/.changeset/blue-trees-repeat.md b/.changeset/blue-trees-repeat.md new file mode 100644 index 00000000..5392f7ae --- /dev/null +++ b/.changeset/blue-trees-repeat.md @@ -0,0 +1,5 @@ +--- +'@spotlightjs/overlay': minor +--- + +feat: Allow to directly add sentry envelopes via trigger diff --git a/packages/overlay/src/integrations/sentry/index.ts b/packages/overlay/src/integrations/sentry/index.ts index 69413e2c..c57a645e 100644 --- a/packages/overlay/src/integrations/sentry/index.ts +++ b/packages/overlay/src/integrations/sentry/index.ts @@ -49,8 +49,19 @@ export default function sentryIntegration(options: SentryIntegrationOptions = {} on('sentry:showError', onRenderError as EventListener); + const onAddEnvelope = (e: CustomEvent) => { + if (!e.detail.envelope) return; + processEnvelope({ + contentType: 'application/x-sentry-envelope', + data: e.detail.envelope, + }); + }; + + on('sentry:addEnvelope', onAddEnvelope as EventListener); + return () => { off('sentry:showError', onRenderError as EventListener); + off('sentry:addEnvelope', onAddEnvelope as EventListener); }; }, diff --git a/packages/website/src/content/docs/reference/sentry.mdx b/packages/website/src/content/docs/reference/sentry.mdx index 0b97f86f..cd3e9087 100644 --- a/packages/website/src/content/docs/reference/sentry.mdx +++ b/packages/website/src/content/docs/reference/sentry.mdx @@ -16,10 +16,18 @@ init({ Additionally it includes an event to trigger synchronously rendering an error: ```js -import { trigger } as Spotlight from '@spotlightjs/spotlight'; +import { trigger } from '@spotlightjs/spotlight'; trigger("sentry:showError", { eventId: string, event?: Event, }); ``` + +You can also directly add envelopes to the Sentry integration: + +```js +import { trigger } from '@spotlightjs/spotlight'; + +trigger("sentry:addEnvelope", sentryEnvelope); +``` \ No newline at end of file From 28007e399e87c9ad4135e20be9818f3bd0c28f9e Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Tue, 20 Aug 2024 20:20:07 +0100 Subject: [PATCH 2/4] Use predefined const for content type --- packages/overlay/src/integrations/sentry/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/overlay/src/integrations/sentry/index.ts b/packages/overlay/src/integrations/sentry/index.ts index c57a645e..d69c031d 100644 --- a/packages/overlay/src/integrations/sentry/index.ts +++ b/packages/overlay/src/integrations/sentry/index.ts @@ -52,7 +52,7 @@ export default function sentryIntegration(options: SentryIntegrationOptions = {} const onAddEnvelope = (e: CustomEvent) => { if (!e.detail.envelope) return; processEnvelope({ - contentType: 'application/x-sentry-envelope', + contentType: HEADER, data: e.detail.envelope, }); }; From 34b641c72531edcd4678daef3b3f0d904018f326 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 21 Aug 2024 08:53:31 +0200 Subject: [PATCH 3/4] directly pass envelope --- packages/overlay/src/integrations/sentry/index.ts | 15 ++++++++------- .../src/content/docs/reference/configuration.md | 2 +- .../website/src/content/docs/reference/sentry.mdx | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/overlay/src/integrations/sentry/index.ts b/packages/overlay/src/integrations/sentry/index.ts index d69c031d..4cafbbbf 100644 --- a/packages/overlay/src/integrations/sentry/index.ts +++ b/packages/overlay/src/integrations/sentry/index.ts @@ -41,19 +41,20 @@ export default function sentryIntegration(options: SentryIntegrationOptions = {} }); } - const onRenderError = (e: CustomEvent) => { - log('Sentry Event', e.detail.event_id); - if (!e.detail.event) return; - sentryDataCache.pushEvent(e.detail.event).then(() => open(`/errors/${e.detail.event.event_id}`)); + const onRenderError = (e: CustomEvent<{ event?: SentryEvent; event_id: string }>) => { + const { event_id, event } = e.detail; + log('Sentry Event', event_id); + if (!event) return; + sentryDataCache.pushEvent(event).then(() => open(`/errors/${event.event_id}`)); }; on('sentry:showError', onRenderError as EventListener); - const onAddEnvelope = (e: CustomEvent) => { - if (!e.detail.envelope) return; + const onAddEnvelope = (e: CustomEvent) => { + if (!e.detail) return; processEnvelope({ contentType: HEADER, - data: e.detail.envelope, + data: e.detail, }); }; diff --git a/packages/website/src/content/docs/reference/configuration.md b/packages/website/src/content/docs/reference/configuration.md index 1257a681..2e5fd196 100644 --- a/packages/website/src/content/docs/reference/configuration.md +++ b/packages/website/src/content/docs/reference/configuration.md @@ -155,7 +155,7 @@ import { trigger } from '@spotlightjs/spotlight'; trigger('sentry:showError', { event: string, - eventId: string, + event_id: string, }); ``` diff --git a/packages/website/src/content/docs/reference/sentry.mdx b/packages/website/src/content/docs/reference/sentry.mdx index cd3e9087..705a80d1 100644 --- a/packages/website/src/content/docs/reference/sentry.mdx +++ b/packages/website/src/content/docs/reference/sentry.mdx @@ -19,7 +19,7 @@ Additionally it includes an event to trigger synchronously rendering an error: import { trigger } from '@spotlightjs/spotlight'; trigger("sentry:showError", { - eventId: string, + event_id: string, event?: Event, }); ``` From b2fafeaec0a28ed634d4440cb72de2056d0a53fa Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 21 Aug 2024 09:18:21 +0200 Subject: [PATCH 4/4] fix it --- packages/overlay/src/integrations/sentry/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/overlay/src/integrations/sentry/index.ts b/packages/overlay/src/integrations/sentry/index.ts index 4cafbbbf..1c2dfbe6 100644 --- a/packages/overlay/src/integrations/sentry/index.ts +++ b/packages/overlay/src/integrations/sentry/index.ts @@ -50,7 +50,7 @@ export default function sentryIntegration(options: SentryIntegrationOptions = {} on('sentry:showError', onRenderError as EventListener); - const onAddEnvelope = (e: CustomEvent) => { + const onAddEnvelope = (e: CustomEvent) => { if (!e.detail) return; processEnvelope({ contentType: HEADER,