posthog-js 1.167.1 → 1.168.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/all-external-dependencies.js +2 -2
- package/dist/all-external-dependencies.js.map +1 -1
- package/dist/array.full.js +2 -2
- package/dist/array.full.js.map +1 -1
- package/dist/array.full.no-external.js +2 -2
- package/dist/array.full.no-external.js.map +1 -1
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/array.no-external.js +1 -1
- package/dist/array.no-external.js.map +1 -1
- package/dist/exception-autocapture.js +1 -1
- package/dist/exception-autocapture.js.map +1 -1
- package/dist/external-scripts-loader.js.map +1 -1
- package/dist/lib/src/extensions/exception-autocapture/error-conversion.d.ts +36 -2
- package/dist/lib/src/types.d.ts +8 -17
- package/dist/lib/src/utils/globals.d.ts +3 -2
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +9 -18
- package/dist/module.full.d.ts +9 -18
- package/dist/module.full.js +2 -2
- package/dist/module.full.js.map +1 -1
- package/dist/module.full.no-external.d.ts +9 -18
- package/dist/module.full.no-external.js +2 -2
- package/dist/module.full.no-external.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +9 -18
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/recorder-v2.js.map +1 -1
- package/dist/recorder.js.map +1 -1
- package/dist/surveys-preview.js.map +1 -1
- package/dist/surveys.js.map +1 -1
- package/dist/tracing-headers.js.map +1 -1
- package/dist/web-vitals.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/src/extensions/exception-autocapture/error-conversion.d.ts +36 -2
- package/lib/src/extensions/exception-autocapture/error-conversion.js +104 -65
- package/lib/src/extensions/exception-autocapture/error-conversion.js.map +1 -1
- package/lib/src/extensions/sentry-integration.js +1 -0
- package/lib/src/extensions/sentry-integration.js.map +1 -1
- package/lib/src/posthog-core.js +10 -1
- package/lib/src/posthog-core.js.map +1 -1
- package/lib/src/types.d.ts +8 -17
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/globals.d.ts +3 -2
- package/lib/src/utils/globals.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-conversion.js","sourceRoot":"","sources":["../../../../src/extensions/exception-autocapture/error-conversion.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACH,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,WAAW,GACd,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,kBAAkB,EAAc,MAAM,eAAe,CAAA;AAE9D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACvF,OAAO,EAAkD,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5F;;GAEG;AAEH,IAAM,mBAAmB,GACrB,0GAA0G,CAAA;AAE9G,IAAM,mBAAmB,GAAG,6BAA6B,CAAA;AAEzD,SAAS,UAAU,CAAC,EAAoC;IACpD,IAAI,EAAE,EAAE,CAAC;QACL,IAAI,QAAQ,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3B,OAAO,EAAE,CAAC,WAAW,CAAA;QACzB,CAAC;QAED,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,OAAO,CAAC,CAAA;QACZ,CAAC;IACL,CAAC;IAED,OAAO,CAAC,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAyD;IACtF,iEAAiE;IACjE,4DAA4D;IAC5D,mCAAmC;IACnC,IAAM,UAAU,GAAG,EAAE,CAAC,UAAU,IAAI,EAAE,CAAC,KAAK,IAAI,EAAE,CAAA;IAElD,IAAM,OAAO,GA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C,CAAC,CAAC,OAAO,IAChB;AACL,CAAC","sourcesContent":["import {\n isDOMError,\n isDOMException,\n isError,\n isErrorEvent,\n isErrorWithStack,\n isEvent,\n isPlainObject,\n isPrimitive,\n} from './type-checking'\nimport { defaultStackParser, StackFrame } from './stack-trace'\n\nimport { isEmptyString, isNumber, isString, isUndefined } from '../../utils/type-utils'\nimport { ErrorEventArgs, ErrorProperties, SeverityLevel, severityLevels } from '../../types'\n\n/**\n * based on the very wonderful MIT licensed Sentry SDK\n */\n\nconst ERROR_TYPES_PATTERN =\n /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i\n\nconst reactMinifiedRegexp = /Minified React error #\\d+;/i\n\nfunction getPopSize(ex: Error & { framesToPop?: number }): number {\n if (ex) {\n if (isNumber(ex.framesToPop)) {\n return ex.framesToPop\n }\n\n if (reactMinifiedRegexp.test(ex.message)) {\n return 1\n }\n }\n\n return 0\n}\n\nexport function parseStackFrames(ex: Error & { framesToPop?: number; stacktrace?: string }): StackFrame[] {\n // Access and store the stacktrace property before doing ANYTHING\n // else to it because Opera is not very good at providing it\n // reliably in other circumstances.\n const stacktrace = ex.stacktrace || ex.stack || ''\n\n const popSize = getPopSize(ex)\n\n try {\n return defaultStackParser(stacktrace, popSize)\n } catch {\n // no-empty\n }\n\n return []\n}\n\nfunction errorPropertiesFromError(error: Error): ErrorProperties {\n const frames = parseStackFrames(error)\n\n return {\n $exception_type: error.name,\n $exception_message: error.message,\n $exception_stack_trace_raw: JSON.stringify(frames),\n $exception_level: 'error',\n }\n}\n\nfunction errorPropertiesFromString(candidate: string): ErrorProperties {\n return {\n $exception_type: 'Error',\n $exception_message: candidate,\n $exception_level: 'error',\n }\n}\n\n/**\n * Given any captured exception, extract its keys and create a sorted\n * and truncated list that will be used inside the event message.\n * eg. `Non-error exception captured with keys: foo, bar, baz`\n */\nfunction extractExceptionKeysForMessage(exception: Record<string, unknown>, maxLength = 40): string {\n const keys = Object.keys(exception)\n keys.sort()\n\n if (!keys.length) {\n return '[object has no keys]'\n }\n\n for (let i = keys.length; i > 0; i--) {\n const serialized = keys.slice(0, i).join(', ')\n if (serialized.length > maxLength) {\n continue\n }\n if (i === keys.length) {\n return serialized\n }\n return serialized.length <= maxLength ? serialized : `${serialized.slice(0, maxLength)}...`\n }\n\n return ''\n}\n\nfunction isSeverityLevel(x: unknown): x is SeverityLevel {\n return isString(x) && !isEmptyString(x) && severityLevels.indexOf(x as SeverityLevel) >= 0\n}\n\nfunction errorPropertiesFromObject(candidate: Record<string, unknown>): ErrorProperties {\n return {\n $exception_type: isEvent(candidate) ? candidate.constructor.name : 'Error',\n $exception_message: `Non-Error ${'exception'} captured with keys: ${extractExceptionKeysForMessage(candidate)}`,\n $exception_level: isSeverityLevel(candidate.level) ? candidate.level : 'error',\n }\n}\n\nexport function errorToProperties([event, source, lineno, colno, error]: ErrorEventArgs): ErrorProperties {\n // some properties are not optional but, it's useful to start off without them enforced\n let errorProperties: Omit<ErrorProperties, '$exception_type' | '$exception_message' | '$exception_level'> & {\n $exception_type?: string\n $exception_message?: string\n $exception_level?: string\n } = {}\n\n if (isUndefined(error) && isString(event)) {\n let name = 'Error'\n let message = event\n const groups = event.match(ERROR_TYPES_PATTERN)\n if (groups) {\n name = groups[1]\n message = groups[2]\n }\n errorProperties = {\n $exception_type: name,\n $exception_message: message,\n }\n }\n\n const candidate = error || event\n\n if (isDOMError(candidate) || isDOMException(candidate)) {\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMError\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n\n const domException = candidate as unknown as DOMException\n\n if (isErrorWithStack(candidate)) {\n errorProperties = errorPropertiesFromError(candidate as Error)\n } else {\n const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException')\n const message = domException.message ? `${name}: ${domException.message}` : name\n errorProperties = errorPropertiesFromString(message)\n errorProperties.$exception_type = isDOMError(domException) ? 'DOMError' : 'DOMException'\n errorProperties.$exception_message = errorProperties.$exception_message || message\n }\n if ('code' in domException) {\n errorProperties['$exception_DOMException_code'] = `${domException.code}`\n }\n } else if (isErrorEvent(candidate as ErrorEvent) && (candidate as ErrorEvent).error) {\n errorProperties = errorPropertiesFromError((candidate as ErrorEvent).error as Error)\n } else if (isError(candidate)) {\n errorProperties = errorPropertiesFromError(candidate)\n } else if (isPlainObject(candidate) || isEvent(candidate)) {\n // group these by using the keys available on the object\n const objectException = candidate as Record<string, unknown>\n errorProperties = errorPropertiesFromObject(objectException)\n errorProperties.$exception_is_synthetic = true\n } else {\n // If none of previous checks were valid, then it must be a string\n errorProperties.$exception_type = errorProperties.$exception_type || 'Error'\n errorProperties.$exception_message = errorProperties.$exception_message || candidate\n errorProperties.$exception_is_synthetic = true\n }\n\n return {\n ...errorProperties,\n // now we make sure the mandatory fields that were made optional are present\n $exception_type: errorProperties.$exception_type || 'UnknownErrorType',\n $exception_message: errorProperties.$exception_message || '',\n $exception_level: isSeverityLevel(errorProperties.$exception_level)\n ? errorProperties.$exception_level\n : 'error',\n ...(source\n ? {\n $exception_source: source, // TODO get this from URL if not present\n }\n : {}),\n ...(lineno ? { $exception_lineno: lineno } : {}),\n ...(colno ? { $exception_colno: colno } : {}),\n }\n}\n\nexport function unhandledRejectionToProperties([ev]: [ev: PromiseRejectionEvent]): ErrorProperties {\n // dig the object of the rejection out of known event types\n let error: unknown = ev\n try {\n // PromiseRejectionEvents store the object of the rejection under 'reason'\n // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent\n if ('reason' in ev) {\n error = ev.reason\n }\n // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents\n // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into\n // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec\n // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and\n // https://github.com/getsentry/sentry-javascript/issues/2380\n else if ('detail' in ev && 'reason' in (ev as any).detail) {\n error = (ev as any).detail.reason\n }\n } catch {\n // no-empty\n }\n\n // some properties are not optional but, it's useful to start off without them enforced\n let errorProperties: Omit<ErrorProperties, '$exception_type' | '$exception_message' | '$exception_level'> & {\n $exception_type?: string\n $exception_message?: string\n $exception_level?: string\n } = {}\n if (isPrimitive(error)) {\n errorProperties = {\n $exception_message: `Non-Error promise rejection captured with value: ${String(error)}`,\n }\n } else {\n errorProperties = errorToProperties([error as string | Event])\n }\n errorProperties.$exception_handled = false\n\n return {\n ...errorProperties,\n // now we make sure the mandatory fields that were made optional are present\n $exception_type: (errorProperties.$exception_type = 'UnhandledRejection'),\n $exception_message: (errorProperties.$exception_message =\n errorProperties.$exception_message || (ev as any).reason || String(error)),\n $exception_level: isSeverityLevel(errorProperties.$exception_level)\n ? errorProperties.$exception_level\n : 'error',\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"error-conversion.js","sourceRoot":"","sources":["../../../../src/extensions/exception-autocapture/error-conversion.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACH,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,WAAW,GACd,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,kBAAkB,EAAc,MAAM,eAAe,CAAA;AAE9D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACvF,OAAO,EAAgD,cAAc,EAAE,MAAM,aAAa,CAAA;AAuC1F;;GAEG;AAEH,IAAM,mBAAmB,GACrB,0GAA0G,CAAA;AAE9G,IAAM,mBAAmB,GAAG,6BAA6B,CAAA;AAEzD,SAAS,UAAU,CAAC,EAAoC;IACpD,IAAI,EAAE,EAAE,CAAC;QACL,IAAI,QAAQ,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;YAC3B,OAAO,EAAE,CAAC,WAAW,CAAA;QACzB,CAAC;QAED,IAAI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SAC9C,CAAC,CAAA;IACN,CAAC;SAAM,CAAC;QACJ,OAAO,iBAAiB,CAAC,CAAC,KAAuB,CAAC,EAAE;YAChD,OAAO,EAAE,KAAK;YACd,qBAAqB,EAAE,oBAAoB;YAC3C,uBAAuB,EAAG,EAAU,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC;SAC/D,CAAC,CAAA;IACN,CAAC;AACL,CAAC","sourcesContent":["import {\n isDOMError,\n isDOMException,\n isError,\n isErrorEvent,\n isErrorWithStack,\n isEvent,\n isPlainObject,\n isPrimitive,\n} from './type-checking'\nimport { defaultStackParser, StackFrame } from './stack-trace'\n\nimport { isEmptyString, isNumber, isString, isUndefined } from '../../utils/type-utils'\nimport { ErrorEventArgs, ErrorMetadata, SeverityLevel, severityLevels } from '../../types'\n\nexport interface ErrorProperties {\n $exception_list: Exception[]\n $exception_level?: SeverityLevel\n $exception_DOMException_code?: string\n $exception_personURL?: string\n}\n\nexport interface Exception {\n type?: string\n value?: string\n mechanism?: {\n /**\n * In theory, whether or not the exception has been handled by the user. In practice, whether or not we see it before\n * it hits the global error/rejection handlers, whether through explicit handling by the user or auto instrumentation.\n */\n handled?: boolean\n type?: string\n source?: string\n /**\n * True when `captureException` is called with anything other than an instance of `Error` (or, in the case of browser,\n * an instance of `ErrorEvent`, `DOMError`, or `DOMException`). causing us to create a synthetic error in an attempt\n * to recreate the stacktrace.\n */\n synthetic?: boolean\n }\n module?: string\n thread_id?: number\n stacktrace?: {\n frames?: StackFrame[]\n }\n}\n\nexport interface ErrorConversions {\n errorToProperties: (args: ErrorEventArgs, metadata?: ErrorMetadata) => ErrorProperties\n unhandledRejectionToProperties: (args: [ev: PromiseRejectionEvent]) => ErrorProperties\n}\n\n/**\n * based on the very wonderful MIT licensed Sentry SDK\n */\n\nconst ERROR_TYPES_PATTERN =\n /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i\n\nconst reactMinifiedRegexp = /Minified React error #\\d+;/i\n\nfunction getPopSize(ex: Error & { framesToPop?: number }): number {\n if (ex) {\n if (isNumber(ex.framesToPop)) {\n return ex.framesToPop\n }\n\n if (reactMinifiedRegexp.test(ex.message)) {\n return 1\n }\n }\n\n return 0\n}\n\nexport function parseStackFrames(ex: Error & { framesToPop?: number; stacktrace?: string }): StackFrame[] {\n // Access and store the stacktrace property before doing ANYTHING\n // else to it because Opera is not very good at providing it\n // reliably in other circumstances.\n const stacktrace = ex.stacktrace || ex.stack || ''\n\n const popSize = getPopSize(ex)\n\n try {\n return defaultStackParser(stacktrace, popSize)\n } catch {\n // no-empty\n }\n\n return []\n}\n\nfunction errorPropertiesFromError(error: Error, metadata?: ErrorMetadata): ErrorProperties {\n const frames = parseStackFrames(error)\n\n const handled = metadata?.handled ?? true\n const synthetic = metadata?.synthetic ?? false\n\n const exceptionType = metadata?.overrideExceptionType ? metadata.overrideExceptionType : error.name\n const exceptionMessage = metadata?.overrideExceptionMessage ? metadata.overrideExceptionMessage : error.message\n\n return {\n $exception_list: [\n {\n type: exceptionType,\n value: exceptionMessage,\n stacktrace: {\n frames,\n },\n mechanism: {\n handled,\n synthetic,\n },\n },\n ],\n $exception_level: 'error',\n }\n}\n\nfunction errorPropertiesFromString(candidate: string, metadata?: ErrorMetadata): ErrorProperties {\n // Defaults for metadata are based on what the error candidate is.\n const handled = metadata?.handled ?? true\n const synthetic = metadata?.synthetic ?? true\n\n const exceptionType = metadata?.overrideExceptionType\n ? metadata.overrideExceptionType\n : metadata?.defaultExceptionType ?? 'Error'\n const exceptionMessage = metadata?.overrideExceptionMessage\n ? metadata.overrideExceptionMessage\n : candidate\n ? candidate\n : metadata?.defaultExceptionMessage\n\n return {\n $exception_list: [\n {\n type: exceptionType,\n value: exceptionMessage,\n mechanism: {\n handled,\n synthetic,\n },\n },\n ],\n $exception_level: 'error',\n }\n}\n\n/**\n * Given any captured exception, extract its keys and create a sorted\n * and truncated list that will be used inside the event message.\n * eg. `Non-error exception captured with keys: foo, bar, baz`\n */\nfunction extractExceptionKeysForMessage(exception: Record<string, unknown>, maxLength = 40): string {\n const keys = Object.keys(exception)\n keys.sort()\n\n if (!keys.length) {\n return '[object has no keys]'\n }\n\n for (let i = keys.length; i > 0; i--) {\n const serialized = keys.slice(0, i).join(', ')\n if (serialized.length > maxLength) {\n continue\n }\n if (i === keys.length) {\n return serialized\n }\n return serialized.length <= maxLength ? serialized : `${serialized.slice(0, maxLength)}...`\n }\n\n return ''\n}\n\nfunction isSeverityLevel(x: unknown): x is SeverityLevel {\n return isString(x) && !isEmptyString(x) && severityLevels.indexOf(x as SeverityLevel) >= 0\n}\n\nfunction errorPropertiesFromObject(candidate: Record<string, unknown>, metadata?: ErrorMetadata): ErrorProperties {\n // Defaults for metadata are based on what the error candidate is.\n const handled = metadata?.handled ?? true\n const synthetic = metadata?.synthetic ?? true\n\n const exceptionType = metadata?.overrideExceptionType\n ? metadata.overrideExceptionType\n : isEvent(candidate)\n ? candidate.constructor.name\n : 'Error'\n const exceptionMessage = metadata?.overrideExceptionMessage\n ? metadata.overrideExceptionMessage\n : `Non-Error ${'exception'} captured with keys: ${extractExceptionKeysForMessage(candidate)}`\n\n return {\n $exception_list: [\n {\n type: exceptionType,\n value: exceptionMessage,\n mechanism: {\n handled,\n synthetic,\n },\n },\n ],\n $exception_level: isSeverityLevel(candidate.level) ? candidate.level : 'error',\n }\n}\n\nexport function errorToProperties(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n [event, _, __, ___, error]: ErrorEventArgs,\n metadata?: ErrorMetadata\n): ErrorProperties {\n let errorProperties: ErrorProperties = { $exception_list: [] }\n\n const candidate = error || event\n\n if (isDOMError(candidate) || isDOMException(candidate)) {\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMError\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n\n const domException = candidate as unknown as DOMException\n\n if (isErrorWithStack(candidate)) {\n errorProperties = errorPropertiesFromError(candidate as Error, metadata)\n } else {\n const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException')\n const message = domException.message ? `${name}: ${domException.message}` : name\n const exceptionType = isDOMError(domException) ? 'DOMError' : 'DOMException'\n errorProperties = errorPropertiesFromString(message, {\n ...metadata,\n overrideExceptionType: exceptionType,\n defaultExceptionMessage: message,\n })\n }\n if ('code' in domException) {\n errorProperties['$exception_DOMException_code'] = `${domException.code}`\n }\n return errorProperties\n } else if (isErrorEvent(candidate as ErrorEvent) && (candidate as ErrorEvent).error) {\n return errorPropertiesFromError((candidate as ErrorEvent).error as Error, metadata)\n } else if (isError(candidate)) {\n return errorPropertiesFromError(candidate, metadata)\n } else if (isPlainObject(candidate) || isEvent(candidate)) {\n // group these by using the keys available on the object\n const objectException = candidate as Record<string, unknown>\n return errorPropertiesFromObject(objectException)\n } else if (isUndefined(error) && isString(event)) {\n let name = 'Error'\n let message = event\n const groups = event.match(ERROR_TYPES_PATTERN)\n if (groups) {\n name = groups[1]\n message = groups[2]\n }\n\n return errorPropertiesFromString(message, {\n ...metadata,\n overrideExceptionType: name,\n defaultExceptionMessage: message,\n })\n } else {\n return errorPropertiesFromString(candidate as string, metadata)\n }\n}\n\nexport function unhandledRejectionToProperties([ev]: [ev: PromiseRejectionEvent]): ErrorProperties {\n // dig the object of the rejection out of known event types\n let error: unknown = ev\n try {\n // PromiseRejectionEvents store the object of the rejection under 'reason'\n // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent\n if ('reason' in ev) {\n error = ev.reason\n }\n // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents\n // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into\n // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec\n // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and\n // https://github.com/getsentry/sentry-javascript/issues/2380\n else if ('detail' in ev && 'reason' in (ev as any).detail) {\n error = (ev as any).detail.reason\n }\n } catch {\n // no-empty\n }\n\n if (isPrimitive(error)) {\n return errorPropertiesFromString(`Non-Error promise rejection captured with value: ${String(error)}`, {\n handled: false,\n synthetic: false,\n overrideExceptionType: 'UnhandledRejection',\n })\n } else {\n return errorToProperties([error as string | Event], {\n handled: false,\n overrideExceptionType: 'UnhandledRejection',\n defaultExceptionMessage: (ev as any).reason || String(error),\n })\n }\n}\n"]}
|
|
@@ -37,6 +37,7 @@ export function createEventProcessor(_posthog, _a) {
|
|
|
37
37
|
$exception_type: (_c = exceptions[0]) === null || _c === void 0 ? void 0 : _c.type,
|
|
38
38
|
$exception_personURL: personUrl,
|
|
39
39
|
$exception_level: event.level,
|
|
40
|
+
$exception_list: exceptions,
|
|
40
41
|
// Sentry Exception Properties
|
|
41
42
|
$sentry_event_id: event.event_id,
|
|
42
43
|
$sentry_exception: event.exception,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry-integration.js","sourceRoot":"","sources":["../../../src/extensions/sentry-integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAwDH,IAAM,IAAI,GAAG,YAAY,CAAA;AAEzB,MAAM,UAAU,oBAAoB,CAChC,QAAiB,EACjB,EAAiG;QAAjG,qBAA+F,EAAE,KAAA,EAA/F,YAAY,kBAAA,EAAE,SAAS,eAAA,EAAE,MAAM,YAAA,EAAE,yBAA6B,EAA7B,iBAAiB,mBAAG,CAAC,OAAO,CAAC,KAAA;IAEhE,OAAO,UAAC,KAAK;;QACT,IAAM,kBAAkB,GAAG,iBAAiB,KAAK,GAAG,IAAI,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAsB,CAAC,CAAA;QAChH,IAAI,CAAC,kBAAkB,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAA;QAC3D,IAAI,CAAC,KAAK,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,GAAG,EAAE,CAAA;QAEhC,IAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,WAAW,CAChD,IAAI,EACJ,mB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C,IAAI,CAAC,CAAA;QAE5C,OAAO,KAAK,CAAA;IAChB,CAAC,CAAA;AACL,CAAC;AAED,kCAAkC;AAClC,MAAM,UAAU,iBAAiB,CAAC,QAAiB,EAAE,OAAkC;IACnF,IAAM,SAAS,GAAG,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACzD,OAAO;QACH,IAAI,EAAE,IAAI;QACV,YAAY,YAAC,KAAK;YACd,OAAO,SAAS,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;KACJ,CAAA;AACL,CAAC;AACD,+BAA+B;AAC/B;IAQI,2BACI,QAAiB,EACjB,YAAqB,EACrB,SAAkB,EAClB,MAAe;IACf;;;;;;OAMG;IACH,iBAAyC;QAEzC,gEAAgE;QAChE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,UAAU,uBAAkE;YACzF,uBAAuB,CACnB,oBAAoB,CAAC,QAAQ,EAAE,EAAE,YAAY,cAAA,EAAE,SAAS,WAAA,EAAE,MAAM,QAAA,EAAE,iBAAiB,mBAAA,EAAE,CAAC,CACzF,CAAA;QACL,CAAC,CAAA;IACL,CAAC;IACL,wBAAC;AAAD,CAAC,AA9BD,IA8BC","sourcesContent":["/**\n * Integrate Sentry with PostHog. This will add a direct link to the person in Sentry, and an $exception event in PostHog\n *\n * ### Usage\n *\n * Sentry.init({\n * dsn: 'https://example',\n * integrations: [\n * new posthog.SentryIntegration(posthog)\n * ]\n * })\n *\n * @param {Object} [posthog] The posthog object\n * @param {string} [organization] Optional: The Sentry organization, used to send a direct link from PostHog to Sentry\n * @param {Number} [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry\n * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)\n */\n\nimport { PostHog } from '../posthog-core'\nimport { SeverityLevel } from '../types'\n\n// NOTE - we can't import from @sentry/types because it changes frequently and causes clashes\n// We only use a small subset of the types, so we can just define the integration overall and use any for the rest\n\n// import {\n// Event as _SentryEvent,\n// EventProcessor as _SentryEventProcessor,\n// Hub as _SentryHub,\n// Integration as _SentryIntegration,\n// SeverityLevel as _SeverityLevel,\n// IntegrationClass as _SentryIntegrationClass,\n// } from '@sentry/types'\n\n// Uncomment the above and comment the below to get type checking for development\n\ntype _SentryEvent = any\ntype _SentryEventProcessor = any\ntype _SentryHub = any\n\ninterface _SentryIntegrationClass {\n name: string\n setupOnce(addGlobalEventProcessor: (callback: _SentryEventProcessor) => void, getCurrentHub: () => _SentryHub): void\n}\n\ninterface _SentryIntegration {\n name: string\n processEvent(event: _SentryEvent): _SentryEvent\n}\n\ninterface SentryExceptionProperties {\n $sentry_event_id: any\n $sentry_exception: any\n $sentry_exception_message: any\n $sentry_exception_type: any\n $sentry_tags: any\n $sentry_url?: string\n}\n\nexport type SentryIntegrationOptions = {\n organization?: string\n projectId?: number\n prefix?: string\n /**\n * By default, only errors are sent to PostHog. You can set this to '*' to send all events.\n * Or to an error of SeverityLevel to only send events matching the provided levels.\n * e.g. ['error', 'fatal'] to send only errors and fatals\n * e.g. ['error'] to send only errors -- the default when omitted\n * e.g. '*' to send all events\n */\n severityAllowList?: SeverityLevel[] | '*'\n}\n\nconst NAME = 'posthog-js'\n\nexport function createEventProcessor(\n _posthog: PostHog,\n { organization, projectId, prefix, severityAllowList = ['error'] }: SentryIntegrationOptions = {}\n): (event: _SentryEvent) => _SentryEvent {\n return (event) => {\n const shouldProcessLevel = severityAllowList === '*' || severityAllowList.includes(event.level as SeverityLevel)\n if (!shouldProcessLevel || !_posthog.__loaded) return event\n if (!event.tags) event.tags = {}\n\n const personUrl = _posthog.requestRouter.endpointFor(\n 'ui',\n `/project/${_posthog.config.token}/person/${_posthog.get_distinct_id()}`\n )\n event.tags['PostHog Person URL'] = personUrl\n if (_posthog.sessionRecordingStarted()) {\n event.tags['PostHog Recording URL'] = _posthog.get_session_replay_url({ withTimestamp: true })\n }\n\n const exceptions = event.exception?.values || []\n\n const data: SentryExceptionProperties & {\n // two properties added to match any exception auto-capture\n // added manually to avoid any dependency on the lazily loaded content\n $exception_message: any\n $exception_type: any\n $exception_list: any\n $exception_personURL: string\n $exception_level: SeverityLevel\n $level: SeverityLevel\n } = {\n // PostHog Exception Properties,\n $exception_message: exceptions[0]?.value || event.message,\n $exception_type: exceptions[0]?.type,\n $exception_personURL: personUrl,\n $exception_level: event.level,\n $exception_list: exceptions,\n // Sentry Exception Properties\n $sentry_event_id: event.event_id,\n $sentry_exception: event.exception,\n $sentry_exception_message: exceptions[0]?.value || event.message,\n $sentry_exception_type: exceptions[0]?.type,\n $sentry_tags: event.tags,\n $level: event.level,\n }\n\n if (organization && projectId) {\n data['$sentry_url'] =\n (prefix || 'https://sentry.io/organizations/') +\n organization +\n '/issues/?project=' +\n projectId +\n '&query=' +\n event.event_id\n }\n\n _posthog.exceptions.sendExceptionEvent(data)\n\n return event\n }\n}\n\n// V8 integration - function based\nexport function sentryIntegration(_posthog: PostHog, options?: SentryIntegrationOptions): _SentryIntegration {\n const processor = createEventProcessor(_posthog, options)\n return {\n name: NAME,\n processEvent(event) {\n return processor(event)\n },\n }\n}\n// V7 integration - class based\nexport class SentryIntegration implements _SentryIntegrationClass {\n name: string\n\n setupOnce: (\n addGlobalEventProcessor: (callback: _SentryEventProcessor) => void,\n getCurrentHub: () => _SentryHub\n ) => void\n\n constructor(\n _posthog: PostHog,\n organization?: string,\n projectId?: number,\n prefix?: string,\n /**\n * By default, only errors are sent to PostHog. You can set this to '*' to send all events.\n * Or to an error of SeverityLevel to only send events matching the provided levels.\n * e.g. ['error', 'fatal'] to send only errors and fatals\n * e.g. ['error'] to send only errors -- the default when omitted\n * e.g. '*' to send all events\n */\n severityAllowList?: SeverityLevel[] | '*'\n ) {\n // setupOnce gets called by Sentry when it intializes the plugin\n this.name = NAME\n this.setupOnce = function (addGlobalEventProcessor: (callback: _SentryEventProcessor) => void) {\n addGlobalEventProcessor(\n createEventProcessor(_posthog, { organization, projectId, prefix, severityAllowList })\n )\n }\n }\n}\n"]}
|
package/lib/src/posthog-core.js
CHANGED
|
@@ -1588,7 +1588,16 @@ var PostHog = /** @class */ (function () {
|
|
|
1588
1588
|
undefined,
|
|
1589
1589
|
error,
|
|
1590
1590
|
])
|
|
1591
|
-
: __assign({ $
|
|
1591
|
+
: __assign({ $exception_level: 'error', $exception_list: [
|
|
1592
|
+
{
|
|
1593
|
+
type: error.name,
|
|
1594
|
+
value: error.message,
|
|
1595
|
+
mechanism: {
|
|
1596
|
+
handled: true,
|
|
1597
|
+
synthetic: false,
|
|
1598
|
+
},
|
|
1599
|
+
},
|
|
1600
|
+
] }, additionalProperties);
|
|
1592
1601
|
this.exceptions.sendExceptionEvent(properties);
|
|
1593
1602
|
};
|
|
1594
1603
|
/**
|