crewplus 0.2.71__py3-none-any.whl → 0.2.72__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.
Potentially problematic release.
This version of crewplus might be problematic. Click here for more details.
- crewplus/services/tracing_manager.py +29 -10
- crewplus/utils/tracing_util.py +51 -0
- {crewplus-0.2.71.dist-info → crewplus-0.2.72.dist-info}/METADATA +1 -1
- {crewplus-0.2.71.dist-info → crewplus-0.2.72.dist-info}/RECORD +7 -6
- {crewplus-0.2.71.dist-info → crewplus-0.2.72.dist-info}/WHEEL +0 -0
- {crewplus-0.2.71.dist-info → crewplus-0.2.72.dist-info}/entry_points.txt +0 -0
- {crewplus-0.2.71.dist-info → crewplus-0.2.72.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# File: crewplus/services/tracing_manager.py
|
|
2
2
|
|
|
3
|
-
from typing import Any, Optional, List, Protocol
|
|
3
|
+
from typing import Any, Optional, List, Protocol, Dict
|
|
4
4
|
import os
|
|
5
5
|
import logging
|
|
6
6
|
|
|
@@ -9,11 +9,14 @@ import logging
|
|
|
9
9
|
try:
|
|
10
10
|
from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
|
|
11
11
|
from ..callbacks.async_langfuse_handler import AsyncLangfuseCallbackHandler
|
|
12
|
+
from ..utils.tracing_util import get_langfuse_handler, get_async_langfuse_handler
|
|
12
13
|
LANGFUSE_AVAILABLE = True
|
|
13
14
|
except ImportError:
|
|
14
15
|
LANGFUSE_AVAILABLE = False
|
|
15
16
|
LangfuseCallbackHandler = None
|
|
16
17
|
AsyncLangfuseCallbackHandler = None
|
|
18
|
+
get_langfuse_handler = None
|
|
19
|
+
get_async_langfuse_handler = None
|
|
17
20
|
|
|
18
21
|
class TracingContext(Protocol):
|
|
19
22
|
"""
|
|
@@ -102,11 +105,11 @@ class TracingManager:
|
|
|
102
105
|
if enable_langfuse:
|
|
103
106
|
try:
|
|
104
107
|
# Create both sync and async handlers. We'll pick one at runtime.
|
|
105
|
-
sync_handler =
|
|
108
|
+
sync_handler = get_langfuse_handler()
|
|
106
109
|
self._sync_handlers.append(sync_handler)
|
|
107
110
|
|
|
108
111
|
if AsyncLangfuseCallbackHandler:
|
|
109
|
-
async_handler =
|
|
112
|
+
async_handler = get_async_langfuse_handler()
|
|
110
113
|
self._async_handlers.append(async_handler)
|
|
111
114
|
|
|
112
115
|
self.context.logger.info(f"Langfuse tracing enabled for {self.context.get_model_identifier()}")
|
|
@@ -115,7 +118,7 @@ class TracingManager:
|
|
|
115
118
|
else:
|
|
116
119
|
self.context.logger.info("Langfuse is not enabled, skipping handler initialization.")
|
|
117
120
|
|
|
118
|
-
def
|
|
121
|
+
def add_callbacks_to_config(self, config: Optional[dict], handlers: List[Any]) -> dict:
|
|
119
122
|
"""A generic helper to add a list of handlers to a config object."""
|
|
120
123
|
if config is None:
|
|
121
124
|
config = {}
|
|
@@ -154,10 +157,26 @@ class TracingManager:
|
|
|
154
157
|
|
|
155
158
|
return config
|
|
156
159
|
|
|
157
|
-
def add_sync_callbacks_to_config(self, config: Optional[dict]) -> dict:
|
|
158
|
-
"""
|
|
159
|
-
|
|
160
|
+
def add_sync_callbacks_to_config(self, config: Optional[dict], handlers: Optional[List[Any]] = None) -> dict:
|
|
161
|
+
"""
|
|
162
|
+
Adds synchronous tracing handlers to the request configuration.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
config: The configuration dictionary to which callbacks will be added.
|
|
166
|
+
handlers: An optional list of handlers to add. If not provided,
|
|
167
|
+
the manager's default synchronous handlers are used.
|
|
168
|
+
"""
|
|
169
|
+
handlers_to_add = self._sync_handlers if handlers is None else handlers
|
|
170
|
+
return self.add_callbacks_to_config(config, handlers_to_add)
|
|
160
171
|
|
|
161
|
-
def add_async_callbacks_to_config(self, config: Optional[dict]) -> dict:
|
|
162
|
-
"""
|
|
163
|
-
|
|
172
|
+
def add_async_callbacks_to_config(self, config: Optional[dict], handlers: Optional[List[Any]] = None) -> dict:
|
|
173
|
+
"""
|
|
174
|
+
Adds asynchronous tracing handlers to the request configuration.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
config: The configuration dictionary to which callbacks will be added.
|
|
178
|
+
handlers: An optional list of handlers to add. If not provided,
|
|
179
|
+
the manager's default asynchronous handlers are used.
|
|
180
|
+
"""
|
|
181
|
+
handlers_to_add = self._async_handlers if handlers is None else handlers
|
|
182
|
+
return self.add_callbacks_to_config(config, handlers_to_add)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from typing import Dict, Any, Optional
|
|
2
|
+
from langchain_core.runnables import RunnableConfig
|
|
3
|
+
from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
|
|
4
|
+
from ..callbacks.async_langfuse_handler import AsyncLangfuseCallbackHandler
|
|
5
|
+
|
|
6
|
+
# Singleton holder for the Langfuse handler to avoid multiple instances per run
|
|
7
|
+
_LANGFUSE_HANDLER: Optional[LangfuseCallbackHandler] = None
|
|
8
|
+
_ASYNC_LANGFUSE_HANDLER: Optional[AsyncLangfuseCallbackHandler] = None
|
|
9
|
+
|
|
10
|
+
def _get_langfuse_handler() -> LangfuseCallbackHandler:
|
|
11
|
+
global _LANGFUSE_HANDLER
|
|
12
|
+
if _LANGFUSE_HANDLER is None:
|
|
13
|
+
_LANGFUSE_HANDLER = LangfuseCallbackHandler()
|
|
14
|
+
return _LANGFUSE_HANDLER
|
|
15
|
+
|
|
16
|
+
def get_langfuse_handler() -> LangfuseCallbackHandler:
|
|
17
|
+
return _get_langfuse_handler()
|
|
18
|
+
|
|
19
|
+
def get_async_langfuse_handler() -> "AsyncLangfuseCallbackHandler":
|
|
20
|
+
"""Returns a singleton instance of the async Langfuse handler."""
|
|
21
|
+
global _ASYNC_LANGFUSE_HANDLER
|
|
22
|
+
if _ASYNC_LANGFUSE_HANDLER is None:
|
|
23
|
+
_ASYNC_LANGFUSE_HANDLER = AsyncLangfuseCallbackHandler()
|
|
24
|
+
return _ASYNC_LANGFUSE_HANDLER
|
|
25
|
+
|
|
26
|
+
def prepare_trace_config(context: Dict[str, Any]) -> RunnableConfig:
|
|
27
|
+
"""
|
|
28
|
+
Prepares a minimal RunnableConfig for tracing, primarily for Langfuse.
|
|
29
|
+
|
|
30
|
+
- Creates a new config containing only tracing-related information.
|
|
31
|
+
- Extracts 'trace_metadata' from the context's 'configurable' dict
|
|
32
|
+
and uses it as the 'metadata' for the new trace config.
|
|
33
|
+
- Adds a singleton Langfuse callback handler.
|
|
34
|
+
"""
|
|
35
|
+
# The full config is passed in the 'config' key of the context
|
|
36
|
+
# Start with a copy of the existing config from the graph to preserve its state
|
|
37
|
+
run_config = context.get("config", {}).copy()
|
|
38
|
+
|
|
39
|
+
# Extract trace_metadata from the 'configurable' part of the full config
|
|
40
|
+
trace_metadata = run_config.get("trace_metadata", {})
|
|
41
|
+
if not trace_metadata:
|
|
42
|
+
trace_metadata = run_config.get("configurable", {}).get("trace_metadata", {})
|
|
43
|
+
|
|
44
|
+
# If trace_metadata exists, merge all its fields into the main metadata key
|
|
45
|
+
if trace_metadata and isinstance(trace_metadata, dict):
|
|
46
|
+
if "metadata" not in run_config:
|
|
47
|
+
run_config["metadata"] = {}
|
|
48
|
+
run_config["metadata"].update(trace_metadata)
|
|
49
|
+
|
|
50
|
+
return run_config
|
|
51
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
crewplus-0.2.
|
|
2
|
-
crewplus-0.2.
|
|
3
|
-
crewplus-0.2.
|
|
4
|
-
crewplus-0.2.
|
|
1
|
+
crewplus-0.2.72.dist-info/METADATA,sha256=RYFh6zu4R5RZg4Ojlp2jIKOV61A7DNvwu_4s1SDu1X0,5424
|
|
2
|
+
crewplus-0.2.72.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
|
|
3
|
+
crewplus-0.2.72.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
|
4
|
+
crewplus-0.2.72.dist-info/licenses/LICENSE,sha256=2_NHSHRTKB_cTcT_GXgcenOCtIZku8j343mOgAguTfc,1087
|
|
5
5
|
crewplus/__init__.py,sha256=m46HkZL1Y4toD619NL47Sn2Qe084WFFSFD7e6VoYKZc,284
|
|
6
6
|
crewplus/callbacks/__init__.py,sha256=YG7ieeb91qEjp1zF0-inEN7mjZ7yT_D2yzdWFT8Z1Ws,63
|
|
7
7
|
crewplus/callbacks/async_langfuse_handler.py,sha256=A4uFeLpvOUdc58M7sZoE65_C1V98u0QCvx5jUquM0pM,7006
|
|
@@ -10,10 +10,11 @@ crewplus/services/azure_chat_model.py,sha256=iWzJ2GQFSNmwJx-2O5_xKPSB6VVc-7T6bcf
|
|
|
10
10
|
crewplus/services/gemini_chat_model.py,sha256=DYqz01H2TIHiCDQesSozVfOsMigno6QGwOtIweg7UHk,40103
|
|
11
11
|
crewplus/services/init_services.py,sha256=tc1ti8Yufo2ixlJpwg8uH0KmoyQ4EqxCOe4uTEWnlRM,2413
|
|
12
12
|
crewplus/services/model_load_balancer.py,sha256=Q9Gx3GrbKworU-Ytxeqp0ggHSgZ1Q6brtTk-nCl4sak,12095
|
|
13
|
-
crewplus/services/tracing_manager.py,sha256=
|
|
13
|
+
crewplus/services/tracing_manager.py,sha256=pwNFeA77vnoZMh_AUOnK5TvAaPOOLg5oDnVOe1yUa9A,8502
|
|
14
14
|
crewplus/utils/__init__.py,sha256=2Gk1n5srFJQnFfBuYTxktdtKOVZyNrFcNaZKhXk35Pw,142
|
|
15
15
|
crewplus/utils/schema_action.py,sha256=GDaBoVFQD1rXqrLVSMTfXYW1xcUu7eDcHsn57XBSnIg,422
|
|
16
16
|
crewplus/utils/schema_document_updater.py,sha256=frvffxn2vbi71fHFPoGb9hq7gH2azmmdq17p-Fumnvg,7322
|
|
17
|
+
crewplus/utils/tracing_util.py,sha256=39F9ydMjXSy5UbQIjYDKc1yiBVnibuWt0cGpYM55k7Q,2281
|
|
17
18
|
crewplus/vectorstores/milvus/__init__.py,sha256=OeYv2rdyG7tcREIjBJPyt2TbE54NvyeRoWMe7LwopRE,245
|
|
18
19
|
crewplus/vectorstores/milvus/milvus_schema_manager.py,sha256=-QRav-hzu-XWeJ_yKUMolal_EyMUspSg-nvh5sqlrlQ,11442
|
|
19
20
|
crewplus/vectorstores/milvus/schema_milvus.py,sha256=wwNpfqsKS0xeozZES40IvB0iNwUtpCall_7Hkg0dL1g,27223
|
|
@@ -22,4 +23,4 @@ docs/GeminiChatModel.md,sha256=zZYyl6RmjZTUsKxxMiC9O4yV70MC4TD-IGUmWhIDBKA,8677
|
|
|
22
23
|
docs/ModelLoadBalancer.md,sha256=aGHES1dcXPz4c7Y8kB5-vsCNJjriH2SWmjBkSGoYKiI,4398
|
|
23
24
|
docs/VDBService.md,sha256=Dw286Rrf_fsi13jyD3Bo4Sy7nZ_G7tYm7d8MZ2j9hxk,9375
|
|
24
25
|
docs/index.md,sha256=3tlc15uR8lzFNM5WjdoZLw0Y9o1P1gwgbEnOdIBspqc,1643
|
|
25
|
-
crewplus-0.2.
|
|
26
|
+
crewplus-0.2.72.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|