@posthog/ai 8.20.1 → 8.21.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.
Files changed (66) hide show
  1. package/README.md +20 -0
  2. package/dist/adk/index.cjs +125 -36
  3. package/dist/adk/index.cjs.map +1 -1
  4. package/dist/adk/index.d.ts +7 -0
  5. package/dist/adk/index.mjs +126 -37
  6. package/dist/adk/index.mjs.map +1 -1
  7. package/dist/anthropic/index.cjs +115 -22
  8. package/dist/anthropic/index.cjs.map +1 -1
  9. package/dist/anthropic/index.d.ts +7 -0
  10. package/dist/anthropic/index.mjs +116 -23
  11. package/dist/anthropic/index.mjs.map +1 -1
  12. package/dist/claude-agent-sdk/index.cjs +131 -35
  13. package/dist/claude-agent-sdk/index.cjs.map +1 -1
  14. package/dist/claude-agent-sdk/index.d.ts +6 -0
  15. package/dist/claude-agent-sdk/index.mjs +132 -36
  16. package/dist/claude-agent-sdk/index.mjs.map +1 -1
  17. package/dist/gemini/index.cjs +116 -23
  18. package/dist/gemini/index.cjs.map +1 -1
  19. package/dist/gemini/index.d.ts +7 -0
  20. package/dist/gemini/index.mjs +116 -23
  21. package/dist/gemini/index.mjs.map +1 -1
  22. package/dist/genkit/index.cjs +138 -43
  23. package/dist/genkit/index.cjs.map +1 -1
  24. package/dist/genkit/index.d.ts +7 -0
  25. package/dist/genkit/index.mjs +138 -43
  26. package/dist/genkit/index.mjs.map +1 -1
  27. package/dist/index.cjs +114 -21
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.ts +11 -0
  30. package/dist/index.mjs +115 -22
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/langchain/index.cjs +99 -21
  33. package/dist/langchain/index.cjs.map +1 -1
  34. package/dist/langchain/index.d.ts +7 -0
  35. package/dist/langchain/index.mjs +99 -21
  36. package/dist/langchain/index.mjs.map +1 -1
  37. package/dist/langchain/middleware/index.cjs +99 -21
  38. package/dist/langchain/middleware/index.cjs.map +1 -1
  39. package/dist/langchain/middleware/index.d.ts +6 -0
  40. package/dist/langchain/middleware/index.mjs +99 -21
  41. package/dist/langchain/middleware/index.mjs.map +1 -1
  42. package/dist/openai/index.cjs +115 -22
  43. package/dist/openai/index.cjs.map +1 -1
  44. package/dist/openai/index.d.ts +7 -0
  45. package/dist/openai/index.mjs +116 -23
  46. package/dist/openai/index.mjs.map +1 -1
  47. package/dist/openai-agents/index.cjs +139 -60
  48. package/dist/openai-agents/index.cjs.map +1 -1
  49. package/dist/openai-agents/index.d.ts +7 -0
  50. package/dist/openai-agents/index.mjs +139 -60
  51. package/dist/openai-agents/index.mjs.map +1 -1
  52. package/dist/otel/index.browser.cjs +24 -14
  53. package/dist/otel/index.browser.cjs.map +1 -1
  54. package/dist/otel/index.browser.mjs +24 -14
  55. package/dist/otel/index.browser.mjs.map +1 -1
  56. package/dist/otel/index.cjs +24 -14
  57. package/dist/otel/index.cjs.map +1 -1
  58. package/dist/otel/index.d.ts +3 -3
  59. package/dist/otel/index.mjs +24 -14
  60. package/dist/otel/index.mjs.map +1 -1
  61. package/dist/vercel/index.cjs +114 -21
  62. package/dist/vercel/index.cjs.map +1 -1
  63. package/dist/vercel/index.d.ts +6 -0
  64. package/dist/vercel/index.mjs +115 -22
  65. package/dist/vercel/index.mjs.map +1 -1
  66. package/package.json +5 -5
@@ -1,12 +1,81 @@
1
1
  import "uuid";
2
+ import { acceptsEventOptions, eventOptionsAsLegacyProperties } from "@posthog/core";
2
3
  //#region src/captureAiEvent.ts
3
4
  /** @internal */
4
5
  function isFullAiCaptureEnabled(client) {
5
6
  return client?.enableFullAiCapture === true;
6
7
  }
8
+ /**
9
+ * The caller's distinct id as a string, or undefined when it is missing, empty or only whitespace.
10
+ *
11
+ * @internal
12
+ */
13
+ function userDistinctId(value) {
14
+ if (!value) return;
15
+ const id = String(value);
16
+ return id.trim() === "" ? void 0 : id;
17
+ }
18
+ /**
19
+ * The caller's per-event options when they are an object. A missing or `null` value means no
20
+ * options. An array or any other value is reported and ignored, so it is never spread.
21
+ *
22
+ * @internal
23
+ */
24
+ function readAiEventOptions(value) {
25
+ if (value === void 0 || value === null) return;
26
+ if (typeof value === "object" && !Array.isArray(value)) return value;
27
+ console.warn(`[PostHog AI] options must be an object, got ${Array.isArray(value) ? "array" : typeof value}; ignoring them`);
28
+ }
29
+ /**
30
+ * The `properties` and `options` for an AI event. `personless` (no user distinct id) turns person
31
+ * processing off and beats the caller's `process_person_profile`.
32
+ *
33
+ * posthog-node 6 takes the options as they are, so no option is written as a property.
34
+ * posthog-node 5 has no per-event options: each known option is sent as the property that version
35
+ * reads, and an unknown key is dropped.
36
+ *
37
+ * @internal
38
+ */
39
+ function eventOptionFields(client, properties, options, personless) {
40
+ const userOptions = readAiEventOptions(options);
41
+ if (isPostHogNode6(client)) {
42
+ const eventOptions = {
43
+ ...userOptions,
44
+ ...personless ? { process_person_profile: false } : {}
45
+ };
46
+ return Object.keys(eventOptions).length > 0 ? {
47
+ properties,
48
+ options: eventOptions
49
+ } : { properties };
50
+ }
51
+ const withOptionProperties = {
52
+ ...properties,
53
+ ...eventOptionsAsLegacyProperties(userOptions)
54
+ };
55
+ if (personless) withOptionProperties.$process_person_profile = false;
56
+ return { properties: withOptionProperties };
57
+ }
58
+ /**
59
+ * Whether the client is posthog-node 6 or later, the first major with per-event options.
60
+ *
61
+ * @internal
62
+ */
63
+ function isPostHogNode6(client) {
64
+ return acceptsEventOptions(client);
65
+ }
66
+ /**
67
+ * posthog-node 6 sends every AI event on its capture v1 AI lane; `enableFullAiCapture` then only
68
+ * controls truncation and media redaction. posthog-node 5 keeps the opt-in, so an `@posthog/ai`
69
+ * upgrade never changes how a 5.x client sends.
70
+ *
71
+ * @internal
72
+ */
73
+ function usesAiLane(client) {
74
+ return isPostHogNode6(client) || isFullAiCaptureEnabled(client);
75
+ }
7
76
  /** @internal */
8
77
  function captureAiEvent(client, event) {
9
- if (isFullAiCaptureEnabled(client) && typeof client.captureAi === "function") {
78
+ if (usesAiLane(client) && typeof client.captureAi === "function") {
10
79
  client.captureAi(event);
11
80
  return;
12
81
  }
@@ -154,13 +223,17 @@ var MediaTypeContext = class MediaTypeContext {
154
223
  //#region src/sanitization/binary_content_redactor.ts
155
224
  const STRONG_CONTEXT_MIN_LENGTH = 64;
156
225
  const WEAK_CONTEXT_MIN_LENGTH = 1024;
226
+ const MAX_NODES = 1e4;
227
+ const TRUNCATED = "[Truncated]";
157
228
  var BinaryContentRedactor = class {
158
229
  constructor(recognizer = new Base64Recognizer()) {
159
230
  this.recognizer = recognizer;
160
- this.visited = /* @__PURE__ */ new WeakSet();
231
+ this.ancestors = /* @__PURE__ */ new WeakSet();
232
+ this.remainingNodes = MAX_NODES;
161
233
  }
162
234
  redact(value, mediaType) {
163
- this.visited = /* @__PURE__ */ new WeakSet();
235
+ this.ancestors = /* @__PURE__ */ new WeakSet();
236
+ this.remainingNodes = MAX_NODES;
164
237
  return this.walk(value, mediaType ? new MediaTypeContext(void 0, void 0, mediaType) : MediaTypeContext.EMPTY);
165
238
  }
166
239
  /** Redact one leaf while a caller owns bounded, type-preserving traversal. @internal */
@@ -172,18 +245,24 @@ var BinaryContentRedactor = class {
172
245
  if (typeof value === "string") return this.redactLeaf(value, ctx);
173
246
  if (typeof value !== "object") return value;
174
247
  if (typeof Uint8Array !== "undefined" && value instanceof Uint8Array) return this.redactLeaf(value, ctx);
175
- if (this.visited.has(value)) return null;
176
- this.visited.add(value);
177
- if (Array.isArray(value)) return value.map((item) => this.walk(item, ctx));
178
- const obj = value;
179
- const out = {};
180
- for (const k of Object.keys(obj)) Object.defineProperty(out, k, {
181
- value: this.walk(obj[k], new MediaTypeContext(obj, k)),
182
- enumerable: true,
183
- writable: true,
184
- configurable: true
185
- });
186
- return out;
248
+ if (this.ancestors.has(value)) return null;
249
+ if (this.remainingNodes <= 0) return TRUNCATED;
250
+ this.remainingNodes--;
251
+ this.ancestors.add(value);
252
+ try {
253
+ if (Array.isArray(value)) return value.map((item) => this.walk(item, ctx));
254
+ const obj = value;
255
+ const out = {};
256
+ for (const k of Object.keys(obj)) Object.defineProperty(out, k, {
257
+ value: this.walk(obj[k], new MediaTypeContext(obj, k)),
258
+ enumerable: true,
259
+ writable: true,
260
+ configurable: true
261
+ });
262
+ return out;
263
+ } finally {
264
+ this.ancestors.delete(value);
265
+ }
187
266
  }
188
267
  redactString(value, ctx) {
189
268
  const hasDefiniteBinaryData = ctx.hasDefiniteBinaryData();
@@ -362,7 +441,7 @@ function summarizeErrorForPrivacy(error) {
362
441
  }
363
442
  //#endregion
364
443
  //#region package.json
365
- var version = "8.20.1";
444
+ var version = "8.21.0";
366
445
  //#endregion
367
446
  //#region src/gatewayWarning.ts
368
447
  const POSTHOG_AI_GATEWAY_HOSTS = [
@@ -486,16 +565,12 @@ var PostHogTracingProcessor = class {
486
565
  this._privacyMode = options.privacyMode ?? false;
487
566
  this._groups = options.groups ?? {};
488
567
  this._properties = options.properties ?? {};
568
+ this._eventOptions = options.options;
489
569
  this._onError = options.onError;
490
570
  }
491
571
  _getDistinctId(trace) {
492
- if (typeof this._distinctId === "function") {
493
- if (trace) {
494
- const result = this._distinctId(trace);
495
- if (result) return String(result);
496
- }
497
- return;
498
- } else if (this._distinctId) return String(this._distinctId);
572
+ if (typeof this._distinctId === "function") return trace ? userDistinctId(this._distinctId(trace)) : void 0;
573
+ return userDistinctId(this._distinctId);
499
574
  }
500
575
  _withPrivacyMode(value) {
501
576
  return withPrivacyMode(this._client, this._privacyMode, value);
@@ -523,7 +598,7 @@ var PostHogTracingProcessor = class {
523
598
  this._onError?.(error, context);
524
599
  } catch (handlerError) {}
525
600
  }
526
- _captureEvent(event, properties, distinctId) {
601
+ _captureEvent(event, properties, identity) {
527
602
  try {
528
603
  if (!this._client?.capture) return;
529
604
  const finalProperties = {
@@ -531,9 +606,9 @@ var PostHogTracingProcessor = class {
531
606
  ...properties
532
607
  };
533
608
  const eventMessage = {
534
- distinctId: distinctId || "unknown",
609
+ distinctId: identity.distinctId || "unknown",
535
610
  event,
536
- properties: finalProperties,
611
+ ...eventOptionFields(this._client, finalProperties, this._eventOptions, identity.personless),
537
612
  groups: Object.keys(this._groups).length > 0 ? this._groups : void 0
538
613
  };
539
614
  captureAiEvent(this._client, eventMessage);
@@ -618,8 +693,10 @@ var PostHogTracingProcessor = class {
618
693
  properties.$ai_group_id = groupId;
619
694
  }
620
695
  if (metadata && Object.keys(metadata).length > 0) properties.$ai_trace_metadata = this._prepareCapturedValue(metadata);
621
- if (distinctId == null) properties.$process_person_profile = false;
622
- this._captureEvent("$ai_trace", properties, distinctId ?? traceId);
696
+ this._captureEvent("$ai_trace", properties, {
697
+ distinctId: distinctId ?? traceId,
698
+ personless: distinctId == null
699
+ });
623
700
  } catch (error) {
624
701
  this._handleError(error, "onTraceEnd");
625
702
  }
@@ -651,39 +728,41 @@ var PostHogTracingProcessor = class {
651
728
  const userDistinctId = traceInfo?.distinctId ?? this._getDistinctId(null);
652
729
  const groupId = traceInfo?.groupId ?? null;
653
730
  const errorProperties = this._getErrorProperties(span.error);
654
- if (userDistinctId == null) errorProperties.$process_person_profile = false;
655
- const distinctId = userDistinctId ?? traceId;
731
+ const identity = {
732
+ distinctId: userDistinctId ?? traceId,
733
+ personless: userDistinctId == null
734
+ };
656
735
  switch (spanData.type) {
657
736
  case "generation":
658
- this._handleGenerationSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
737
+ this._handleGenerationSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
659
738
  break;
660
739
  case "response":
661
- this._handleResponseSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
740
+ this._handleResponseSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
662
741
  break;
663
742
  case "function":
664
- this._handleFunctionSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
743
+ this._handleFunctionSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
665
744
  break;
666
745
  case "agent":
667
- this._handleAgentSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
746
+ this._handleAgentSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
668
747
  break;
669
748
  case "handoff":
670
- this._handleHandoffSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
749
+ this._handleHandoffSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
671
750
  break;
672
751
  case "guardrail":
673
- this._handleGuardrailSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
752
+ this._handleGuardrailSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
674
753
  break;
675
754
  case "custom":
676
- this._handleCustomSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
755
+ this._handleCustomSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
677
756
  break;
678
757
  case "transcription":
679
758
  case "speech":
680
759
  case "speech_group":
681
- this._handleAudioSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
760
+ this._handleAudioSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
682
761
  break;
683
762
  case "mcp_tools":
684
- this._handleMcpSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
763
+ this._handleMcpSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
685
764
  break;
686
- default: this._handleGenericSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties);
765
+ default: this._handleGenericSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties);
687
766
  }
688
767
  } catch (error) {
689
768
  this._handleError(error, "onSpanEnd");
@@ -705,7 +784,7 @@ var PostHogTracingProcessor = class {
705
784
  this._handleError(error, "forceFlush");
706
785
  }
707
786
  }
708
- _handleGenerationSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
787
+ _handleGenerationSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
709
788
  const rawResponse = spanData.output?.[0];
710
789
  const rawResponseUsage = rawResponse?.usage;
711
790
  const usage = spanData.usage ?? rawResponseUsage ?? {};
@@ -749,9 +828,9 @@ var PostHogTracingProcessor = class {
749
828
  if (usage.reasoning_tokens) properties.$ai_reasoning_tokens = usage.reasoning_tokens;
750
829
  if (usage.cache_read_input_tokens) properties.$ai_cache_read_input_tokens = usage.cache_read_input_tokens;
751
830
  if (usage.cache_creation_input_tokens) properties.$ai_cache_creation_input_tokens = usage.cache_creation_input_tokens;
752
- this._captureEvent("$ai_generation", properties, distinctId);
831
+ this._captureEvent("$ai_generation", properties, identity);
753
832
  }
754
- _handleResponseSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
833
+ _handleResponseSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
755
834
  const responseSpanData = spanData;
756
835
  const response = responseSpanData._response;
757
836
  const responseId = spanData.response_id ?? response?.id;
@@ -775,9 +854,9 @@ var PostHogTracingProcessor = class {
775
854
  const outputTokenDetails = usage.output_tokens_details;
776
855
  if (outputTokenDetails?.reasoning_tokens) properties.$ai_reasoning_tokens = outputTokenDetails.reasoning_tokens;
777
856
  if (response?.output) properties.$ai_output_choices = this._prepareCapturedValue(response.output);
778
- this._captureEvent("$ai_generation", properties, distinctId);
857
+ this._captureEvent("$ai_generation", properties, identity);
779
858
  }
780
- _handleFunctionSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
859
+ _handleFunctionSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
781
860
  const properties = {
782
861
  ...this._baseProperties(traceId, spanId, parentId, latency, groupId, errorProperties),
783
862
  $ai_span_name: spanData.name,
@@ -786,9 +865,9 @@ var PostHogTracingProcessor = class {
786
865
  $ai_output_state: this._prepareCapturedValue(spanData.output)
787
866
  };
788
867
  if (spanData.mcp_data) properties.$ai_mcp_data = this._prepareCapturedValue(spanData.mcp_data);
789
- this._captureEvent("$ai_span", properties, distinctId);
868
+ this._captureEvent("$ai_span", properties, identity);
790
869
  }
791
- _handleAgentSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
870
+ _handleAgentSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
792
871
  const properties = {
793
872
  ...this._baseProperties(traceId, spanId, parentId, latency, groupId, errorProperties),
794
873
  $ai_span_name: spanData.name,
@@ -797,9 +876,9 @@ var PostHogTracingProcessor = class {
797
876
  if (spanData.handoffs) properties.$ai_agent_handoffs = spanData.handoffs;
798
877
  if (spanData.tools) properties.$ai_agent_tools = spanData.tools;
799
878
  if (spanData.output_type) properties.$ai_agent_output_type = spanData.output_type;
800
- this._captureEvent("$ai_span", properties, distinctId);
879
+ this._captureEvent("$ai_span", properties, identity);
801
880
  }
802
- _handleHandoffSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
881
+ _handleHandoffSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
803
882
  const properties = {
804
883
  ...this._baseProperties(traceId, spanId, parentId, latency, groupId, errorProperties),
805
884
  $ai_span_name: `${spanData.from_agent} -> ${spanData.to_agent}`,
@@ -807,27 +886,27 @@ var PostHogTracingProcessor = class {
807
886
  $ai_handoff_from_agent: spanData.from_agent,
808
887
  $ai_handoff_to_agent: spanData.to_agent
809
888
  };
810
- this._captureEvent("$ai_span", properties, distinctId);
889
+ this._captureEvent("$ai_span", properties, identity);
811
890
  }
812
- _handleGuardrailSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
891
+ _handleGuardrailSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
813
892
  const properties = {
814
893
  ...this._baseProperties(traceId, spanId, parentId, latency, groupId, errorProperties),
815
894
  $ai_span_name: spanData.name,
816
895
  $ai_span_type: "guardrail",
817
896
  $ai_guardrail_triggered: spanData.triggered
818
897
  };
819
- this._captureEvent("$ai_span", properties, distinctId);
898
+ this._captureEvent("$ai_span", properties, identity);
820
899
  }
821
- _handleCustomSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
900
+ _handleCustomSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
822
901
  const properties = {
823
902
  ...this._baseProperties(traceId, spanId, parentId, latency, groupId, errorProperties),
824
903
  $ai_span_name: spanData.name,
825
904
  $ai_span_type: "custom",
826
905
  $ai_custom_data: this._prepareCapturedValue(spanData.data)
827
906
  };
828
- this._captureEvent("$ai_span", properties, distinctId);
907
+ this._captureEvent("$ai_span", properties, identity);
829
908
  }
830
- _handleAudioSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
909
+ _handleAudioSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
831
910
  const spanType = spanData.type;
832
911
  const properties = {
833
912
  ...this._baseProperties(traceId, spanId, parentId, latency, groupId, errorProperties),
@@ -848,9 +927,9 @@ var PostHogTracingProcessor = class {
848
927
  const speechGroup = spanData;
849
928
  if (speechGroup.input) properties.$ai_input = this._prepareCapturedValue(speechGroup.input);
850
929
  }
851
- this._captureEvent("$ai_span", properties, distinctId);
930
+ this._captureEvent("$ai_span", properties, identity);
852
931
  }
853
- _handleMcpSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
932
+ _handleMcpSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
854
933
  const properties = {
855
934
  ...this._baseProperties(traceId, spanId, parentId, latency, groupId, errorProperties),
856
935
  $ai_span_name: `mcp:${spanData.server}`,
@@ -858,16 +937,16 @@ var PostHogTracingProcessor = class {
858
937
  $ai_mcp_server: spanData.server,
859
938
  $ai_mcp_tools: this._prepareCapturedValue(spanData.result)
860
939
  };
861
- this._captureEvent("$ai_span", properties, distinctId);
940
+ this._captureEvent("$ai_span", properties, identity);
862
941
  }
863
- _handleGenericSpan(spanData, traceId, spanId, parentId, latency, distinctId, groupId, errorProperties) {
942
+ _handleGenericSpan(spanData, traceId, spanId, parentId, latency, identity, groupId, errorProperties) {
864
943
  const spanType = spanData.type || "unknown";
865
944
  const properties = {
866
945
  ...this._baseProperties(traceId, spanId, parentId, latency, groupId, errorProperties),
867
946
  $ai_span_name: spanType,
868
947
  $ai_span_type: spanType
869
948
  };
870
- this._captureEvent("$ai_span", properties, distinctId);
949
+ this._captureEvent("$ai_span", properties, identity);
871
950
  }
872
951
  };
873
952
  //#endregion