posthog 7.4.1__py3-none-any.whl → 7.4.3__py3-none-any.whl
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.
- posthog/__init__.py +27 -6
- posthog/ai/langchain/callbacks.py +11 -9
- posthog/client.py +19 -16
- posthog/exception_utils.py +3 -3
- posthog/version.py +1 -1
- {posthog-7.4.1.dist-info → posthog-7.4.3.dist-info}/METADATA +1 -1
- {posthog-7.4.1.dist-info → posthog-7.4.3.dist-info}/RECORD +10 -10
- {posthog-7.4.1.dist-info → posthog-7.4.3.dist-info}/WHEEL +0 -0
- {posthog-7.4.1.dist-info → posthog-7.4.3.dist-info}/licenses/LICENSE +0 -0
- {posthog-7.4.1.dist-info → posthog-7.4.3.dist-info}/top_level.txt +0 -0
posthog/__init__.py
CHANGED
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
import datetime # noqa: F401
|
|
2
|
-
from typing import Callable, Dict, Optional
|
|
2
|
+
from typing import Any, Callable, Dict, Optional # noqa: F401
|
|
3
|
+
|
|
3
4
|
from typing_extensions import Unpack
|
|
4
5
|
|
|
5
|
-
from posthog.args import OptionalCaptureArgs, OptionalSetArgs
|
|
6
|
+
from posthog.args import ExceptionArg, OptionalCaptureArgs, OptionalSetArgs
|
|
6
7
|
from posthog.client import Client
|
|
8
|
+
from posthog.contexts import (
|
|
9
|
+
identify_context as inner_identify_context,
|
|
10
|
+
)
|
|
7
11
|
from posthog.contexts import (
|
|
8
12
|
new_context as inner_new_context,
|
|
13
|
+
)
|
|
14
|
+
from posthog.contexts import (
|
|
9
15
|
scoped as inner_scoped,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
identify_context as inner_identify_context,
|
|
16
|
+
)
|
|
17
|
+
from posthog.contexts import (
|
|
13
18
|
set_capture_exception_code_variables_context as inner_set_capture_exception_code_variables_context,
|
|
14
|
-
|
|
19
|
+
)
|
|
20
|
+
from posthog.contexts import (
|
|
15
21
|
set_code_variables_ignore_patterns_context as inner_set_code_variables_ignore_patterns_context,
|
|
16
22
|
)
|
|
23
|
+
from posthog.contexts import (
|
|
24
|
+
set_code_variables_mask_patterns_context as inner_set_code_variables_mask_patterns_context,
|
|
25
|
+
)
|
|
26
|
+
from posthog.contexts import (
|
|
27
|
+
set_context_session as inner_set_context_session,
|
|
28
|
+
)
|
|
29
|
+
from posthog.contexts import (
|
|
30
|
+
tag as inner_tag,
|
|
31
|
+
)
|
|
17
32
|
from posthog.exception_utils import (
|
|
18
33
|
DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS,
|
|
19
34
|
DEFAULT_CODE_VARIABLES_MASK_PATTERNS,
|
|
20
35
|
)
|
|
21
36
|
from posthog.feature_flags import (
|
|
22
37
|
InconclusiveMatchError as InconclusiveMatchError,
|
|
38
|
+
)
|
|
39
|
+
from posthog.feature_flags import (
|
|
23
40
|
RequiresServerEvaluation as RequiresServerEvaluation,
|
|
24
41
|
)
|
|
25
42
|
from posthog.flag_definition_cache import (
|
|
@@ -35,6 +52,8 @@ from posthog.request import (
|
|
|
35
52
|
from posthog.types import (
|
|
36
53
|
FeatureFlag,
|
|
37
54
|
FlagsAndPayloads,
|
|
55
|
+
)
|
|
56
|
+
from posthog.types import (
|
|
38
57
|
FeatureFlagResult as FeatureFlagResult,
|
|
39
58
|
)
|
|
40
59
|
from posthog.version import VERSION
|
|
@@ -201,6 +220,7 @@ default_client = None # type: Optional[Client]
|
|
|
201
220
|
capture_exception_code_variables = False
|
|
202
221
|
code_variables_mask_patterns = DEFAULT_CODE_VARIABLES_MASK_PATTERNS
|
|
203
222
|
code_variables_ignore_patterns = DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS
|
|
223
|
+
in_app_modules = None # type: Optional[list[str]]
|
|
204
224
|
|
|
205
225
|
|
|
206
226
|
# NOTE - this and following functions take unpacked kwargs because we needed to make
|
|
@@ -799,6 +819,7 @@ def setup() -> Client:
|
|
|
799
819
|
capture_exception_code_variables=capture_exception_code_variables,
|
|
800
820
|
code_variables_mask_patterns=code_variables_mask_patterns,
|
|
801
821
|
code_variables_ignore_patterns=code_variables_ignore_patterns,
|
|
822
|
+
in_app_modules=in_app_modules,
|
|
802
823
|
)
|
|
803
824
|
|
|
804
825
|
# always set incase user changes it
|
|
@@ -773,9 +773,11 @@ def _parse_usage_model(
|
|
|
773
773
|
for mapped_key, dataclass_key in field_mapping.items()
|
|
774
774
|
},
|
|
775
775
|
)
|
|
776
|
-
# For Anthropic providers, LangChain reports input_tokens as the sum of input
|
|
776
|
+
# For Anthropic providers, LangChain reports input_tokens as the sum of all input tokens.
|
|
777
777
|
# Our cost calculation expects them to be separate for Anthropic, so we subtract cache tokens.
|
|
778
|
-
#
|
|
778
|
+
# Both cache_read and cache_write tokens should be subtracted since Anthropic's raw API
|
|
779
|
+
# reports input_tokens as tokens NOT read from or used to create a cache.
|
|
780
|
+
# For other providers (OpenAI, etc.), input_tokens already excludes cache tokens as expected.
|
|
779
781
|
# Match logic consistent with plugin-server: exact match on provider OR substring match on model
|
|
780
782
|
is_anthropic = False
|
|
781
783
|
if provider and provider.lower() == "anthropic":
|
|
@@ -783,14 +785,14 @@ def _parse_usage_model(
|
|
|
783
785
|
elif model and "anthropic" in model.lower():
|
|
784
786
|
is_anthropic = True
|
|
785
787
|
|
|
786
|
-
if
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
and normalized_usage.cache_read_tokens
|
|
790
|
-
):
|
|
791
|
-
normalized_usage.input_tokens = max(
|
|
792
|
-
normalized_usage.input_tokens - normalized_usage.cache_read_tokens, 0
|
|
788
|
+
if is_anthropic and normalized_usage.input_tokens:
|
|
789
|
+
cache_tokens = (normalized_usage.cache_read_tokens or 0) + (
|
|
790
|
+
normalized_usage.cache_write_tokens or 0
|
|
793
791
|
)
|
|
792
|
+
if cache_tokens > 0:
|
|
793
|
+
normalized_usage.input_tokens = max(
|
|
794
|
+
normalized_usage.input_tokens - cache_tokens, 0
|
|
795
|
+
)
|
|
794
796
|
return normalized_usage
|
|
795
797
|
|
|
796
798
|
|
posthog/client.py
CHANGED
|
@@ -5,24 +5,33 @@ import sys
|
|
|
5
5
|
import warnings
|
|
6
6
|
from datetime import datetime, timedelta
|
|
7
7
|
from typing import Any, Dict, Optional, Union
|
|
8
|
-
from typing_extensions import Unpack
|
|
9
8
|
from uuid import uuid4
|
|
10
9
|
|
|
11
10
|
from dateutil.tz import tzutc
|
|
12
11
|
from six import string_types
|
|
12
|
+
from typing_extensions import Unpack
|
|
13
13
|
|
|
14
|
-
from posthog.args import
|
|
14
|
+
from posthog.args import ID_TYPES, ExceptionArg, OptionalCaptureArgs, OptionalSetArgs
|
|
15
15
|
from posthog.consumer import Consumer
|
|
16
|
+
from posthog.contexts import (
|
|
17
|
+
_get_current_context,
|
|
18
|
+
get_capture_exception_code_variables_context,
|
|
19
|
+
get_code_variables_ignore_patterns_context,
|
|
20
|
+
get_code_variables_mask_patterns_context,
|
|
21
|
+
get_context_distinct_id,
|
|
22
|
+
get_context_session_id,
|
|
23
|
+
new_context,
|
|
24
|
+
)
|
|
16
25
|
from posthog.exception_capture import ExceptionCapture
|
|
17
26
|
from posthog.exception_utils import (
|
|
27
|
+
DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS,
|
|
28
|
+
DEFAULT_CODE_VARIABLES_MASK_PATTERNS,
|
|
18
29
|
exc_info_from_error,
|
|
30
|
+
exception_is_already_captured,
|
|
19
31
|
exceptions_from_error_tuple,
|
|
20
32
|
handle_in_app,
|
|
21
|
-
exception_is_already_captured,
|
|
22
33
|
mark_exception_as_captured,
|
|
23
34
|
try_attach_code_variables_to_frames,
|
|
24
|
-
DEFAULT_CODE_VARIABLES_MASK_PATTERNS,
|
|
25
|
-
DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS,
|
|
26
35
|
)
|
|
27
36
|
from posthog.feature_flags import (
|
|
28
37
|
InconclusiveMatchError,
|
|
@@ -46,15 +55,6 @@ from posthog.request import (
|
|
|
46
55
|
get,
|
|
47
56
|
remote_config,
|
|
48
57
|
)
|
|
49
|
-
from posthog.contexts import (
|
|
50
|
-
_get_current_context,
|
|
51
|
-
get_context_distinct_id,
|
|
52
|
-
get_context_session_id,
|
|
53
|
-
get_capture_exception_code_variables_context,
|
|
54
|
-
get_code_variables_mask_patterns_context,
|
|
55
|
-
get_code_variables_ignore_patterns_context,
|
|
56
|
-
new_context,
|
|
57
|
-
)
|
|
58
58
|
from posthog.types import (
|
|
59
59
|
FeatureFlag,
|
|
60
60
|
FeatureFlagError,
|
|
@@ -197,6 +197,7 @@ class Client(object):
|
|
|
197
197
|
capture_exception_code_variables=False,
|
|
198
198
|
code_variables_mask_patterns=None,
|
|
199
199
|
code_variables_ignore_patterns=None,
|
|
200
|
+
in_app_modules: list[str] | None = None,
|
|
200
201
|
):
|
|
201
202
|
"""
|
|
202
203
|
Initialize a new PostHog client instance.
|
|
@@ -265,6 +266,7 @@ class Client(object):
|
|
|
265
266
|
if code_variables_ignore_patterns is not None
|
|
266
267
|
else DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS
|
|
267
268
|
)
|
|
269
|
+
self.in_app_modules = in_app_modules
|
|
268
270
|
|
|
269
271
|
if project_root is None:
|
|
270
272
|
try:
|
|
@@ -998,6 +1000,7 @@ class Client(object):
|
|
|
998
1000
|
"values": all_exceptions_with_trace,
|
|
999
1001
|
},
|
|
1000
1002
|
},
|
|
1003
|
+
in_app_include=self.in_app_modules,
|
|
1001
1004
|
project_root=self.project_root,
|
|
1002
1005
|
)
|
|
1003
1006
|
all_exceptions_with_trace_and_in_app = event["exception"]["values"]
|
|
@@ -2182,9 +2185,9 @@ class Client(object):
|
|
|
2182
2185
|
return None
|
|
2183
2186
|
|
|
2184
2187
|
try:
|
|
2185
|
-
from urllib.parse import
|
|
2188
|
+
from urllib.parse import parse_qs, urlparse
|
|
2186
2189
|
except ImportError:
|
|
2187
|
-
from urlparse import
|
|
2190
|
+
from urlparse import parse_qs, urlparse
|
|
2188
2191
|
|
|
2189
2192
|
try:
|
|
2190
2193
|
parsed = urlparse(cache_url)
|
posthog/exception_utils.py
CHANGED
|
@@ -14,23 +14,23 @@ import types
|
|
|
14
14
|
from datetime import datetime
|
|
15
15
|
from types import FrameType, TracebackType # noqa: F401
|
|
16
16
|
from typing import ( # noqa: F401
|
|
17
|
+
TYPE_CHECKING,
|
|
17
18
|
Any,
|
|
18
19
|
Dict,
|
|
19
20
|
Iterator,
|
|
20
21
|
List,
|
|
21
22
|
Literal,
|
|
22
23
|
Optional,
|
|
24
|
+
Pattern,
|
|
23
25
|
Set,
|
|
24
26
|
Tuple,
|
|
25
27
|
TypedDict,
|
|
26
28
|
TypeVar,
|
|
27
29
|
Union,
|
|
28
30
|
cast,
|
|
29
|
-
TYPE_CHECKING,
|
|
30
|
-
Pattern,
|
|
31
31
|
)
|
|
32
32
|
|
|
33
|
-
from posthog.args import
|
|
33
|
+
from posthog.args import ExceptionArg, ExcInfo # noqa: F401
|
|
34
34
|
|
|
35
35
|
try:
|
|
36
36
|
# Python 3.11
|
posthog/version.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
posthog/__init__.py,sha256=
|
|
1
|
+
posthog/__init__.py,sha256=FuDzRpIFTj_xdX6cOvq0yQ5OQTk9pB8R-mo3XXigILw,28436
|
|
2
2
|
posthog/args.py,sha256=JUt0vbtF33IzLt3ARgsxMEYYnZo3RNS_LcK4-CjWaco,3298
|
|
3
|
-
posthog/client.py,sha256=
|
|
3
|
+
posthog/client.py,sha256=u8wpxTN_Vc6InJUK-GI_620aCQ9LgiWZ6j76rqjfZH4,82233
|
|
4
4
|
posthog/consumer.py,sha256=fdteMZ-deJGMpaQmHyznw_cwQG2Vvld1tmN9LUkZPrY,4608
|
|
5
5
|
posthog/contexts.py,sha256=22z4KySFCTwPbz4OYsd_8EJpoc2H91NiLq9cscSvFfw,12600
|
|
6
6
|
posthog/exception_capture.py,sha256=pmKtjQ6QY6zs4u_-ZA4H1gCyR3iI4sfqCQG_jwe_bKo,1774
|
|
7
|
-
posthog/exception_utils.py,sha256=
|
|
7
|
+
posthog/exception_utils.py,sha256=AsFNhFQdeJG1sNJMsCQ4hy6Hjhvq_fOGSAGHVBGpXig,33738
|
|
8
8
|
posthog/feature_flags.py,sha256=4xAcYEpa97b5Lv9bIo5JHbCO6lhYBnH5EmJ2MrjbU3k,22517
|
|
9
9
|
posthog/flag_definition_cache.py,sha256=3LnB76BAU29FmypxagkqTpEW6MfjQQTw3E_xWJ679XQ,4697
|
|
10
10
|
posthog/poller.py,sha256=jBz5rfH_kn_bBz7wCB46Fpvso4ttx4uzqIZWvXBCFmQ,595
|
|
@@ -12,7 +12,7 @@ posthog/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
12
12
|
posthog/request.py,sha256=_WdffuI4BgRL9UvbEEi-4uxpFW3P4h7PRDpYM0lawVU,11817
|
|
13
13
|
posthog/types.py,sha256=OxGHSmmhVYwA7ecmJXUznDCZ1c4gAGtERzSLSYlyQFM,11540
|
|
14
14
|
posthog/utils.py,sha256=-0w-OLcCaoldkbBebPzQyBzLJSo9G9yBOg8NDVz7La8,16088
|
|
15
|
-
posthog/version.py,sha256=
|
|
15
|
+
posthog/version.py,sha256=vihsF6dgxiEGLdqc-3-Px5vakdaHbsft_z_qZYnNwQ8,87
|
|
16
16
|
posthog/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
17
|
posthog/ai/sanitization.py,sha256=Dpx_5gKZfDS38KjmK1C0lvvjm9N8Pp_oIxusac888-g,6057
|
|
18
18
|
posthog/ai/types.py,sha256=arX98hR1PIPeJ3vFikxTlACIh1xPp6aEUw1gBLcKoB0,3273
|
|
@@ -27,7 +27,7 @@ posthog/ai/gemini/gemini.py,sha256=RmmHriUoc2APrZtQiw63hJzBka0H-B3jYH29clxpciw,1
|
|
|
27
27
|
posthog/ai/gemini/gemini_async.py,sha256=0UFk6ZHuG_F7dkw028BTyGybTpPvIKSNfw0yI_LciOM,15108
|
|
28
28
|
posthog/ai/gemini/gemini_converter.py,sha256=JptTOV98s3V0jPKKHVRktze1i0RaSbkkOT0GLxkt2Gk,21801
|
|
29
29
|
posthog/ai/langchain/__init__.py,sha256=9CqAwLynTGj3ASAR80C3PmdTdrYGmu99tz0JL-HPFgI,70
|
|
30
|
-
posthog/ai/langchain/callbacks.py,sha256=
|
|
30
|
+
posthog/ai/langchain/callbacks.py,sha256=ybSGvopspa9Ourk3CJxIioof_qTpTREiVkcaif4HMt4,31606
|
|
31
31
|
posthog/ai/openai/__init__.py,sha256=u4OuUT7k1NgFj0TrxjuyegOg7a_UA8nAU6a-Hszr0OM,490
|
|
32
32
|
posthog/ai/openai/openai.py,sha256=HWqd-uL0cRqwXVE06enRjqnxvIIxc-b_JLI41aimX6A,21324
|
|
33
33
|
posthog/ai/openai/openai_async.py,sha256=b-65PQkIvYaA-AMOBorENL_wa3vh5c5pdSGPG29Nn2s,23655
|
|
@@ -50,8 +50,8 @@ posthog/test/test_request.py,sha256=vrZSayStAAcTr05h2ci3Y8qmKDIV2umBdiJqhr3NPp0,
|
|
|
50
50
|
posthog/test/test_size_limited_dict.py,sha256=Wom7BkzpHmusHilZy0SV3PNzhw7ucuQgqrx86jf8euo,765
|
|
51
51
|
posthog/test/test_types.py,sha256=csLuBiz6RMV36cpg9LVIor4Khq6MfjjGxYXodx5VttY,7586
|
|
52
52
|
posthog/test/test_utils.py,sha256=YqAnXaMHxzEV_D3AHhs-RXnZYzdEN7kdIlpOT6Ti6t0,9714
|
|
53
|
-
posthog-7.4.
|
|
54
|
-
posthog-7.4.
|
|
55
|
-
posthog-7.4.
|
|
56
|
-
posthog-7.4.
|
|
57
|
-
posthog-7.4.
|
|
53
|
+
posthog-7.4.3.dist-info/licenses/LICENSE,sha256=wGf9JBotDkSygFj43m49oiKlFnpMnn97keiZKF-40vE,2450
|
|
54
|
+
posthog-7.4.3.dist-info/METADATA,sha256=r43oVzca9cIo2QbKMGgHdd7OBSZaNMo5eeAd5KBVRp8,6010
|
|
55
|
+
posthog-7.4.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
56
|
+
posthog-7.4.3.dist-info/top_level.txt,sha256=7FBLsRjIUHVKQsXIhozuI3k-mun1tapp8iZO9EmUPEw,8
|
|
57
|
+
posthog-7.4.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|