From 93717b80d552c8620bd7a63dbdf3dd729f89ebd0 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Sat, 30 Mar 2024 09:06:31 +0000 Subject: [PATCH 1/3] feat: display sentry levels when capturing messages --- frontend/src/lib/components/Errors/ErrorDisplay.tsx | 5 ++++- frontend/src/loadPostHogJS.tsx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/components/Errors/ErrorDisplay.tsx b/frontend/src/lib/components/Errors/ErrorDisplay.tsx index cfac9ef9d21a9..1b133f5a4f749 100644 --- a/frontend/src/lib/components/Errors/ErrorDisplay.tsx +++ b/frontend/src/lib/components/Errors/ErrorDisplay.tsx @@ -124,6 +124,7 @@ export function getExceptionPropertiesFrom(eventProperties: Record) $active_feature_flags, $sentry_url, $sentry_exception, + $level, } = eventProperties let $exception_stack_trace_raw = eventProperties.$exception_stack_trace_raw @@ -151,6 +152,7 @@ export function getExceptionPropertiesFrom(eventProperties: Record) $active_feature_flags, $sentry_url, $exception_stack_trace_raw, + $level, } } @@ -172,13 +174,14 @@ export function ErrorDisplay({ event }: { event: EventType | RecordingEventType $active_feature_flags, $sentry_url, $exception_stack_trace_raw, + $level, } = getExceptionPropertiesFrom(event.properties) return (

{$exception_message}

- {$exception_type} + {$exception_type || $level} Date: Thu, 4 Apr 2024 15:09:57 +0100 Subject: [PATCH 2/3] tset --- .../components/Errors/error-display.test.ts | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/Errors/error-display.test.ts b/frontend/src/lib/components/Errors/error-display.test.ts index b2024d1e98b62..aaffd239ed0ea 100644 --- a/frontend/src/lib/components/Errors/error-display.test.ts +++ b/frontend/src/lib/components/Errors/error-display.test.ts @@ -48,8 +48,65 @@ describe('Error Display', () => { $exception_type: 'Error', } const result = getExceptionPropertiesFrom(eventProperties) - // we don't use all the properties - expect(Object.keys(result)).toHaveLength(12) - expect(result).toMatchSnapshot() + expect(result).toEqual({ + $active_feature_flags: ['feature1,feature2'], + $browser: 'Chrome', + $browser_version: '92.0.4515', + $exception_message: 'There was an error creating the support ticket with zendesk.', + $exception_stack_trace_raw: + '[{"colno":220,"filename":"https://app-static-prod.posthog.com/static/chunk-UFQKIDIH.js","function":"submitZendeskTicket","in_app":true,"lineno":25}]', + $exception_synthetic: undefined, + $exception_type: 'Error', + $lib: 'posthog-js', + $lib_version: '1.0.0', + $level: undefined, + $os: 'Windows', + $os_version: '10', + $sentry_url: + 'https://sentry.io/organizations/posthog/issues/?project=1899813&query=40e442d79c22473391aeeeba54c82163', + }) + }) + + it('can read sentry message', () => { + const eventProperties = { + 'should not be in the': 'result', + $browser: 'Chrome', + $browser_version: '92.0.4515', + $active_feature_flags: ['feature1,feature2'], + $lib: 'posthog-js', + $lib_version: '1.0.0', + $os: 'Windows', + $os_version: '10', + $sentry_tags: { + 'PostHog Person URL': 'https://app.posthog.com/person/f6kW3HXaha6dAvHZiOmgrcAXK09682P6nNPxvfjqM9c', + 'PostHog Recording URL': 'https://app.posthog.com/replay/018dc30d-a8a5-7257-9faf-dcd97c0e19cf?t=2294', + }, + $sentry_exception: undefined, + $sentry_url: + 'https://sentry.io/organizations/posthog/issues/?project=1899813&query=40e442d79c22473391aeeeba54c82163', + $sentry_event_id: '40e442d79c22473391aeeeba54c82163', + $sentry_exception_type: undefined, + $exception_personURL: 'https://app.posthog.com/person/f6kW3HXaha6dAvHZiOmgrcAXK09682P6nNPxvfjqM9c', + $exception_type: undefined, + $level: 'info', + $exception_message: 'the message sent into sentry captureMessage', + } + const result = getExceptionPropertiesFrom(eventProperties) + expect(result).toEqual({ + $active_feature_flags: ['feature1,feature2'], + $browser: 'Chrome', + $browser_version: '92.0.4515', + $exception_message: 'the message sent into sentry captureMessage', + $exception_stack_trace_raw: undefined, + $exception_synthetic: undefined, + $exception_type: undefined, + $lib: 'posthog-js', + $lib_version: '1.0.0', + $level: 'info', + $os: 'Windows', + $os_version: '10', + $sentry_url: + 'https://sentry.io/organizations/posthog/issues/?project=1899813&query=40e442d79c22473391aeeeba54c82163', + }) }) }) From b76a45e71ca4e913878ecba757ccbd3e2367b0ef Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Thu, 4 Apr 2024 15:10:13 +0100 Subject: [PATCH 3/3] delete dangling snapshot --- .../__snapshots__/error-display.test.ts.snap | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 frontend/src/lib/components/Errors/__snapshots__/error-display.test.ts.snap diff --git a/frontend/src/lib/components/Errors/__snapshots__/error-display.test.ts.snap b/frontend/src/lib/components/Errors/__snapshots__/error-display.test.ts.snap deleted file mode 100644 index 29adf34a5c83c..0000000000000 --- a/frontend/src/lib/components/Errors/__snapshots__/error-display.test.ts.snap +++ /dev/null @@ -1,20 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Error Display can read sentry stack trace when $exception_stack_trace_raw is not present 1`] = ` -{ - "$active_feature_flags": [ - "feature1,feature2", - ], - "$browser": "Chrome", - "$browser_version": "92.0.4515", - "$exception_message": "There was an error creating the support ticket with zendesk.", - "$exception_stack_trace_raw": "[{"colno":220,"filename":"https://app-static-prod.posthog.com/static/chunk-UFQKIDIH.js","function":"submitZendeskTicket","in_app":true,"lineno":25}]", - "$exception_synthetic": undefined, - "$exception_type": "Error", - "$lib": "posthog-js", - "$lib_version": "1.0.0", - "$os": "Windows", - "$os_version": "10", - "$sentry_url": "https://sentry.io/organizations/posthog/issues/?project=1899813&query=40e442d79c22473391aeeeba54c82163", -} -`;