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: send errors one way #1289

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 15 additions & 6 deletions src/extensions/exception-autocapture/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE, EXCEPTION_CAPTURE_ENDPOINT } fro
import Config from '../../config'

// TODO: move this to /x/ as default
const BASE_ENDPOINT = '/e/'
export const BASE_ERROR_ENDPOINT = '/e/'
const LOGGER_PREFIX = '[Exception Capture]'

export class ExceptionObserver {
private _endpoint: string = BASE_ENDPOINT
private _endpoint: string
instance: PostHog
remoteEnabled: boolean | undefined
private originalOnUnhandledRejectionHandler: Window['onunhandledrejection'] | null | undefined = undefined
Expand All @@ -22,9 +22,17 @@ export class ExceptionObserver {
constructor(instance: PostHog) {
this.instance = instance
this.remoteEnabled = !!this.instance.persistence?.props[EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE]

// TODO: once BASE_ERROR_ENDPOINT is no longer /e/ this can be removed
this._endpoint = this.instance.persistence?.props[EXCEPTION_CAPTURE_ENDPOINT] || BASE_ERROR_ENDPOINT

this.startIfEnabled()
}

get endpoint() {
return this._endpoint
}

get isEnabled() {
return this.remoteEnabled ?? false
}
Expand Down Expand Up @@ -97,14 +105,15 @@ export class ExceptionObserver {
// store this in-memory in case persistence is disabled
this.remoteEnabled = !!autocaptureExceptionsResponse || false
this._endpoint = isObject(autocaptureExceptionsResponse)
? autocaptureExceptionsResponse.endpoint || BASE_ENDPOINT
: BASE_ENDPOINT
? autocaptureExceptionsResponse.endpoint || BASE_ERROR_ENDPOINT
: BASE_ERROR_ENDPOINT

if (this.instance.persistence) {
this.instance.persistence.register({
[EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE]: this.remoteEnabled,
})
// when we come to moving the endpoint to not /e/ we'll want that to persist between startup and decide response
// when we come to moving the endpoint to not /e/
// we'll want that to persist between startup and decide response
// TODO: once BASE_ENDPOINT is no longer /e/ this can be removed
this.instance.persistence.register({
[EXCEPTION_CAPTURE_ENDPOINT]: this._endpoint,
Expand Down Expand Up @@ -132,7 +141,7 @@ export class ExceptionObserver {
_noTruncate: true,
_batchKey: 'exceptionEvent',
_noHeatmaps: true,
_url: this._endpoint,
_url: this.endpoint,
})
}
}
8 changes: 7 additions & 1 deletion src/extensions/sentry-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import { PostHog } from '../posthog-core'
import { SeverityLevel } from '../types'
import { BASE_ERROR_ENDPOINT } from './exception-autocapture'

// NOTE - we can't import from @sentry/types because it changes frequently and causes clashes
// We only use a small subset of the types, so we can just define the integration overall and use any for the rest
Expand Down Expand Up @@ -124,7 +125,12 @@ export function createEventProcessor(
'&query=' +
event.event_id
}
_posthog.capture('$exception', data)

// we take the URL from the exception observer
// so that when we add error specific URL for ingestion
// these errors are sent there too
_posthog.capture('$exception', data, { _url: _posthog.exceptionObserver?.endpoint || BASE_ERROR_ENDPOINT })

return event
}
}
Expand Down
Loading