Skip to content
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

feat(overlay): Allow to directly add sentry envelopes via trigger #498

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-trees-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spotlightjs/overlay': minor
---

feat: Allow to directly add sentry envelopes via trigger
20 changes: 16 additions & 4 deletions packages/overlay/src/integrations/sentry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,28 @@ 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 }>) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While at it I also typed this, for clarity - I think this is correct 😅 cc @BYK

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<string | Buffer>) => {
if (!e.detail) return;
processEnvelope({
contentType: HEADER,
data: e.detail,
});
};

on('sentry:addEnvelope', onAddEnvelope as EventListener);

return () => {
off('sentry:showError', onRenderError as EventListener);
off('sentry:addEnvelope', onAddEnvelope as EventListener);
};
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ import { trigger } from '@spotlightjs/spotlight';

trigger('sentry:showError', {
event: string,
eventId: string,
event_id: string,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these docs were incorrect? We use event_id in the code, as far as I can see 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, sorry :(

});
```

Expand Down
12 changes: 10 additions & 2 deletions packages/website/src/content/docs/reference/sentry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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_id: string,
event?: Event,
});
```

You can also directly add envelopes to the Sentry integration:

```js
import { trigger } from '@spotlightjs/spotlight';

trigger("sentry:addEnvelope", sentryEnvelope);
```
Loading