20
20
* @param {Number } [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry
21
21
* @param {string } [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)
22
22
* @param {SeverityLevel[] | '*' } [severityAllowList] Optional: send events matching the provided levels. Use '*' to send all events (default: ['error'])
23
+ * @param {boolean } [sendExceptionsToPostHog] Optional: capture exceptions as events in PostHog (default: true)
23
24
*/
24
25
25
26
import { SeverityLevel } from './error-tracking/types'
@@ -70,13 +71,20 @@ export type SentryIntegrationOptions = {
70
71
projectId ?: number
71
72
prefix ?: string
72
73
severityAllowList ?: SeverityLevel [ ] | '*'
74
+ sendExceptionsToPostHog ?: boolean
73
75
}
74
76
75
77
const NAME = 'posthog-node'
76
78
77
79
export function createEventProcessor (
78
80
_posthog : PostHogBackendClient ,
79
- { organization, projectId, prefix, severityAllowList = [ 'error' ] } : SentryIntegrationOptions = { }
81
+ {
82
+ organization,
83
+ projectId,
84
+ prefix,
85
+ severityAllowList = [ 'error' ] ,
86
+ sendExceptionsToPostHog = true ,
87
+ } : SentryIntegrationOptions = { }
80
88
) : ( event : _SentryEvent ) => _SentryEvent {
81
89
return ( event ) => {
82
90
const shouldProcessLevel = severityAllowList === '*' || severityAllowList . includes ( event . level )
@@ -147,7 +155,9 @@ export function createEventProcessor(
147
155
event . event_id
148
156
}
149
157
150
- _posthog . capture ( { event : '$exception' , distinctId : userId , properties } )
158
+ if ( sendExceptionsToPostHog ) {
159
+ _posthog . capture ( { event : '$exception' , distinctId : userId , properties } )
160
+ }
151
161
152
162
return event
153
163
}
@@ -182,7 +192,8 @@ export class PostHogSentryIntegration implements _SentryIntegrationClass {
182
192
_posthog : PostHogBackendClient ,
183
193
organization ?: string ,
184
194
prefix ?: string ,
185
- severityAllowList ?: SeverityLevel [ ] | '*'
195
+ severityAllowList ?: SeverityLevel [ ] | '*' ,
196
+ sendExceptionsToPostHog ?: boolean
186
197
) {
187
198
// setupOnce gets called by Sentry when it intializes the plugin
188
199
this . name = NAME
@@ -197,6 +208,7 @@ export class PostHogSentryIntegration implements _SentryIntegrationClass {
197
208
projectId,
198
209
prefix,
199
210
severityAllowList,
211
+ sendExceptionsToPostHog : sendExceptionsToPostHog ?? true ,
200
212
} )
201
213
)
202
214
}
0 commit comments