posthoganalytics 8.2.0__tar.gz → 8.2.2__tar.gz
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.
- {posthoganalytics-8.2.0/posthoganalytics.egg-info → posthoganalytics-8.2.2}/PKG-INFO +1 -1
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/claude_agent_sdk/client.py +34 -12
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/claude_agent_sdk/processor.py +209 -89
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/langchain/callbacks.py +48 -4
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai_agents/processor.py +14 -3
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/claude_agent_sdk/test_client.py +89 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/claude_agent_sdk/test_processor.py +157 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/openai_agents/test_processor.py +30 -0
- posthoganalytics-8.2.2/posthoganalytics/version.py +1 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2/posthoganalytics.egg-info}/PKG-INFO +1 -1
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/pyproject.toml +1 -1
- posthoganalytics-8.2.0/posthoganalytics/version.py +0 -1
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/LICENSE +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/MANIFEST.in +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/README.md +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/README_ANALYTICS.md +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/_async_consumer.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/_async_request.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/_async_utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/_disabled_lane_queue.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/_logging.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/_metrics_autocapture.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/anthropic/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/anthropic/_anthropic_stream.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/anthropic/anthropic.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/anthropic/anthropic_async.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/anthropic/anthropic_converter.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/anthropic/anthropic_providers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/claude_agent_sdk/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/claude_agent_sdk/formatting.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_async_datasets.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_client.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_dataset_serialization.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_dataset_types.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_datasets.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_errors.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_mutations.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_scorer_types.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_scorers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_serialization.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_tags.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_transport.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/evaluations/_types.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/gateway.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/gemini/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/gemini/_shared.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/gemini/gemini.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/gemini/gemini_async.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/gemini/gemini_converter.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/langchain/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/langchain/middleware.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/media.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai/_embeddings.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai/_streaming.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai/openai.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai/openai_async.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai/openai_converter.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai/openai_providers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai/wrapper_utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai_agents/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/otel/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/otel/_privacy.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/otel/_request_context.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/otel/exporter.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/otel/processor.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/otel/spans.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/prompts.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/sanitization.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/stream.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/types.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/args.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/async_client.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/bucketed_rate_limiter.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/capture_compression.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/capture_event.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/capture_send.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/client.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/consumer.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/contexts.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/emails.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/exception_capture.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/exception_utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/feature_flag_evaluations.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/feature_flags.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/flag_definition_cache.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/integrations/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/integrations/_tracing_headers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/integrations/asgi.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/integrations/celery.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/integrations/django.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/integrations/drf.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/integrations/flask.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/integrations/otel.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_argument_ownership.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_capture.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_compatibility.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_context_parameters.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_conversation_id.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_event_types.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_exceptions.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_ids.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_instrument_fastmcp.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_instrument_lowlevel.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_instrument_v2.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_instrumentation.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_intent.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_internal.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_model_parameters.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_output_instructions.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_posthog_events.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_raised_tool_error.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_sanitization.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_server_build.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_sink.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_tool_input.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_transport_identity.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/_truncation.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/asgi.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/constants.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/feedback.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/logger.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/posthog_mcp.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/request_headers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/session.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/session_token.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/tools.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/types.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/mcp/version.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/metrics_capture.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/poller.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/py.typed +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/release_id.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/request.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/claude_agent_sdk/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/claude_agent_sdk/test_processor_content.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/openai_agents/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/otel/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/otel/conftest.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/otel/test_exporter.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/otel/test_processor.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/otel/test_spans.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_async_cancellation.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_async_stream_wrapper.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_capture_contract.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_capture_pipeline.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_evaluations.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_evaluations_datasets.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_evaluations_mutations.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_evaluations_scorers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_evaluations_transport.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_gateway.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_http_status.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_media.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_privacy_mode.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_prompts.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_sanitization.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_stream_midstream_error.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_system_prompts.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_token_reporting.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_tokens_source.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/test_utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/ai/utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/capture_helpers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/conftest.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/logging_helpers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/_helpers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/_helpers_lowlevel.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/_helpers_v2.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/conftest.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_asgi.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_capture.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_conversation_session.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_defaults.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_error_properties.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_error_status.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_fastmcp.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_fastmcp_tool_errors.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_fastmcp_v2.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_fastmcp_v4.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_features_m4.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_feedback.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_initialize_handshake.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_instrument_lowlevel_ownership.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_instrument_v2.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_instrumentation_fork.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_lib_label.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_lowlevel.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_model_parameters.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_no_crash.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_output_instructions.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_pending_tasks.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_pipeline.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_posthog_mcp.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_request_headers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_resources.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_review_fixes.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_send_tools_list_event.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_session_token.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_tool_input.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_transport_identity.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_truncation.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_types.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_units.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_unknown_tool.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_v2_lowlevel.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_v2_mcpserver.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_v2_wire_dual_era.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/mcp/test_virtual_tools.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/released_flags_scenarios.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_ai_capture_lane.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_async_client.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_async_consumer.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_async_feature_flags.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_async_request.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_async_utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_before_send.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_bucketed_rate_limiter.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_capture_compression.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_capture_event.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_capture_invariants.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_capture_send.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_client.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_client_crap_flags.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_client_fork.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_code_variables.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_consumer.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_contexts.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_emails.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_evaluate_flags.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_event_options.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_exception_capture.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_exception_utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_experiment_exposure.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_failed_flag_records.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_feature_flag.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_feature_flag_called_minimization.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_feature_flag_has_experiment.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_feature_flag_result.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_feature_flags.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_feature_flags_regex.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_flag_cache_eviction_reads.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_flag_cache_publication.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_flag_definition_cache.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_flag_payload_parsing.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_flags_released_behaviour.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_flags_v4_response.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_gevent_compat.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_metrics.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_metrics_autocapture.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_module.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_posthog_upgrade_workflow.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_property_matching_version.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_redis_flag_cache_snapshot.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_reference_markdown.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_release_id.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_request.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_server_payload_snapshots.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_size_limited_dict.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_types.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/test_utils_acceptance.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/conftest.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/helpers.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_client_traces.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_config.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_export.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_ids.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_limits.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_otlp.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_pipeline.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_sanitize.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_span.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_traceparent.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/test/tracing/test_transport.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/__init__.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_before_span_send.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_config.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_context.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_drops.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_export.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_ids.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_limits.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_otlp.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_pipeline.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_sanitize.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_span.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_traceparent.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/_transport.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/tracing/span.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/types.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/utils.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics.egg-info/SOURCES.txt +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics.egg-info/dependency_links.txt +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics.egg-info/requires.txt +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics.egg-info/top_level.txt +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/setup.cfg +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/setup.py +0 -0
- {posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/setup_analytics.py +0 -0
{posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/claude_agent_sdk/client.py
RENAMED
|
@@ -32,9 +32,11 @@ from .formatting import (
|
|
|
32
32
|
from posthoganalytics.ai.claude_agent_sdk.processor import (
|
|
33
33
|
PostHogClaudeAgentProcessor,
|
|
34
34
|
_GenerationTracker,
|
|
35
|
+
_PendingToolSpan,
|
|
35
36
|
_from_subagent,
|
|
36
37
|
_promote_input,
|
|
37
38
|
_starts_generation,
|
|
39
|
+
_tool_result_blocks,
|
|
38
40
|
)
|
|
39
41
|
from posthoganalytics.client import Client
|
|
40
42
|
|
|
@@ -119,6 +121,8 @@ class PostHogClaudeSDKClient:
|
|
|
119
121
|
self._current_input: Optional[List[Dict[str, Any]]] = None
|
|
120
122
|
self._next_input: Optional[List[Dict[str, Any]]] = None
|
|
121
123
|
self._pending_output: List[Dict[str, Any]] = []
|
|
124
|
+
# Tool spans waiting for their result, keyed by tool_use_id
|
|
125
|
+
self._pending_tools: Dict[str, _PendingToolSpan] = {}
|
|
122
126
|
self._query_start = time.time()
|
|
123
127
|
|
|
124
128
|
async def connect(self, prompt: Any = None) -> None:
|
|
@@ -146,12 +150,20 @@ class PostHogClaudeSDKClient:
|
|
|
146
150
|
|
|
147
151
|
async def receive_response(self):
|
|
148
152
|
"""Instrumented receive_response -- yields all messages, emits PostHog events."""
|
|
149
|
-
|
|
153
|
+
try:
|
|
154
|
+
async for message in self._client.receive_response():
|
|
155
|
+
try:
|
|
156
|
+
self._process_message(message)
|
|
157
|
+
except Exception as e:
|
|
158
|
+
log.debug(f"PostHog instrumentation error (non-fatal): {e}")
|
|
159
|
+
yield message
|
|
160
|
+
finally:
|
|
161
|
+
# A turn that stops early (break, interrupt, no ResultMessage) would
|
|
162
|
+
# otherwise hold its unfinished tool spans until disconnect().
|
|
150
163
|
try:
|
|
151
|
-
self.
|
|
164
|
+
self._processor._flush_tool_spans(self._pending_tools)
|
|
152
165
|
except Exception as e:
|
|
153
166
|
log.debug(f"PostHog instrumentation error (non-fatal): {e}")
|
|
154
|
-
yield message
|
|
155
167
|
|
|
156
168
|
def _process_message(self, message: Any) -> None:
|
|
157
169
|
if isinstance(message, StreamEvent):
|
|
@@ -186,16 +198,23 @@ class PostHogClaudeSDKClient:
|
|
|
186
198
|
elif isinstance(message, AssistantMessage):
|
|
187
199
|
self._process_assistant_message(message)
|
|
188
200
|
|
|
189
|
-
elif isinstance(message, UserMessage)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
201
|
+
elif isinstance(message, UserMessage):
|
|
202
|
+
# Tool results close their tool spans, subagent ones included.
|
|
203
|
+
for block in _tool_result_blocks(message):
|
|
204
|
+
self._processor._finish_tool_span(
|
|
205
|
+
self._pending_tools, block, self._privacy
|
|
206
|
+
)
|
|
207
|
+
if not _from_subagent(message):
|
|
208
|
+
if not self._tracker.had_any_stream_events:
|
|
209
|
+
# Without stream events, a tool result ends the assistant
|
|
210
|
+
# turn; the result fallback reports the final turn only.
|
|
211
|
+
self._pending_output = []
|
|
212
|
+
self._next_input = _format_user_input(
|
|
213
|
+
message.content, self._processor._client, self._next_input
|
|
214
|
+
)
|
|
197
215
|
|
|
198
216
|
elif isinstance(message, ResultMessage):
|
|
217
|
+
self._processor._flush_tool_spans(self._pending_tools)
|
|
199
218
|
if not self._tracker.had_any_stream_events:
|
|
200
219
|
self._processor._emit_generation_from_result(
|
|
201
220
|
message,
|
|
@@ -217,7 +236,8 @@ class PostHogClaudeSDKClient:
|
|
|
217
236
|
parent_id = self._tracker.current_span_id or self._current_generation_span_id
|
|
218
237
|
for block in message.content:
|
|
219
238
|
if isinstance(block, ToolUseBlock):
|
|
220
|
-
self._processor.
|
|
239
|
+
self._processor._start_tool_span(
|
|
240
|
+
self._pending_tools,
|
|
221
241
|
block,
|
|
222
242
|
self._trace_id,
|
|
223
243
|
parent_id,
|
|
@@ -237,6 +257,8 @@ class PostHogClaudeSDKClient:
|
|
|
237
257
|
"""
|
|
238
258
|
# Emit the trace event covering the entire session
|
|
239
259
|
try:
|
|
260
|
+
# Tool spans whose result never arrived are emitted without one.
|
|
261
|
+
self._processor._flush_tool_spans(self._pending_tools)
|
|
240
262
|
latency = time.time() - self._query_start
|
|
241
263
|
resolved_id = self._processor._resolve_distinct_id(self._distinct_id)
|
|
242
264
|
|
{posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/claude_agent_sdk/processor.py
RENAMED
|
@@ -62,6 +62,36 @@ class _GenerationData:
|
|
|
62
62
|
stop_reason: Optional[str] = None
|
|
63
63
|
|
|
64
64
|
|
|
65
|
+
@dataclass
|
|
66
|
+
class _PendingToolSpan:
|
|
67
|
+
"""A tool span waiting for its ToolResultBlock."""
|
|
68
|
+
|
|
69
|
+
properties: Dict[str, Any]
|
|
70
|
+
start_time: float
|
|
71
|
+
distinct_id: Any
|
|
72
|
+
groups: Dict[str, Any]
|
|
73
|
+
extra_options: Optional[Dict[str, Any]] = None
|
|
74
|
+
privacy: bool = False
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
_TOOL_SPAN_CONTENT_PROPERTIES = ("$ai_input_state", "$ai_output_state", "$ai_error")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _tool_error_text(content: Any) -> str:
|
|
81
|
+
"""The `$ai_error` text for an errored tool result's content."""
|
|
82
|
+
if isinstance(content, str):
|
|
83
|
+
return content
|
|
84
|
+
if isinstance(content, list):
|
|
85
|
+
texts = [
|
|
86
|
+
item["text"]
|
|
87
|
+
for item in content
|
|
88
|
+
if isinstance(item, dict) and isinstance(item.get("text"), str)
|
|
89
|
+
]
|
|
90
|
+
if texts:
|
|
91
|
+
return "\n".join(texts)
|
|
92
|
+
return "" if content is None else str(content)
|
|
93
|
+
|
|
94
|
+
|
|
65
95
|
class _GenerationTracker:
|
|
66
96
|
"""Tracks StreamEvent boundaries to reconstruct per-generation metrics.
|
|
67
97
|
|
|
@@ -162,7 +192,9 @@ class PostHogClaudeAgentProcessor:
|
|
|
162
192
|
|
|
163
193
|
Emits:
|
|
164
194
|
- $ai_generation: one per Anthropic API call (reconstructed from StreamEvents)
|
|
165
|
-
- $ai_span: one per tool use (ToolUseBlock in AssistantMessage)
|
|
195
|
+
- $ai_span: one per tool use (ToolUseBlock in AssistantMessage), emitted
|
|
196
|
+
when its ToolResultBlock arrives so it carries the result, error flag
|
|
197
|
+
and latency
|
|
166
198
|
- $ai_trace: one per query() call (on ResultMessage)
|
|
167
199
|
"""
|
|
168
200
|
|
|
@@ -315,90 +347,114 @@ class PostHogClaudeAgentProcessor:
|
|
|
315
347
|
# Accumulate assistant output per generation
|
|
316
348
|
pending_output: List[Dict[str, Any]] = []
|
|
317
349
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
350
|
+
# Tool spans waiting for their result, keyed by tool_use_id
|
|
351
|
+
pending_tools: Dict[str, _PendingToolSpan] = {}
|
|
352
|
+
|
|
353
|
+
try:
|
|
354
|
+
async for message in original_query(
|
|
355
|
+
prompt=prompt, options=options, transport=transport
|
|
356
|
+
):
|
|
357
|
+
# All instrumentation is wrapped in try/except so PostHog errors
|
|
358
|
+
# never interrupt the underlying Claude Agent SDK query.
|
|
359
|
+
try:
|
|
360
|
+
if isinstance(message, StreamEvent):
|
|
361
|
+
if _starts_generation(message):
|
|
362
|
+
if tracker.current_span_id is not None:
|
|
363
|
+
# The previous request never finished (it was
|
|
364
|
+
# retried), so its partial output is dropped.
|
|
365
|
+
pending_output = []
|
|
366
|
+
current_input, next_input = _promote_input(
|
|
367
|
+
current_input, next_input
|
|
368
|
+
)
|
|
369
|
+
tracker.process_stream_event(message)
|
|
370
|
+
|
|
371
|
+
# Emit $ai_generation when a turn completes
|
|
372
|
+
if tracker.has_completed_generation():
|
|
373
|
+
gen = tracker.pop_generation()
|
|
374
|
+
generation_index += 1
|
|
375
|
+
current_generation_span_id = gen.span_id
|
|
376
|
+
self._emit_generation(
|
|
377
|
+
gen,
|
|
378
|
+
trace_id,
|
|
379
|
+
generation_index,
|
|
380
|
+
current_input,
|
|
381
|
+
pending_output or None,
|
|
382
|
+
distinct_id_override,
|
|
383
|
+
extra_props,
|
|
384
|
+
privacy,
|
|
385
|
+
groups,
|
|
386
|
+
extra_options=extra_options,
|
|
387
|
+
)
|
|
388
|
+
current_input = None
|
|
329
389
|
pending_output = []
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
)
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
current_generation_span_id = gen.span_id
|
|
340
|
-
self._emit_generation(
|
|
341
|
-
gen,
|
|
342
|
-
trace_id,
|
|
343
|
-
generation_index,
|
|
344
|
-
current_input,
|
|
345
|
-
pending_output or None,
|
|
346
|
-
distinct_id_override,
|
|
347
|
-
extra_props,
|
|
348
|
-
privacy,
|
|
349
|
-
groups,
|
|
350
|
-
extra_options=extra_options,
|
|
390
|
+
|
|
391
|
+
elif isinstance(message, AssistantMessage):
|
|
392
|
+
tracker.set_model(message.model)
|
|
393
|
+
# Use the in-progress generation's span_id as parent for tool spans.
|
|
394
|
+
# AssistantMessage arrives before message_stop, so current_generation_span_id
|
|
395
|
+
# would be stale (from the previous turn). tracker.current_span_id gives us
|
|
396
|
+
# the correct in-progress generation.
|
|
397
|
+
parent_id = (
|
|
398
|
+
tracker.current_span_id or current_generation_span_id
|
|
351
399
|
)
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
400
|
+
for block in message.content:
|
|
401
|
+
if isinstance(block, ToolUseBlock):
|
|
402
|
+
self._start_tool_span(
|
|
403
|
+
pending_tools,
|
|
404
|
+
block,
|
|
405
|
+
trace_id,
|
|
406
|
+
parent_id,
|
|
407
|
+
distinct_id_override,
|
|
408
|
+
extra_props,
|
|
409
|
+
privacy,
|
|
410
|
+
groups,
|
|
411
|
+
extra_options=extra_options,
|
|
412
|
+
)
|
|
413
|
+
if not _from_subagent(message):
|
|
414
|
+
# A subagent's own API calls are not this query's generations.
|
|
415
|
+
pending_output = _append_assistant_output(
|
|
416
|
+
pending_output, message.content
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
elif isinstance(message, UserMessage):
|
|
420
|
+
# Tool results close their tool spans, subagent ones included.
|
|
421
|
+
for block in _tool_result_blocks(message):
|
|
422
|
+
self._finish_tool_span(pending_tools, block, privacy)
|
|
423
|
+
if not _from_subagent(message):
|
|
424
|
+
# UserMessages carry tool results; queue them as input
|
|
425
|
+
# for the *next* generation.
|
|
426
|
+
if not tracker.had_any_stream_events:
|
|
427
|
+
# Without stream events, a tool result ends the
|
|
428
|
+
# assistant turn; the result fallback reports the
|
|
429
|
+
# final turn only.
|
|
430
|
+
pending_output = []
|
|
431
|
+
next_input = _format_user_input(
|
|
432
|
+
message.content, self._client, next_input
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
elif isinstance(message, ResultMessage):
|
|
436
|
+
self._flush_tool_spans(pending_tools)
|
|
437
|
+
# Fallback: if no StreamEvents were received, emit a single
|
|
438
|
+
# generation from ResultMessage aggregate data
|
|
439
|
+
if not tracker.had_any_stream_events:
|
|
440
|
+
self._emit_generation_from_result(
|
|
441
|
+
message,
|
|
366
442
|
trace_id,
|
|
367
|
-
|
|
443
|
+
tracker.last_model,
|
|
444
|
+
query_start,
|
|
445
|
+
initial_input,
|
|
446
|
+
pending_output,
|
|
368
447
|
distinct_id_override,
|
|
369
448
|
extra_props,
|
|
370
449
|
privacy,
|
|
371
450
|
groups,
|
|
372
451
|
extra_options=extra_options,
|
|
373
452
|
)
|
|
374
|
-
if not _from_subagent(message):
|
|
375
|
-
# A subagent's own API calls are not this query's generations.
|
|
376
|
-
pending_output = _append_assistant_output(
|
|
377
|
-
pending_output, message.content
|
|
378
|
-
)
|
|
379
453
|
|
|
380
|
-
|
|
381
|
-
# UserMessages carry tool results; queue them as input for the
|
|
382
|
-
# *next* generation.
|
|
383
|
-
if not tracker.had_any_stream_events:
|
|
384
|
-
# Without stream events, a tool result ends the assistant
|
|
385
|
-
# turn; the result fallback reports the final turn only.
|
|
386
|
-
pending_output = []
|
|
387
|
-
next_input = _format_user_input(
|
|
388
|
-
message.content, self._client, next_input
|
|
389
|
-
)
|
|
390
|
-
|
|
391
|
-
elif isinstance(message, ResultMessage):
|
|
392
|
-
# Fallback: if no StreamEvents were received, emit a single
|
|
393
|
-
# generation from ResultMessage aggregate data
|
|
394
|
-
if not tracker.had_any_stream_events:
|
|
395
|
-
self._emit_generation_from_result(
|
|
454
|
+
self._emit_trace(
|
|
396
455
|
message,
|
|
397
456
|
trace_id,
|
|
398
|
-
tracker.last_model,
|
|
399
457
|
query_start,
|
|
400
|
-
initial_input,
|
|
401
|
-
pending_output,
|
|
402
458
|
distinct_id_override,
|
|
403
459
|
extra_props,
|
|
404
460
|
privacy,
|
|
@@ -406,22 +462,18 @@ class PostHogClaudeAgentProcessor:
|
|
|
406
462
|
extra_options=extra_options,
|
|
407
463
|
)
|
|
408
464
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
trace_id,
|
|
412
|
-
query_start,
|
|
413
|
-
distinct_id_override,
|
|
414
|
-
extra_props,
|
|
415
|
-
privacy,
|
|
416
|
-
groups,
|
|
417
|
-
extra_options=extra_options,
|
|
418
|
-
)
|
|
465
|
+
except Exception as e:
|
|
466
|
+
log.debug(f"PostHog instrumentation error (non-fatal): {e}")
|
|
419
467
|
|
|
468
|
+
yield message
|
|
469
|
+
finally:
|
|
470
|
+
# Tool spans still waiting for a result (the query ended
|
|
471
|
+
# early, failed or was cancelled) are emitted without one.
|
|
472
|
+
try:
|
|
473
|
+
self._flush_tool_spans(pending_tools)
|
|
420
474
|
except Exception as e:
|
|
421
475
|
log.debug(f"PostHog instrumentation error (non-fatal): {e}")
|
|
422
476
|
|
|
423
|
-
yield message
|
|
424
|
-
|
|
425
477
|
def _emit_generation(
|
|
426
478
|
self,
|
|
427
479
|
gen: _GenerationData,
|
|
@@ -573,8 +625,9 @@ class PostHogClaudeAgentProcessor:
|
|
|
573
625
|
options=extra_options,
|
|
574
626
|
)
|
|
575
627
|
|
|
576
|
-
def
|
|
628
|
+
def _start_tool_span(
|
|
577
629
|
self,
|
|
630
|
+
pending: Dict[str, _PendingToolSpan],
|
|
578
631
|
block: "ToolUseBlock",
|
|
579
632
|
trace_id: str,
|
|
580
633
|
parent_span_id: Optional[str],
|
|
@@ -584,8 +637,12 @@ class PostHogClaudeAgentProcessor:
|
|
|
584
637
|
groups: Dict[str, Any],
|
|
585
638
|
extra_options: Optional[Dict[str, Any]] = None,
|
|
586
639
|
) -> None:
|
|
587
|
-
|
|
640
|
+
"""Hold a tool span until its ToolResultBlock arrives.
|
|
588
641
|
|
|
642
|
+
The span is emitted by ``_finish_tool_span`` with the result, error
|
|
643
|
+
flag and latency, or by ``_flush_tool_spans`` without them if the
|
|
644
|
+
result never arrives.
|
|
645
|
+
"""
|
|
589
646
|
properties: Dict[str, Any] = {
|
|
590
647
|
"$ai_trace_id": trace_id,
|
|
591
648
|
"$ai_span_id": str(uuid.uuid4()),
|
|
@@ -602,13 +659,68 @@ class PostHogClaudeAgentProcessor:
|
|
|
602
659
|
_ensure_serializable(block.input), self._client
|
|
603
660
|
)
|
|
604
661
|
|
|
662
|
+
span = _PendingToolSpan(
|
|
663
|
+
properties=properties,
|
|
664
|
+
start_time=time.time(),
|
|
665
|
+
distinct_id=distinct_id,
|
|
666
|
+
groups=groups,
|
|
667
|
+
extra_options=extra_options,
|
|
668
|
+
privacy=privacy,
|
|
669
|
+
)
|
|
670
|
+
tool_use_id = getattr(block, "id", None)
|
|
671
|
+
if tool_use_id is None:
|
|
672
|
+
# Nothing can match a result to this span, so emit it now.
|
|
673
|
+
self._capture_tool_span(span)
|
|
674
|
+
return
|
|
675
|
+
# A repeated id would orphan the earlier span; emit it first.
|
|
676
|
+
previous = pending.pop(tool_use_id, None)
|
|
677
|
+
if previous is not None:
|
|
678
|
+
self._capture_tool_span(previous)
|
|
679
|
+
pending[tool_use_id] = span
|
|
680
|
+
|
|
681
|
+
def _finish_tool_span(
|
|
682
|
+
self,
|
|
683
|
+
pending: Dict[str, _PendingToolSpan],
|
|
684
|
+
block: Any,
|
|
685
|
+
privacy: bool,
|
|
686
|
+
) -> None:
|
|
687
|
+
"""Emit the held tool span for a ToolResultBlock with its outcome."""
|
|
688
|
+
tool_use_id = getattr(block, "tool_use_id", None)
|
|
689
|
+
span = pending.pop(tool_use_id, None) if tool_use_id is not None else None
|
|
690
|
+
if span is None:
|
|
691
|
+
return
|
|
692
|
+
properties = span.properties
|
|
693
|
+
properties["$ai_latency"] = time.time() - span.start_time
|
|
694
|
+
is_error = bool(getattr(block, "is_error", False))
|
|
695
|
+
properties["$ai_is_error"] = is_error
|
|
696
|
+
if _with_privacy_mode(self._client, privacy, True):
|
|
697
|
+
content = format_tool_result_content(block, self._client)
|
|
698
|
+
properties["$ai_output_state"] = finalize_ai_content(content, self._client)
|
|
699
|
+
if is_error:
|
|
700
|
+
properties["$ai_error"] = _tool_error_text(content)
|
|
701
|
+
self._capture_tool_span(span)
|
|
702
|
+
|
|
703
|
+
def _flush_tool_spans(self, pending: Dict[str, _PendingToolSpan]) -> None:
|
|
704
|
+
"""Emit tool spans whose result never arrived, without an outcome."""
|
|
705
|
+
while pending:
|
|
706
|
+
_, span = pending.popitem()
|
|
707
|
+
self._capture_tool_span(span)
|
|
708
|
+
|
|
709
|
+
def _capture_tool_span(self, span: _PendingToolSpan) -> None:
|
|
710
|
+
if _with_privacy_mode(self._client, span.privacy, True) is None:
|
|
711
|
+
# Privacy may have been enabled while the tool ran; drop content
|
|
712
|
+
# buffered before then.
|
|
713
|
+
for key in _TOOL_SPAN_CONTENT_PROPERTIES:
|
|
714
|
+
span.properties.pop(key, None)
|
|
715
|
+
resolved_id = self._resolve_distinct_id(span.distinct_id)
|
|
716
|
+
trace_id = span.properties["$ai_trace_id"]
|
|
605
717
|
self._capture_event(
|
|
606
718
|
"$ai_span",
|
|
607
|
-
properties,
|
|
719
|
+
span.properties,
|
|
608
720
|
resolved_id or trace_id,
|
|
609
|
-
groups,
|
|
721
|
+
span.groups,
|
|
610
722
|
personless=resolved_id is None,
|
|
611
|
-
options=extra_options,
|
|
723
|
+
options=span.extra_options,
|
|
612
724
|
)
|
|
613
725
|
|
|
614
726
|
def _emit_trace(
|
|
@@ -680,6 +792,14 @@ def _from_subagent(message: Any) -> bool:
|
|
|
680
792
|
return getattr(message, "parent_tool_use_id", None) is not None
|
|
681
793
|
|
|
682
794
|
|
|
795
|
+
def _tool_result_blocks(message: "UserMessage") -> List[Any]:
|
|
796
|
+
"""The ToolResultBlocks in a UserMessage."""
|
|
797
|
+
content = message.content
|
|
798
|
+
if not isinstance(content, list):
|
|
799
|
+
return []
|
|
800
|
+
return [block for block in content if hasattr(block, "tool_use_id")]
|
|
801
|
+
|
|
802
|
+
|
|
683
803
|
def _starts_generation(message: "StreamEvent") -> bool:
|
|
684
804
|
"""Whether a main-agent API call is starting (subagent calls are skipped)."""
|
|
685
805
|
return (
|
{posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/langchain/callbacks.py
RENAMED
|
@@ -8,7 +8,7 @@ except ImportError:
|
|
|
8
8
|
import json
|
|
9
9
|
import logging
|
|
10
10
|
import time
|
|
11
|
-
from dataclasses import dataclass
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
12
|
from typing import (
|
|
13
13
|
Any,
|
|
14
14
|
Dict,
|
|
@@ -72,6 +72,8 @@ class SpanMetadata:
|
|
|
72
72
|
"""End time of the run."""
|
|
73
73
|
input: Optional[Any]
|
|
74
74
|
"""Input of the run: messages, prompt variables, etc."""
|
|
75
|
+
span_type: Optional[str] = field(default=None, kw_only=True)
|
|
76
|
+
"""`$ai_span_type` of the run, e.g. "tool" for tool runs."""
|
|
75
77
|
|
|
76
78
|
@property
|
|
77
79
|
def latency(self) -> float:
|
|
@@ -303,7 +305,7 @@ class CallbackHandler(BaseCallbackHandler):
|
|
|
303
305
|
)
|
|
304
306
|
self._set_parent_of_run(run_id, parent_run_id)
|
|
305
307
|
self._set_trace_or_span_metadata(
|
|
306
|
-
serialized, input_str, run_id, parent_run_id, **kwargs
|
|
308
|
+
serialized, input_str, run_id, parent_run_id, span_type="tool", **kwargs
|
|
307
309
|
)
|
|
308
310
|
|
|
309
311
|
def on_tool_end(
|
|
@@ -461,12 +463,17 @@ class CallbackHandler(BaseCallbackHandler):
|
|
|
461
463
|
input: Any,
|
|
462
464
|
run_id: UUID,
|
|
463
465
|
parent_run_id: Optional[UUID] = None,
|
|
466
|
+
span_type: Optional[str] = None,
|
|
464
467
|
**kwargs,
|
|
465
468
|
):
|
|
466
469
|
default_name = "trace" if parent_run_id is None else "span"
|
|
467
470
|
run_name = _get_langchain_run_name(serialized, **kwargs) or default_name
|
|
468
471
|
self._runs[run_id] = SpanMetadata(
|
|
469
|
-
name=run_name,
|
|
472
|
+
name=run_name,
|
|
473
|
+
input=input,
|
|
474
|
+
start_time=time.time(),
|
|
475
|
+
end_time=None,
|
|
476
|
+
span_type=span_type,
|
|
470
477
|
)
|
|
471
478
|
|
|
472
479
|
def _set_llm_metadata(
|
|
@@ -575,6 +582,8 @@ class CallbackHandler(BaseCallbackHandler):
|
|
|
575
582
|
}
|
|
576
583
|
if parent_run_id is not None:
|
|
577
584
|
event_properties["$ai_parent_id"] = parent_run_id
|
|
585
|
+
if run.span_type is not None and event_name == "$ai_span":
|
|
586
|
+
event_properties["$ai_span_type"] = run.span_type
|
|
578
587
|
if self._properties:
|
|
579
588
|
event_properties.update(self._properties)
|
|
580
589
|
|
|
@@ -593,6 +602,20 @@ class CallbackHandler(BaseCallbackHandler):
|
|
|
593
602
|
self._privacy_mode,
|
|
594
603
|
finalize_ai_content(outputs, self._ph_client),
|
|
595
604
|
)
|
|
605
|
+
if (
|
|
606
|
+
run.span_type == "tool"
|
|
607
|
+
and isinstance(outputs, ToolMessage)
|
|
608
|
+
and outputs.status == "error"
|
|
609
|
+
):
|
|
610
|
+
# A tool error handled by `handle_tool_error` ends the run
|
|
611
|
+
# normally, with the error as a ToolMessage. Only the tool's own
|
|
612
|
+
# span is the error, not a chain that returns the message.
|
|
613
|
+
event_properties["$ai_is_error"] = True
|
|
614
|
+
event_properties["$ai_error"] = with_privacy_mode(
|
|
615
|
+
self._ph_client,
|
|
616
|
+
self._privacy_mode,
|
|
617
|
+
_tool_message_text(outputs),
|
|
618
|
+
)
|
|
596
619
|
|
|
597
620
|
_capture_ai_event(
|
|
598
621
|
self._ph_client,
|
|
@@ -847,6 +870,19 @@ def _convert_lc_tool_calls_to_oai(
|
|
|
847
870
|
return tool_calls
|
|
848
871
|
|
|
849
872
|
|
|
873
|
+
def _tool_message_text(message: ToolMessage) -> str:
|
|
874
|
+
"""The text of a ToolMessage, for `$ai_error`."""
|
|
875
|
+
content = message.content
|
|
876
|
+
if isinstance(content, str):
|
|
877
|
+
return content
|
|
878
|
+
texts = [
|
|
879
|
+
item if isinstance(item, str) else item.get("text", "")
|
|
880
|
+
for item in content
|
|
881
|
+
if isinstance(item, str) or isinstance(item, dict)
|
|
882
|
+
]
|
|
883
|
+
return "\n".join(text for text in texts if text)
|
|
884
|
+
|
|
885
|
+
|
|
850
886
|
def _convert_message_to_dict(message: BaseMessage) -> dict[str, Any]:
|
|
851
887
|
# assistant message
|
|
852
888
|
if isinstance(message, HumanMessage):
|
|
@@ -860,7 +896,15 @@ def _convert_message_to_dict(message: BaseMessage) -> dict[str, Any]:
|
|
|
860
896
|
elif isinstance(message, SystemMessage):
|
|
861
897
|
message_dict = {"role": "system", "content": message.content}
|
|
862
898
|
elif isinstance(message, ToolMessage):
|
|
863
|
-
message_dict = {
|
|
899
|
+
message_dict = {
|
|
900
|
+
"role": "tool",
|
|
901
|
+
"content": message.content,
|
|
902
|
+
"tool_call_id": message.tool_call_id,
|
|
903
|
+
}
|
|
904
|
+
if message.name:
|
|
905
|
+
message_dict["name"] = message.name
|
|
906
|
+
if message.status == "error":
|
|
907
|
+
message_dict["status"] = message.status
|
|
864
908
|
elif isinstance(message, FunctionMessage):
|
|
865
909
|
message_dict = {"role": "function", "content": message.content}
|
|
866
910
|
else:
|
{posthoganalytics-8.2.0 → posthoganalytics-8.2.2}/posthoganalytics/ai/openai_agents/processor.py
RENAMED
|
@@ -49,6 +49,13 @@ def _parse_iso_timestamp(iso_str: Optional[str]) -> Optional[float]:
|
|
|
49
49
|
return None
|
|
50
50
|
|
|
51
51
|
|
|
52
|
+
def _usage_count(usage: Any, key: str) -> Optional[int]:
|
|
53
|
+
"""Read a top-level token count from a usage dict or usage object."""
|
|
54
|
+
if isinstance(usage, dict):
|
|
55
|
+
return usage.get(key)
|
|
56
|
+
return getattr(usage, key, None) if usage else None
|
|
57
|
+
|
|
58
|
+
|
|
52
59
|
def _usage_detail(usage: Any, details_keys: tuple, key: str) -> Optional[int]:
|
|
53
60
|
"""Read a token count nested under a usage details field.
|
|
54
61
|
|
|
@@ -733,13 +740,17 @@ class PostHogTracingProcessor(TracingProcessor):
|
|
|
733
740
|
response = span_data.response
|
|
734
741
|
response_id = response.id if response else None
|
|
735
742
|
|
|
736
|
-
# Try to extract usage from response
|
|
743
|
+
# Try to extract usage from response. With trace_include_sensitive_data
|
|
744
|
+
# off the SDK leaves the response unset but still records usage on the
|
|
745
|
+
# span, as a dict of the same shape.
|
|
737
746
|
usage = getattr(response, "usage", None) if response else None
|
|
747
|
+
if usage is None:
|
|
748
|
+
usage = getattr(span_data, "usage", None)
|
|
738
749
|
total_cost_usd = getattr(usage, "cost", None) if usage else None
|
|
739
750
|
# None when the response never reported a count: absent means unknown,
|
|
740
751
|
# 0 is a report of nothing.
|
|
741
|
-
input_tokens =
|
|
742
|
-
output_tokens =
|
|
752
|
+
input_tokens = _usage_count(usage, "input_tokens")
|
|
753
|
+
output_tokens = _usage_count(usage, "output_tokens")
|
|
743
754
|
|
|
744
755
|
# Try to extract model from response
|
|
745
756
|
model = getattr(response, "model", None) if response else None
|