Skip to content

Commit

Permalink
fix(sentry): Reverse stack traces of incoming Sentry error events (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 authored Nov 17, 2023
1 parent e027452 commit 60e3495
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-poets-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spotlightjs/core': patch
---

fix(sentry): Reverse stack traces of error events
15 changes: 11 additions & 4 deletions packages/core/src/integrations/sentry/components/Events/Error.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SentryErrorEvent } from '../../types';
import { EventException, EventExceptionValue, SentryErrorEvent } from '../../types';
import Frame from './Error/Frame';

export function ErrorTitle({ event }: { event: SentryErrorEvent }) {
const values = 'values' in event.exception ? event.exception.values : [event.exception.value];
const values = arraifyValues(event.exception);

return (
<>
Expand All @@ -12,7 +12,7 @@ export function ErrorTitle({ event }: { event: SentryErrorEvent }) {
}

export function ErrorSummary({ event }: { event: SentryErrorEvent }) {
const values = 'values' in event.exception ? event.exception.values : [event.exception.value];
const values = arraifyValues(event.exception);

return (
<div className="space-y-4 font-mono">
Expand All @@ -25,7 +25,7 @@ export function ErrorSummary({ event }: { event: SentryErrorEvent }) {
}

export default function Error({ event }: { event: SentryErrorEvent }) {
const values = 'values' in event.exception ? event.exception.values : [event.exception.value];
const values = arraifyValues(event.exception);

return (
<>
Expand All @@ -49,3 +49,10 @@ export default function Error({ event }: { event: SentryErrorEvent }) {
</>
);
}

function arraifyValues(exception: EventException): EventExceptionValue[] {
if (exception.value) {
return [exception.value];
}
return exception.values;
}
29 changes: 27 additions & 2 deletions packages/core/src/integrations/sentry/data/sentryDataCache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Envelope } from '@sentry/types';
import { generate_uuidv4 } from '~/lib/uuid';
import { Sdk, SentryEvent, SentryTransactionEvent, Span, Trace } from '../types';
import { Sdk, SentryErrorEvent, SentryEvent, SentryTransactionEvent, Span, Trace } from '../types';
import { groupSpans } from '../utils/traces';

function toTimestamp(date: string | number) {
Expand Down Expand Up @@ -56,7 +56,15 @@ class SentryDataCache {
event_id?: string;
},
) {
if (!event.event_id) event.event_id = generate_uuidv4();
if (!event.event_id) {
event.event_id = generate_uuidv4();
}

console.log('DDDD', event);
if (isErrorEvent(event)) {
console.log('AAAA');
reverseStackTraces(event);
}

event.timestamp = toTimestamp(event.timestamp);
if (event.start_timestamp) event.start_timestamp = toTimestamp(event.start_timestamp);
Expand Down Expand Up @@ -170,3 +178,20 @@ class SentryDataCache {
}

export default new SentryDataCache();

function isErrorEvent(event: SentryEvent): event is SentryErrorEvent {
return !event.type;
}

function reverseStackTraces(errorEvent: SentryErrorEvent): void {
if (!errorEvent.exception || !errorEvent.exception.values) {
console.log('CCC', errorEvent);
return;
}
errorEvent.exception.values.forEach(value => {
if (value.stacktrace) {
value.stacktrace.frames.reverse();
}
});
console.log('BBB', errorEvent.exception.values);
}
2 changes: 2 additions & 0 deletions packages/core/src/integrations/sentry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export type EventExceptionValue = {
export type EventException =
| {
values: EventExceptionValue[];
value: undefined;
}
| {
values: undefined;
value: EventExceptionValue;
};

Expand Down

0 comments on commit 60e3495

Please sign in to comment.