posthog-node 4.5.0 → 4.5.2

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/lib/index.d.ts CHANGED
@@ -389,7 +389,7 @@ interface Mechanism {
389
389
  declare class ErrorTracking {
390
390
  private client;
391
391
  private _exceptionAutocaptureEnabled;
392
- static captureException(client: PostHog, error: unknown, distinctId: string, hint: EventHint, additionalProperties?: Record<string | number, any>): Promise<void>;
392
+ static captureException(client: PostHog, error: unknown, hint: EventHint, distinctId?: string, additionalProperties?: Record<string | number, any>): Promise<void>;
393
393
  constructor(client: PostHog, options: PostHogOptions);
394
394
  private startAutocaptureIfEnabled;
395
395
  private onException;
@@ -472,7 +472,7 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
472
472
  reloadFeatureFlags(): Promise<void>;
473
473
  shutdown(shutdownTimeoutMs?: number): Promise<void>;
474
474
  private addLocalPersonAndGroupProperties;
475
- captureException(error: unknown, distinctId: string, additionalProperties?: Record<string | number, any>): void;
475
+ captureException(error: unknown, distinctId?: string, additionalProperties?: Record<string | number, any>): void;
476
476
  }
477
477
 
478
478
  /**
package/lib/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { createReadStream } from 'node:fs';
3
3
  import { createInterface } from 'node:readline';
4
4
  import { posix, dirname, sep } from 'node:path';
5
5
 
6
- var version = "4.5.0";
6
+ var version = "4.5.2";
7
7
 
8
8
  var PostHogPersistedProperty;
9
9
  (function (PostHogPersistedProperty) {
@@ -2874,10 +2874,12 @@ function getLastStackFrame(arr) {
2874
2874
 
2875
2875
  const SHUTDOWN_TIMEOUT = 2000;
2876
2876
  class ErrorTracking {
2877
- static async captureException(client, error, distinctId, hint, additionalProperties) {
2877
+ static async captureException(client, error, hint, distinctId, additionalProperties) {
2878
2878
  const properties = {
2879
2879
  ...additionalProperties
2880
2880
  };
2881
+ // Given stateless nature of Node SDK we capture exceptions using personless processing when no
2882
+ // user can be determined because a distinct_id is not provided e.g. exception autocapture
2881
2883
  if (!distinctId) {
2882
2884
  properties.$process_person_profile = false;
2883
2885
  }
@@ -2903,11 +2905,7 @@ class ErrorTracking {
2903
2905
  }
2904
2906
  }
2905
2907
  onException(exception, hint) {
2906
- // Given stateless nature of Node SDK we capture exceptions using personless processing
2907
- // when no user can be determined e.g. in the case of exception autocapture
2908
- ErrorTracking.captureException(this.client, exception, uuidv7(), hint, {
2909
- $process_person_profile: false
2910
- });
2908
+ ErrorTracking.captureException(this.client, exception, hint);
2911
2909
  }
2912
2910
  async onFatalError() {
2913
2911
  await this.client.shutdown(SHUTDOWN_TIMEOUT);
@@ -2998,8 +2996,12 @@ class PostHog extends PostHogCoreStateless {
2998
2996
  // return await super.getFeatureFlagsStateless(distinctId, groups, undefined, undefined, disableGeoip)
2999
2997
  return await _getFlags(distinctId, groups, disableGeoip);
3000
2998
  }
2999
+ if (event === '$feature_flag_called') {
3000
+ // If we're capturing a $feature_flag_called event, we don't want to enrich the event with cached flags that may be out of date.
3001
+ return {};
3002
+ }
3001
3003
  if ((this.featureFlagsPoller?.featureFlags?.length || 0) > 0) {
3002
- // Otherwise we may as well check for the flags locally and include them if there
3004
+ // Otherwise we may as well check for the flags locally and include them if they are already loaded
3003
3005
  const groupsWithStringValues = {};
3004
3006
  for (const [key, value] of Object.entries(groups || {})) {
3005
3007
  groupsWithStringValues[key] = String(value);
@@ -3245,9 +3247,9 @@ class PostHog extends PostHogCoreStateless {
3245
3247
  }
3246
3248
  captureException(error, distinctId, additionalProperties) {
3247
3249
  const syntheticException = new Error('PostHog syntheticException');
3248
- ErrorTracking.captureException(this, error, distinctId, {
3250
+ ErrorTracking.captureException(this, error, {
3249
3251
  syntheticException
3250
- }, additionalProperties);
3252
+ }, distinctId, additionalProperties);
3251
3253
  }
3252
3254
  }
3253
3255
 
@@ -3368,7 +3370,7 @@ function setupExpressErrorHandler(_posthog, app) {
3368
3370
  };
3369
3371
  // Given stateless nature of Node SDK we capture exceptions using personless processing
3370
3372
  // when no user can be determined e.g. in the case of exception autocapture
3371
- ErrorTracking.captureException(_posthog, error, uuidv7(), hint, {
3373
+ ErrorTracking.captureException(_posthog, error, hint, uuidv7(), {
3372
3374
  $process_person_profile: false
3373
3375
  });
3374
3376
  next(error);