posthog-node
Advanced tools
Comparing version 4.4.1 to 4.5.0
# Next | ||
# 4.5.0 - 2025-02-06 | ||
## Added | ||
1. Adds manual exception capture with full stack trace processing via `captureException` function | ||
2. Adds ability to enable exception autocapture via the `enableExceptionAutocapture` init option | ||
# 4.4.1 - 2025-01-21 | ||
@@ -4,0 +11,0 @@ |
export * from './src/posthog-node' | ||
export * from './src/extensions/sentry-integration' | ||
export * from './src/extensions/express' |
/// <reference types="node" /> | ||
import { SeverityLevel } from 'posthog-node/src/extensions/error-tracking/types'; | ||
import * as http from 'node:http'; | ||
type PostHogCoreOptions = { | ||
@@ -375,2 +378,24 @@ /** PostHog API host, usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com' */ | ||
interface EventHint { | ||
mechanism?: Partial<Mechanism>; | ||
syntheticException?: Error | null; | ||
} | ||
interface Mechanism { | ||
handled?: boolean; | ||
type?: string; | ||
source?: string; | ||
synthetic?: boolean; | ||
} | ||
declare class ErrorTracking { | ||
private client; | ||
private _exceptionAutocaptureEnabled; | ||
static captureException(client: PostHog, error: unknown, distinctId: string, hint: EventHint, additionalProperties?: Record<string | number, any>): Promise<void>; | ||
constructor(client: PostHog, options: PostHogOptions); | ||
private startAutocaptureIfEnabled; | ||
private onException; | ||
private onFatalError; | ||
isEnabled(): boolean; | ||
} | ||
type PostHogOptions = PostHogCoreOptions & { | ||
@@ -380,2 +405,3 @@ persistence?: 'memory'; | ||
privacyMode?: boolean; | ||
enableExceptionAutocapture?: boolean; | ||
featureFlagsPollingInterval?: number; | ||
@@ -388,2 +414,3 @@ maxCacheSize?: number; | ||
private featureFlagsPoller?; | ||
protected errorTracking: ErrorTracking; | ||
private maxCacheSize; | ||
@@ -451,2 +478,3 @@ readonly options: PostHogOptions; | ||
private addLocalPersonAndGroupProperties; | ||
captureException(error: unknown, distinctId: string, additionalProperties?: Record<string | number, any>): void; | ||
} | ||
@@ -458,4 +486,2 @@ | ||
declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"]; | ||
declare type SeverityLevel = (typeof severityLevels)[number]; | ||
type _SentryEvent = any; | ||
@@ -487,2 +513,16 @@ type _SentryEventProcessor = any; | ||
export { PostHog, PostHogOptions, PostHogSentryIntegration, SentryIntegrationOptions, SeverityLevel, createEventProcessor, sentryIntegration, severityLevels }; | ||
type ExpressMiddleware = (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void; | ||
type ExpressErrorMiddleware = (error: MiddlewareError, req: http.IncomingMessage, res: http.ServerResponse, next: (error: MiddlewareError) => void) => void; | ||
interface MiddlewareError extends Error { | ||
status?: number | string; | ||
statusCode?: number | string; | ||
status_code?: number | string; | ||
output?: { | ||
statusCode?: number | string; | ||
}; | ||
} | ||
declare function setupExpressErrorHandler(_posthog: PostHog, app: { | ||
use: (middleware: ExpressMiddleware | ExpressErrorMiddleware) => unknown; | ||
}): void; | ||
export { PostHog, PostHogOptions, PostHogSentryIntegration, SentryIntegrationOptions, createEventProcessor, sentryIntegration, setupExpressErrorHandler }; |
@@ -186,4 +186,10 @@ import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PostHogCoreOptions, PostHogEventProperties, PostHogPersistedProperty, PostHogCaptureOptions, JsonType } from './types'; | ||
overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): Promise<void>; | ||
/*** | ||
*** ERROR TRACKING | ||
***/ | ||
captureException(error: Error, additionalProperties?: { | ||
[key: string]: any; | ||
}): void; | ||
} | ||
export * from './types'; | ||
export { LZString }; |
export * from './src/posthog-node'; | ||
export * from './src/extensions/sentry-integration'; | ||
export * from './src/extensions/express'; |
@@ -24,5 +24,4 @@ /** | ||
*/ | ||
import { SeverityLevel } from 'posthog-node/src/extensions/error-tracking/types'; | ||
import { type PostHog } from '../posthog-node'; | ||
export declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"]; | ||
export declare type SeverityLevel = (typeof severityLevels)[number]; | ||
type _SentryEvent = any; | ||
@@ -29,0 +28,0 @@ type _SentryEventProcessor = any; |
import { JsonType, PostHogCoreOptions, PostHogCoreStateless, PostHogFetchOptions, PostHogFetchResponse, PostHogFlagsAndPayloadsResponse, PostHogPersistedProperty } from '../../posthog-core/src'; | ||
import { EventMessage, GroupIdentifyMessage, IdentifyMessage, PostHogNodeV1 } from './types'; | ||
import ErrorTracking from './error-tracking'; | ||
export type PostHogOptions = PostHogCoreOptions & { | ||
@@ -7,2 +8,3 @@ persistence?: 'memory'; | ||
privacyMode?: boolean; | ||
enableExceptionAutocapture?: boolean; | ||
featureFlagsPollingInterval?: number; | ||
@@ -15,2 +17,3 @@ maxCacheSize?: number; | ||
private featureFlagsPoller?; | ||
protected errorTracking: ErrorTracking; | ||
private maxCacheSize; | ||
@@ -78,2 +81,3 @@ readonly options: PostHogOptions; | ||
private addLocalPersonAndGroupProperties; | ||
captureException(error: unknown, distinctId: string, additionalProperties?: Record<string | number, any>): void; | ||
} |
{ | ||
"name": "posthog-node", | ||
"version": "4.4.1", | ||
"version": "4.5.0", | ||
"description": "PostHog Node.js integration", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -25,7 +25,5 @@ /** | ||
import { SeverityLevel } from 'posthog-node/src/extensions/error-tracking/types' | ||
import { type PostHog } from '../posthog-node' | ||
export const severityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'] as const | ||
export declare type SeverityLevel = (typeof severityLevels)[number] | ||
// NOTE - we can't import from @sentry/types because it changes frequently and causes clashes | ||
@@ -32,0 +30,0 @@ // We only use a small subset of the types, so we can just define the integration overall and use any for the rest |
@@ -17,2 +17,3 @@ import { version } from '../package.json' | ||
import fetch from './fetch' | ||
import ErrorTracking from './error-tracking' | ||
@@ -23,2 +24,3 @@ export type PostHogOptions = PostHogCoreOptions & { | ||
privacyMode?: boolean | ||
enableExceptionAutocapture?: boolean | ||
// The interval in milliseconds between polls for refreshing feature flag definitions. Defaults to 30 seconds. | ||
@@ -39,2 +41,3 @@ featureFlagsPollingInterval?: number | ||
private featureFlagsPoller?: FeatureFlagsPoller | ||
protected errorTracking: ErrorTracking | ||
private maxCacheSize: number | ||
@@ -67,2 +70,3 @@ public readonly options: PostHogOptions | ||
} | ||
this.errorTracking = new ErrorTracking(this, options) | ||
this.distinctIdHasSentFlagCalls = {} | ||
@@ -488,2 +492,7 @@ this.maxCacheSize = options.maxCacheSize || MAX_CACHE_SIZE | ||
} | ||
captureException(error: unknown, distinctId: string, additionalProperties?: Record<string | number, any>): void { | ||
const syntheticException = new Error('PostHog syntheticException') | ||
ErrorTracking.captureException(this, error, distinctId, { syntheticException }, additionalProperties) | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1173201
53
16432