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

chore: remove custom exceptions endpoint #1513

Merged
merged 2 commits into from
Nov 18, 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
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 @@ -564,7 +564,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,
})
}
}
Loading