Skip to content

Commit 3f0f352

Browse files
committed
fix: fallback for distinct_id
1 parent abc08a7 commit 3f0f352

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

posthog/ai/langchain/callbacks.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,11 @@ def on_llm_end(
173173
"$ai_trace_id": trace_id,
174174
"$ai_posthog_properties": self._properties,
175175
}
176-
try:
177-
self._client.capture(
178-
distinct_id=self._distinct_id,
179-
event="$ai_generation",
180-
properties=event_properties,
181-
)
182-
except Exception as e:
183-
self.log.exception(f"Error capturing event: {e}")
176+
self._client.capture(
177+
distinct_id=self._distinct_id or trace_id,
178+
event="$ai_generation",
179+
properties=event_properties,
180+
)
184181

185182
def on_chain_error(
186183
self,
@@ -219,7 +216,7 @@ def on_llm_error(
219216
"$ai_posthog_properties": self._properties,
220217
}
221218
self._client.capture(
222-
distinct_id=self._distinct_id,
219+
distinct_id=self._distinct_id or trace_id,
223220
event="$ai_generation",
224221
properties=event_properties,
225222
)

0 commit comments

Comments
 (0)