posthoganalytics 7.5.1__tar.gz → 7.7.0__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-7.5.1/posthoganalytics.egg-info → posthoganalytics-7.7.0}/PKG-INFO +1 -1
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/__init__.py +35 -0
- posthoganalytics-7.7.0/posthoganalytics/ai/openai_agents/__init__.py +76 -0
- posthoganalytics-7.7.0/posthoganalytics/ai/openai_agents/processor.py +863 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/client.py +38 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/contexts.py +44 -0
- posthoganalytics-7.7.0/posthoganalytics/test/ai/__init__.py +0 -0
- posthoganalytics-7.7.0/posthoganalytics/test/ai/openai_agents/__init__.py +1 -0
- posthoganalytics-7.7.0/posthoganalytics/test/ai/openai_agents/test_processor.py +810 -0
- posthoganalytics-7.7.0/posthoganalytics/test/ai/test_sanitization.py +522 -0
- posthoganalytics-7.7.0/posthoganalytics/test/ai/test_system_prompts.py +363 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_client.py +115 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/version.py +1 -1
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0/posthoganalytics.egg-info}/PKG-INFO +1 -1
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics.egg-info/SOURCES.txt +8 -1
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/pyproject.toml +3 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/LICENSE +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/MANIFEST.in +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/README.md +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/__init__.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/anthropic/__init__.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/anthropic/anthropic.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/anthropic/anthropic_async.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/anthropic/anthropic_converter.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/anthropic/anthropic_providers.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/gemini/__init__.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/gemini/gemini.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/gemini/gemini_async.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/gemini/gemini_converter.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/langchain/__init__.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/langchain/callbacks.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/openai/__init__.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/openai/openai.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/openai/openai_async.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/openai/openai_converter.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/openai/openai_providers.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/sanitization.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/types.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/ai/utils.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/args.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/consumer.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/exception_capture.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/exception_utils.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/feature_flags.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/flag_definition_cache.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/integrations/__init__.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/integrations/django.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/poller.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/py.typed +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/request.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/__init__.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_before_send.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_consumer.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_contexts.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_exception_capture.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_feature_flag.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_feature_flag_result.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_feature_flags.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_flag_definition_cache.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_module.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_request.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_size_limited_dict.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_types.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/test/test_utils.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/types.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics/utils.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics.egg-info/dependency_links.txt +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics.egg-info/requires.txt +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/posthoganalytics.egg-info/top_level.txt +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/setup.cfg +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/setup.py +0 -0
- {posthoganalytics-7.5.1 → posthoganalytics-7.7.0}/setup_analytics.py +0 -0
|
@@ -23,6 +23,9 @@ from posthoganalytics.contexts import (
|
|
|
23
23
|
from posthoganalytics.contexts import (
|
|
24
24
|
set_code_variables_mask_patterns_context as inner_set_code_variables_mask_patterns_context,
|
|
25
25
|
)
|
|
26
|
+
from posthoganalytics.contexts import (
|
|
27
|
+
set_context_device_id as inner_set_context_device_id,
|
|
28
|
+
)
|
|
26
29
|
from posthoganalytics.contexts import (
|
|
27
30
|
set_context_session as inner_set_context_session,
|
|
28
31
|
)
|
|
@@ -133,6 +136,26 @@ def set_context_session(session_id: str):
|
|
|
133
136
|
return inner_set_context_session(session_id)
|
|
134
137
|
|
|
135
138
|
|
|
139
|
+
def set_context_device_id(device_id: str):
|
|
140
|
+
"""
|
|
141
|
+
Set the device ID for the current context, associating all feature flag requests
|
|
142
|
+
in this or child contexts with the given device ID.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
device_id: The device ID to associate with the current context and its children
|
|
146
|
+
|
|
147
|
+
Examples:
|
|
148
|
+
```python
|
|
149
|
+
from posthoganalytics import set_context_device_id
|
|
150
|
+
set_context_device_id("device_123")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Category:
|
|
154
|
+
Contexts
|
|
155
|
+
"""
|
|
156
|
+
return inner_set_context_device_id(device_id)
|
|
157
|
+
|
|
158
|
+
|
|
136
159
|
def identify_context(distinct_id: str):
|
|
137
160
|
"""
|
|
138
161
|
Identify the current context with a distinct ID.
|
|
@@ -483,6 +506,7 @@ def feature_enabled(
|
|
|
483
506
|
only_evaluate_locally=False, # type: bool
|
|
484
507
|
send_feature_flag_events=True, # type: bool
|
|
485
508
|
disable_geoip=None, # type: Optional[bool]
|
|
509
|
+
device_id=None, # type: Optional[str]
|
|
486
510
|
):
|
|
487
511
|
# type: (...) -> bool
|
|
488
512
|
"""
|
|
@@ -522,6 +546,7 @@ def feature_enabled(
|
|
|
522
546
|
only_evaluate_locally=only_evaluate_locally,
|
|
523
547
|
send_feature_flag_events=send_feature_flag_events,
|
|
524
548
|
disable_geoip=disable_geoip,
|
|
549
|
+
device_id=device_id,
|
|
525
550
|
)
|
|
526
551
|
|
|
527
552
|
|
|
@@ -534,6 +559,7 @@ def get_feature_flag(
|
|
|
534
559
|
only_evaluate_locally=False, # type: bool
|
|
535
560
|
send_feature_flag_events=True, # type: bool
|
|
536
561
|
disable_geoip=None, # type: Optional[bool]
|
|
562
|
+
device_id=None, # type: Optional[str]
|
|
537
563
|
) -> Optional[FeatureFlag]:
|
|
538
564
|
"""
|
|
539
565
|
Get feature flag variant for users. Used with experiments.
|
|
@@ -572,6 +598,7 @@ def get_feature_flag(
|
|
|
572
598
|
only_evaluate_locally=only_evaluate_locally,
|
|
573
599
|
send_feature_flag_events=send_feature_flag_events,
|
|
574
600
|
disable_geoip=disable_geoip,
|
|
601
|
+
device_id=device_id,
|
|
575
602
|
)
|
|
576
603
|
|
|
577
604
|
|
|
@@ -582,6 +609,7 @@ def get_all_flags(
|
|
|
582
609
|
group_properties=None, # type: Optional[dict]
|
|
583
610
|
only_evaluate_locally=False, # type: bool
|
|
584
611
|
disable_geoip=None, # type: Optional[bool]
|
|
612
|
+
device_id=None, # type: Optional[str]
|
|
585
613
|
) -> Optional[dict[str, FeatureFlag]]:
|
|
586
614
|
"""
|
|
587
615
|
Get all flags for a given user.
|
|
@@ -614,6 +642,7 @@ def get_all_flags(
|
|
|
614
642
|
group_properties=group_properties or {},
|
|
615
643
|
only_evaluate_locally=only_evaluate_locally,
|
|
616
644
|
disable_geoip=disable_geoip,
|
|
645
|
+
device_id=device_id,
|
|
617
646
|
)
|
|
618
647
|
|
|
619
648
|
|
|
@@ -626,6 +655,7 @@ def get_feature_flag_result(
|
|
|
626
655
|
only_evaluate_locally=False,
|
|
627
656
|
send_feature_flag_events=True,
|
|
628
657
|
disable_geoip=None, # type: Optional[bool]
|
|
658
|
+
device_id=None, # type: Optional[str]
|
|
629
659
|
):
|
|
630
660
|
# type: (...) -> Optional[FeatureFlagResult]
|
|
631
661
|
"""
|
|
@@ -657,6 +687,7 @@ def get_feature_flag_result(
|
|
|
657
687
|
only_evaluate_locally=only_evaluate_locally,
|
|
658
688
|
send_feature_flag_events=send_feature_flag_events,
|
|
659
689
|
disable_geoip=disable_geoip,
|
|
690
|
+
device_id=device_id,
|
|
660
691
|
)
|
|
661
692
|
|
|
662
693
|
|
|
@@ -670,6 +701,7 @@ def get_feature_flag_payload(
|
|
|
670
701
|
only_evaluate_locally=False,
|
|
671
702
|
send_feature_flag_events=True,
|
|
672
703
|
disable_geoip=None, # type: Optional[bool]
|
|
704
|
+
device_id=None, # type: Optional[str]
|
|
673
705
|
) -> Optional[str]:
|
|
674
706
|
return _proxy(
|
|
675
707
|
"get_feature_flag_payload",
|
|
@@ -682,6 +714,7 @@ def get_feature_flag_payload(
|
|
|
682
714
|
only_evaluate_locally=only_evaluate_locally,
|
|
683
715
|
send_feature_flag_events=send_feature_flag_events,
|
|
684
716
|
disable_geoip=disable_geoip,
|
|
717
|
+
device_id=device_id,
|
|
685
718
|
)
|
|
686
719
|
|
|
687
720
|
|
|
@@ -712,6 +745,7 @@ def get_all_flags_and_payloads(
|
|
|
712
745
|
group_properties=None, # type: Optional[dict]
|
|
713
746
|
only_evaluate_locally=False,
|
|
714
747
|
disable_geoip=None, # type: Optional[bool]
|
|
748
|
+
device_id=None, # type: Optional[str]
|
|
715
749
|
) -> FlagsAndPayloads:
|
|
716
750
|
return _proxy(
|
|
717
751
|
"get_all_flags_and_payloads",
|
|
@@ -721,6 +755,7 @@ def get_all_flags_and_payloads(
|
|
|
721
755
|
group_properties=group_properties or {},
|
|
722
756
|
only_evaluate_locally=only_evaluate_locally,
|
|
723
757
|
disable_geoip=disable_geoip,
|
|
758
|
+
device_id=device_id,
|
|
724
759
|
)
|
|
725
760
|
|
|
726
761
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from agents.tracing import Trace
|
|
7
|
+
|
|
8
|
+
from posthoganalytics.client import Client
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
import agents # noqa: F401
|
|
12
|
+
except ImportError:
|
|
13
|
+
raise ModuleNotFoundError(
|
|
14
|
+
"Please install the OpenAI Agents SDK to use this feature: 'pip install openai-agents'"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from posthoganalytics.ai.openai_agents.processor import PostHogTracingProcessor
|
|
18
|
+
|
|
19
|
+
__all__ = ["PostHogTracingProcessor", "instrument"]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def instrument(
|
|
23
|
+
client: Optional[Client] = None,
|
|
24
|
+
distinct_id: Optional[Union[str, Callable[[Trace], Optional[str]]]] = None,
|
|
25
|
+
privacy_mode: bool = False,
|
|
26
|
+
groups: Optional[Dict[str, Any]] = None,
|
|
27
|
+
properties: Optional[Dict[str, Any]] = None,
|
|
28
|
+
) -> PostHogTracingProcessor:
|
|
29
|
+
"""
|
|
30
|
+
One-liner to instrument OpenAI Agents SDK with PostHog tracing.
|
|
31
|
+
|
|
32
|
+
This registers a PostHogTracingProcessor with the OpenAI Agents SDK,
|
|
33
|
+
automatically capturing traces, spans, and LLM generations.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
client: Optional PostHog client instance. If not provided, uses the default client.
|
|
37
|
+
distinct_id: Optional distinct ID to associate with all traces.
|
|
38
|
+
Can also be a callable that takes a trace and returns a distinct ID.
|
|
39
|
+
privacy_mode: If True, redacts input/output content from events.
|
|
40
|
+
groups: Optional PostHog groups to associate with events.
|
|
41
|
+
properties: Optional additional properties to include with all events.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
PostHogTracingProcessor: The registered processor instance.
|
|
45
|
+
|
|
46
|
+
Example:
|
|
47
|
+
```python
|
|
48
|
+
from posthoganalytics.ai.openai_agents import instrument
|
|
49
|
+
|
|
50
|
+
# Simple setup
|
|
51
|
+
instrument(distinct_id="user@example.com")
|
|
52
|
+
|
|
53
|
+
# With custom properties
|
|
54
|
+
instrument(
|
|
55
|
+
distinct_id="user@example.com",
|
|
56
|
+
privacy_mode=True,
|
|
57
|
+
properties={"environment": "production"}
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Now run agents as normal - traces automatically sent to PostHog
|
|
61
|
+
from agents import Agent, Runner
|
|
62
|
+
agent = Agent(name="Assistant", instructions="You are helpful.")
|
|
63
|
+
result = Runner.run_sync(agent, "Hello!")
|
|
64
|
+
```
|
|
65
|
+
"""
|
|
66
|
+
from agents.tracing import add_trace_processor
|
|
67
|
+
|
|
68
|
+
processor = PostHogTracingProcessor(
|
|
69
|
+
client=client,
|
|
70
|
+
distinct_id=distinct_id,
|
|
71
|
+
privacy_mode=privacy_mode,
|
|
72
|
+
groups=groups,
|
|
73
|
+
properties=properties,
|
|
74
|
+
)
|
|
75
|
+
add_trace_processor(processor)
|
|
76
|
+
return processor
|