Skip to content

Commit

Permalink
chore: remove custom exceptions endpoint (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin authored Nov 18, 2024
1 parent d3d369b commit 75296e8
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 38 deletions.
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const EVENT_TIMERS_KEY = '__timers'
export const AUTOCAPTURE_DISABLED_SERVER_SIDE = '$autocapture_disabled_server_side'
export const HEATMAPS_ENABLED_SERVER_SIDE = '$heatmaps_enabled_server_side'
export const EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE = '$exception_capture_enabled_server_side'
export const EXCEPTION_CAPTURE_ENDPOINT_SUFFIX = '$exception_capture_endpoint_suffix'
export const WEB_VITALS_ENABLED_SERVER_SIDE = '$web_vitals_enabled_server_side'
export const DEAD_CLICKS_ENABLED_SERVER_SIDE = '$dead_clicks_enabled_server_side'
export const WEB_VITALS_ALLOWED_METRICS = '$web_vitals_allowed_metrics'
Expand Down
1 change: 0 additions & 1 deletion src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ export class PostHog {
this.experiments?.afterDecideResponse(response)
this.surveys?.afterDecideResponse(response)
this.webVitalsAutocapture?.afterDecideResponse(response)
this.exceptions?.afterDecideResponse(response)
this.exceptionObserver?.afterDecideResponse(response)
this.deadClicksAutocapture?.afterDecideResponse(response)
}
Expand Down
38 changes: 2 additions & 36 deletions src/posthog-exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
import { EXCEPTION_CAPTURE_ENDPOINT_SUFFIX } from './constants'
import { PostHog } from './posthog-core'
import { DecideResponse, Properties } from './types'
import { isObject } from './utils/type-utils'

// TODO: move this to /x/ as default
export const BASE_ERROR_ENDPOINT_SUFFIX = '/e/'
import { Properties } from './types'

export class PostHogExceptions {
private _endpointSuffix: string

constructor(private readonly instance: PostHog) {
// TODO: once BASE_ERROR_ENDPOINT_SUFFIX is no longer /e/ this can be removed
this._endpointSuffix =
this.instance.persistence?.props[EXCEPTION_CAPTURE_ENDPOINT_SUFFIX] || BASE_ERROR_ENDPOINT_SUFFIX
}

get endpoint() {
// Always respect any api_host set by the client config
return this.instance.requestRouter.endpointFor('api', this._endpointSuffix)
}

afterDecideResponse(response: DecideResponse) {
const autocaptureExceptionsResponse = response.autocaptureExceptions

this._endpointSuffix = isObject(autocaptureExceptionsResponse)
? autocaptureExceptionsResponse.endpoint || BASE_ERROR_ENDPOINT_SUFFIX
: BASE_ERROR_ENDPOINT_SUFFIX

if (this.instance.persistence) {
// 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_SUFFIX]: this._endpointSuffix,
})
}
}
constructor(private readonly instance: PostHog) {}

/**
* :TRICKY: Make sure we batch these requests
Expand All @@ -44,7 +11,6 @@ export class PostHogExceptions {
this.instance.capture('$exception', properties, {
_noTruncate: true,
_batchKey: 'exceptionEvent',
_url: this.endpoint,
})
}
}

0 comments on commit 75296e8

Please sign in to comment.