Repository navigation
fix: handle AsyncPosthog in the LangChain and new_context exception paths - #1211
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
posthog-python Compliance ReportDate: 2026-11-08T21:51:04.106738+00:00 ✅ All Tests Passed!121/121 tests passed Capture_V1 Tests✅ 95/95 tests passed View Details
Capture_Ai Tests✅ 5/5 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
Feature_Flags_Local_Evaluation Tests✅ 4/4 tests passed View Details
|
SDK performance: posthog-pythonBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marandaneto
left a comment
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
💡 Motivation and Context
AsyncPosthoghas noenable_exception_autocapturesetting, but two exception paths read it directly:CallbackHandler: a failed run loses its$ai_generation,$ai_spanor$ai_traceevent. TheAttributeErrorhappens inside a LangChain callback, which LangChain swallows, so the event is never sent.new_context(client=<AsyncPosthog>): raisesAttributeErrorunlesscapture_exceptionsis passed.Changes:
getattr(..., False), as the handler already does forprivacy_mode. A client without the setting does not capture exceptions by default.capture_exceptions=Truestill captures through the given client.enable_exception_autocapturein the LangChain tests, and a realAsyncPosthogin the context tests.💚 How did you test it?
pytest posthog/test: everything passes except three fork tests intest_metrics_autocapture.py. Those also fail intermittently with the branch reset tomain's code, and pass on reruns.mypywith the baseline filter andruffare clean.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Claude Opus 5.5) found both bugs while extending capture v1 smoke tests, then wrote the fixes and tests. The other integrations that read this setting (Django, Flask, ASGI, DRF) take a
Clientand are unchanged.🤖 Generated with Claude Code