posthog 6.7.9__py3-none-any.whl → 6.7.11__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/ai/langchain/callbacks.py +2 -0
- posthog/integrations/django.py +40 -38
- posthog/version.py +1 -1
- {posthog-6.7.9.dist-info → posthog-6.7.11.dist-info}/METADATA +1 -1
- {posthog-6.7.9.dist-info → posthog-6.7.11.dist-info}/RECORD +8 -8
- {posthog-6.7.9.dist-info → posthog-6.7.11.dist-info}/WHEEL +0 -0
- {posthog-6.7.9.dist-info → posthog-6.7.11.dist-info}/licenses/LICENSE +0 -0
- {posthog-6.7.9.dist-info → posthog-6.7.11.dist-info}/top_level.txt +0 -0
|
@@ -486,6 +486,7 @@ class CallbackHandler(BaseCallbackHandler):
|
|
|
486
486
|
"$ai_latency": run.latency,
|
|
487
487
|
"$ai_span_name": run.name,
|
|
488
488
|
"$ai_span_id": run_id,
|
|
489
|
+
"$ai_framework": "langchain",
|
|
489
490
|
}
|
|
490
491
|
if parent_run_id is not None:
|
|
491
492
|
event_properties["$ai_parent_id"] = parent_run_id
|
|
@@ -556,6 +557,7 @@ class CallbackHandler(BaseCallbackHandler):
|
|
|
556
557
|
"$ai_http_status": 200,
|
|
557
558
|
"$ai_latency": run.latency,
|
|
558
559
|
"$ai_base_url": run.base_url,
|
|
560
|
+
"$ai_framework": "langchain",
|
|
559
561
|
}
|
|
560
562
|
|
|
561
563
|
if run.tools:
|
posthog/integrations/django.py
CHANGED
|
@@ -3,13 +3,19 @@ from posthog import contexts
|
|
|
3
3
|
from posthog.client import Client
|
|
4
4
|
|
|
5
5
|
try:
|
|
6
|
-
from asgiref.sync import iscoroutinefunction
|
|
6
|
+
from asgiref.sync import iscoroutinefunction, markcoroutinefunction
|
|
7
7
|
except ImportError:
|
|
8
|
-
# Fallback for older Django versions
|
|
8
|
+
# Fallback for older Django versions without asgiref
|
|
9
9
|
import asyncio
|
|
10
10
|
|
|
11
11
|
iscoroutinefunction = asyncio.iscoroutinefunction
|
|
12
12
|
|
|
13
|
+
# No-op fallback for markcoroutinefunction
|
|
14
|
+
# Older Django versions without asgiref typically don't support async middleware anyway
|
|
15
|
+
def markcoroutinefunction(func):
|
|
16
|
+
return func
|
|
17
|
+
|
|
18
|
+
|
|
13
19
|
if TYPE_CHECKING:
|
|
14
20
|
from django.http import HttpRequest, HttpResponse # noqa: F401
|
|
15
21
|
from typing import Callable, Dict, Any, Optional, Union, Awaitable # noqa: F401
|
|
@@ -39,26 +45,24 @@ class PosthogContextMiddleware:
|
|
|
39
45
|
See the context documentation for more information. The extracted distinct ID and session ID, if found, are used to
|
|
40
46
|
associate all events captured in the middleware context with the same distinct ID and session as currently active on the
|
|
41
47
|
frontend. See the documentation for `set_context_session` and `identify_context` for more details.
|
|
48
|
+
|
|
49
|
+
This middleware is hybrid-capable: it supports both WSGI (sync) and ASGI (async) Django applications. The middleware
|
|
50
|
+
detects at initialization whether the next middleware in the chain is async or sync, and adapts its behavior accordingly.
|
|
51
|
+
This ensures compatibility with both pure sync and pure async middleware chains, as well as mixed chains in ASGI mode.
|
|
42
52
|
"""
|
|
43
53
|
|
|
44
|
-
# Django middleware capability flags
|
|
45
54
|
sync_capable = True
|
|
46
55
|
async_capable = True
|
|
47
56
|
|
|
48
57
|
def __init__(self, get_response):
|
|
49
58
|
# type: (Union[Callable[[HttpRequest], HttpResponse], Callable[[HttpRequest], Awaitable[HttpResponse]]]) -> None
|
|
59
|
+
self.get_response = get_response
|
|
50
60
|
self._is_coroutine = iscoroutinefunction(get_response)
|
|
51
|
-
self._async_get_response = None # type: Optional[Callable[[HttpRequest], Awaitable[HttpResponse]]]
|
|
52
|
-
self._sync_get_response = None # type: Optional[Callable[[HttpRequest], HttpResponse]]
|
|
53
61
|
|
|
62
|
+
# Mark this instance as a coroutine function if get_response is async
|
|
63
|
+
# This is required for Django to correctly detect async middleware
|
|
54
64
|
if self._is_coroutine:
|
|
55
|
-
self
|
|
56
|
-
"Callable[[HttpRequest], Awaitable[HttpResponse]]", get_response
|
|
57
|
-
)
|
|
58
|
-
else:
|
|
59
|
-
self._sync_get_response = cast(
|
|
60
|
-
"Callable[[HttpRequest], HttpResponse]", get_response
|
|
61
|
-
)
|
|
65
|
+
markcoroutinefunction(self)
|
|
62
66
|
|
|
63
67
|
from django.conf import settings
|
|
64
68
|
|
|
@@ -181,40 +185,38 @@ class PosthogContextMiddleware:
|
|
|
181
185
|
return user_id, email
|
|
182
186
|
|
|
183
187
|
def __call__(self, request):
|
|
184
|
-
# type: (HttpRequest) -> HttpResponse
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if self._is_coroutine:
|
|
188
|
-
raise RuntimeError(
|
|
189
|
-
"PosthogContextMiddleware received sync call but get_response is async"
|
|
190
|
-
)
|
|
188
|
+
# type: (HttpRequest) -> Union[HttpResponse, Awaitable[HttpResponse]]
|
|
189
|
+
"""
|
|
190
|
+
Unified entry point for both sync and async request handling.
|
|
191
191
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
When sync_capable and async_capable are both True, Django passes requests
|
|
193
|
+
without conversion. This method detects the mode and routes accordingly.
|
|
194
|
+
"""
|
|
195
|
+
if self._is_coroutine:
|
|
196
|
+
return self.__acall__(request)
|
|
197
|
+
else:
|
|
198
|
+
# Synchronous path
|
|
199
|
+
if self.request_filter and not self.request_filter(request):
|
|
200
|
+
return self.get_response(request)
|
|
195
201
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
202
|
+
with contexts.new_context(self.capture_exceptions, client=self.client):
|
|
203
|
+
for k, v in self.extract_tags(request).items():
|
|
204
|
+
contexts.tag(k, v)
|
|
199
205
|
|
|
200
|
-
|
|
201
|
-
return self._sync_get_response(request)
|
|
206
|
+
return self.get_response(request)
|
|
202
207
|
|
|
203
208
|
async def __acall__(self, request):
|
|
204
|
-
# type: (HttpRequest) -> HttpResponse
|
|
209
|
+
# type: (HttpRequest) -> Awaitable[HttpResponse]
|
|
210
|
+
"""
|
|
211
|
+
Asynchronous entry point for async request handling.
|
|
212
|
+
|
|
213
|
+
This method is called when the middleware chain is async.
|
|
214
|
+
"""
|
|
205
215
|
if self.request_filter and not self.request_filter(request):
|
|
206
|
-
|
|
207
|
-
return await self._async_get_response(request)
|
|
208
|
-
else:
|
|
209
|
-
assert self._sync_get_response is not None
|
|
210
|
-
return self._sync_get_response(request)
|
|
216
|
+
return await self.get_response(request)
|
|
211
217
|
|
|
212
218
|
with contexts.new_context(self.capture_exceptions, client=self.client):
|
|
213
219
|
for k, v in self.extract_tags(request).items():
|
|
214
220
|
contexts.tag(k, v)
|
|
215
221
|
|
|
216
|
-
|
|
217
|
-
return await self._async_get_response(request)
|
|
218
|
-
else:
|
|
219
|
-
assert self._sync_get_response is not None
|
|
220
|
-
return self._sync_get_response(request)
|
|
222
|
+
return await self.get_response(request)
|
posthog/version.py
CHANGED
|
@@ -11,7 +11,7 @@ posthog/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
11
11
|
posthog/request.py,sha256=CaONBN7a5RD8xiSShVMgHEd9XxKWM6ZQTLZypiqABhA,6168
|
|
12
12
|
posthog/types.py,sha256=Dl3aFGX9XUR0wMmK12r2s5Hjan9jL4HpQ9GHpVcEq5U,10207
|
|
13
13
|
posthog/utils.py,sha256=-0w-OLcCaoldkbBebPzQyBzLJSo9G9yBOg8NDVz7La8,16088
|
|
14
|
-
posthog/version.py,sha256=
|
|
14
|
+
posthog/version.py,sha256=TlWP7mz_3i_wmO2u7eAu_PtleXF0r8-jT2AL1xYUPqA,88
|
|
15
15
|
posthog/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
posthog/ai/sanitization.py,sha256=owipZ4eJYtd4JTI-CM_klatclXaeaIec3XJBOUfsOnQ,5770
|
|
17
17
|
posthog/ai/types.py,sha256=ceubs4K9xf8vQx7wokq1NL9hPtxyS7D7sUOuT7Lx1lM,3237
|
|
@@ -25,14 +25,14 @@ posthog/ai/gemini/__init__.py,sha256=JV_9-gBR87leHgZW4XAYZP7LSl4YaXeuhqDUpA8HygA
|
|
|
25
25
|
posthog/ai/gemini/gemini.py,sha256=-c2MnBeask6SrAbFZ7XXZ_OMcuglTBRdnFe_ROVgXWQ,14972
|
|
26
26
|
posthog/ai/gemini/gemini_converter.py,sha256=0LM5OXsCWjg8eazi06VI5Fc4LSGxSUvg-_XpZVll78A,16009
|
|
27
27
|
posthog/ai/langchain/__init__.py,sha256=9CqAwLynTGj3ASAR80C3PmdTdrYGmu99tz0JL-HPFgI,70
|
|
28
|
-
posthog/ai/langchain/callbacks.py,sha256=
|
|
28
|
+
posthog/ai/langchain/callbacks.py,sha256=l4sP3M2B_t6qAgDeusoKoDpE99i6Cbw7SMhpuykOmTk,29575
|
|
29
29
|
posthog/ai/openai/__init__.py,sha256=u4OuUT7k1NgFj0TrxjuyegOg7a_UA8nAU6a-Hszr0OM,490
|
|
30
30
|
posthog/ai/openai/openai.py,sha256=ts95vdvWH7h0TX4FpLLK_wU_7H0MP3eZBEg0S-lsCKw,20127
|
|
31
31
|
posthog/ai/openai/openai_async.py,sha256=QFewU-8VBW1BhrNHkKCFuW57jqu2RSnF2VZ9mDuxjbE,21775
|
|
32
32
|
posthog/ai/openai/openai_converter.py,sha256=B38g_RgN1n7mbxbDDAZFcu50RO4UHCtJQAmpvDVry7o,20451
|
|
33
33
|
posthog/ai/openai/openai_providers.py,sha256=zQIFTXHS2-dBKQX7FZxTFo7rIj5iiN7VHm9_2RzuDs8,3941
|
|
34
34
|
posthog/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
35
|
-
posthog/integrations/django.py,sha256=
|
|
35
|
+
posthog/integrations/django.py,sha256=7z7YsF46KTe11WfgX__qHpYau_jFt-9BacNYY9GI17A,8667
|
|
36
36
|
posthog/test/__init__.py,sha256=VYgM6xPbJbvS-xhIcDiBRs0MFC9V_jT65uNeerCz_rM,299
|
|
37
37
|
posthog/test/test_before_send.py,sha256=3546WKlk8rF6bhvqhwcxAsjJovDw0Hf8yTvcYGbrhyI,7912
|
|
38
38
|
posthog/test/test_client.py,sha256=F-jUA0uKgHpVLOdnen2j6WSTp6whlJcpZdSecLoREFg,96273
|
|
@@ -47,8 +47,8 @@ posthog/test/test_request.py,sha256=l19WVyZQc4Iqmh_bpnAFOj4nGRpDK1iO-o5aJDQfFdo,
|
|
|
47
47
|
posthog/test/test_size_limited_dict.py,sha256=Wom7BkzpHmusHilZy0SV3PNzhw7ucuQgqrx86jf8euo,765
|
|
48
48
|
posthog/test/test_types.py,sha256=csLuBiz6RMV36cpg9LVIor4Khq6MfjjGxYXodx5VttY,7586
|
|
49
49
|
posthog/test/test_utils.py,sha256=NUs2bgqrVuMdnKRq52syizgglt5_7wxxZl3dDMun-Tg,9602
|
|
50
|
-
posthog-6.7.
|
|
51
|
-
posthog-6.7.
|
|
52
|
-
posthog-6.7.
|
|
53
|
-
posthog-6.7.
|
|
54
|
-
posthog-6.7.
|
|
50
|
+
posthog-6.7.11.dist-info/licenses/LICENSE,sha256=wGf9JBotDkSygFj43m49oiKlFnpMnn97keiZKF-40vE,2450
|
|
51
|
+
posthog-6.7.11.dist-info/METADATA,sha256=-zYlR7_6n6nw9FWyEVE0mxtA1jWYUfrYjq3ovy_qCwU,6016
|
|
52
|
+
posthog-6.7.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
53
|
+
posthog-6.7.11.dist-info/top_level.txt,sha256=7FBLsRjIUHVKQsXIhozuI3k-mun1tapp8iZO9EmUPEw,8
|
|
54
|
+
posthog-6.7.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|