Skip to content

Commit 48c2e77

Browse files
committed
Merge branch 'master' into dn-chore/update-license
2 parents c46c3d2 + 51380ac commit 48c2e77

21 files changed

+1554
-220
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
## 3.24.0 – 2025-04-10
2+
3+
1. Add config option to `log_captured_exceptions`
4+
5+
## 3.23.0 – 2025-03-26
6+
7+
1. Expand automatic retries to include read errors (e.g. RemoteDisconnected)
8+
9+
## 3.22.0 – 2025-03-26
10+
11+
1. Add more information to `$feature_flag_called` events.
12+
2. Support for the `/decide?v=3` endpoint which contains more information about feature flags.
13+
14+
## 3.21.0 – 2025-03-17
15+
16+
1. Support serializing dataclasses.
17+
18+
## 3.20.0 – 2025-03-13
19+
20+
1. Add support for OpenAI Responses API.
21+
122
## 3.19.2 – 2025-03-11
223

324
1. Fix install requirements for analytics package

mypy-baseline.txt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,7 @@ posthog/sentry/posthog_integration.py:0: error: Statement is unreachable [unrea
3535
posthog/ai/utils.py:0: error: Need type annotation for "output" (hint: "output: list[<type>] = ...") [var-annotated]
3636
posthog/ai/utils.py:0: error: Function "builtins.any" is not valid as a type [valid-type]
3737
posthog/ai/utils.py:0: note: Perhaps you meant "typing.Any" instead of "any"?
38-
posthog/ai/utils.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
3938
posthog/ai/utils.py:0: error: Function "builtins.any" is not valid as a type [valid-type]
4039
posthog/ai/utils.py:0: note: Perhaps you meant "typing.Any" instead of "any"?
41-
posthog/ai/utils.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
4240
sentry_django_example/sentry_django_example/settings.py:0: error: Need type annotation for "ALLOWED_HOSTS" (hint: "ALLOWED_HOSTS: list[<type>] = ...") [var-annotated]
43-
sentry_django_example/sentry_django_example/settings.py:0: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
44-
posthog/ai/openai/openai_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
45-
posthog/ai/openai/openai_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
46-
posthog/ai/openai/openai_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
47-
posthog/ai/openai/openai.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
48-
posthog/ai/openai/openai.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
49-
posthog/ai/openai/openai.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
50-
posthog/ai/anthropic/anthropic_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
51-
posthog/ai/anthropic/anthropic_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
52-
posthog/ai/anthropic/anthropic_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
53-
posthog/ai/anthropic/anthropic.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
54-
posthog/ai/anthropic/anthropic.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
55-
posthog/ai/anthropic/anthropic.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
41+
sentry_django_example/sentry_django_example/settings.py:0: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]

posthog/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from posthog.client import Client
66
from posthog.exception_capture import Integrations # noqa: F401
7+
from posthog.types import FeatureFlag, FlagsAndPayloads
78
from posthog.version import VERSION
89

910
__version__ = VERSION
@@ -313,6 +314,7 @@ def capture_exception(
313314
timestamp=None, # type: Optional[datetime.datetime]
314315
uuid=None, # type: Optional[str]
315316
groups=None, # type: Optional[Dict]
317+
**kwargs
316318
):
317319
# type: (...) -> Tuple[bool, dict]
318320
"""
@@ -326,6 +328,7 @@ def capture_exception(
326328
Optionally you can submit
327329
- `properties`, which can be a dict with any information you'd like to add
328330
- `groups`, which is a dict of group type -> group key mappings
331+
- remaining `kwargs` will be logged if `log_captured_exceptions` is enabled
329332
330333
For example:
331334
```python
@@ -354,6 +357,7 @@ def capture_exception(
354357
timestamp=timestamp,
355358
uuid=uuid,
356359
groups=groups,
360+
**kwargs
357361
)
358362

359363

@@ -403,7 +407,7 @@ def get_feature_flag(
403407
only_evaluate_locally=False, # type: bool
404408
send_feature_flag_events=True, # type: bool
405409
disable_geoip=None, # type: Optional[bool]
406-
):
410+
) -> Optional[FeatureFlag]:
407411
"""
408412
Get feature flag variant for users. Used with experiments.
409413
Example:
@@ -446,7 +450,7 @@ def get_all_flags(
446450
group_properties={}, # type: dict
447451
only_evaluate_locally=False, # type: bool
448452
disable_geoip=None, # type: Optional[bool]
449-
):
453+
) -> Optional[dict[str, FeatureFlag]]:
450454
"""
451455
Get all flags for a given user.
452456
Example:
@@ -477,7 +481,7 @@ def get_feature_flag_payload(
477481
only_evaluate_locally=False,
478482
send_feature_flag_events=True,
479483
disable_geoip=None, # type: Optional[bool]
480-
):
484+
) -> Optional[str]:
481485
return _proxy(
482486
"get_feature_flag_payload",
483487
key=key,
@@ -519,7 +523,7 @@ def get_all_flags_and_payloads(
519523
group_properties={},
520524
only_evaluate_locally=False,
521525
disable_geoip=None, # type: Optional[bool]
522-
):
526+
) -> FlagsAndPayloads:
523527
return _proxy(
524528
"get_all_flags_and_payloads",
525529
distinct_id=distinct_id,

posthog/ai/anthropic/anthropic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def create(
5454
**kwargs: Arguments passed to Anthropic's messages.create
5555
"""
5656
if posthog_trace_id is None:
57-
posthog_trace_id = uuid.uuid4()
57+
posthog_trace_id = str(uuid.uuid4())
5858

5959
if kwargs.get("stream", False):
6060
return self._create_streaming(
@@ -89,7 +89,7 @@ def stream(
8989
**kwargs: Any,
9090
):
9191
if posthog_trace_id is None:
92-
posthog_trace_id = uuid.uuid4()
92+
posthog_trace_id = str(uuid.uuid4())
9393

9494
return self._create_streaming(
9595
posthog_distinct_id,
@@ -116,7 +116,7 @@ def _create_streaming(
116116

117117
def generator():
118118
nonlocal usage_stats
119-
nonlocal accumulated_content
119+
nonlocal accumulated_content # noqa: F824
120120
try:
121121
for event in response:
122122
if hasattr(event, "usage") and event.usage:
@@ -167,7 +167,7 @@ def _capture_streaming_event(
167167
output: str,
168168
):
169169
if posthog_trace_id is None:
170-
posthog_trace_id = uuid.uuid4()
170+
posthog_trace_id = str(uuid.uuid4())
171171

172172
event_properties = {
173173
"$ai_provider": "anthropic",

posthog/ai/anthropic/anthropic_async.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def create(
5454
**kwargs: Arguments passed to Anthropic's messages.create
5555
"""
5656
if posthog_trace_id is None:
57-
posthog_trace_id = uuid.uuid4()
57+
posthog_trace_id = str(uuid.uuid4())
5858

5959
if kwargs.get("stream", False):
6060
return await self._create_streaming(
@@ -89,7 +89,7 @@ async def stream(
8989
**kwargs: Any,
9090
):
9191
if posthog_trace_id is None:
92-
posthog_trace_id = uuid.uuid4()
92+
posthog_trace_id = str(uuid.uuid4())
9393

9494
return await self._create_streaming(
9595
posthog_distinct_id,
@@ -116,7 +116,7 @@ async def _create_streaming(
116116

117117
async def generator():
118118
nonlocal usage_stats
119-
nonlocal accumulated_content
119+
nonlocal accumulated_content # noqa: F824
120120
try:
121121
async for event in response:
122122
if hasattr(event, "usage") and event.usage:
@@ -167,7 +167,7 @@ async def _capture_streaming_event(
167167
output: str,
168168
):
169169
if posthog_trace_id is None:
170-
posthog_trace_id = uuid.uuid4()
170+
posthog_trace_id = str(uuid.uuid4())
171171

172172
event_properties = {
173173
"$ai_provider": "anthropic",

0 commit comments

Comments
 (0)