diff --git a/.changeset/funny-poets-check.md b/.changeset/funny-poets-check.md
new file mode 100644
index 00000000..1170c861
--- /dev/null
+++ b/.changeset/funny-poets-check.md
@@ -0,0 +1,5 @@
+---
+'@spotlightjs/core': patch
+---
+
+fix(sentry): Reverse stack traces of error events
diff --git a/packages/core/src/integrations/sentry/components/Events/Error.tsx b/packages/core/src/integrations/sentry/components/Events/Error.tsx
index 9521c572..c85408e0 100644
--- a/packages/core/src/integrations/sentry/components/Events/Error.tsx
+++ b/packages/core/src/integrations/sentry/components/Events/Error.tsx
@@ -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 (
<>
@@ -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 (
@@ -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 (
<>
@@ -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;
+}
diff --git a/packages/core/src/integrations/sentry/data/sentryDataCache.ts b/packages/core/src/integrations/sentry/data/sentryDataCache.ts
index 5754fbfd..547125c3 100644
--- a/packages/core/src/integrations/sentry/data/sentryDataCache.ts
+++ b/packages/core/src/integrations/sentry/data/sentryDataCache.ts
@@ -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) {
@@ -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);
@@ -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);
+}
diff --git a/packages/core/src/integrations/sentry/types.ts b/packages/core/src/integrations/sentry/types.ts
index 2e34a857..d17702d8 100644
--- a/packages/core/src/integrations/sentry/types.ts
+++ b/packages/core/src/integrations/sentry/types.ts
@@ -29,8 +29,10 @@ export type EventExceptionValue = {
export type EventException =
| {
values: EventExceptionValue[];
+ value: undefined;
}
| {
+ values: undefined;
value: EventExceptionValue;
};