langfuse-haystack 0.6.0__tar.gz → 0.6.2__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.
- langfuse_haystack-0.6.2/CHANGELOG.md +100 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/PKG-INFO +4 -3
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/src/haystack_integrations/tracing/langfuse/tracer.py +32 -11
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/tests/test_tracer.py +16 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/tests/test_tracing.py +1 -1
- langfuse_haystack-0.6.0/CHANGELOG.md +0 -53
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/.gitignore +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/LICENSE.txt +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/README.md +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/example/basic_rag.py +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/example/chat.py +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/example/requirements.txt +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/pydoc/config.yml +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/pyproject.toml +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/src/haystack_integrations/components/connectors/langfuse/__init__.py +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/src/haystack_integrations/components/connectors/langfuse/langfuse_connector.py +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/src/haystack_integrations/tracing/langfuse/__init__.py +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/tests/__init__.py +0 -0
- {langfuse_haystack-0.6.0 → langfuse_haystack-0.6.2}/tests/test_langfuse_span.py +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [unreleased]
|
|
4
|
+
|
|
5
|
+
### 🚀 Features
|
|
6
|
+
|
|
7
|
+
- Warn if LangfuseTracer initialized without tracing enabled (#1231)
|
|
8
|
+
|
|
9
|
+
### 🧹 Chores
|
|
10
|
+
|
|
11
|
+
- Use text instead of content for ChatMessage in Llama.cpp, Langfuse and Mistral (#1238)
|
|
12
|
+
|
|
13
|
+
### 🌀 Miscellaneous
|
|
14
|
+
|
|
15
|
+
- Chore: Fix tracing_context_var lint errors (#1220)
|
|
16
|
+
|
|
17
|
+
## [integrations/langfuse-v0.6.0] - 2024-11-18
|
|
18
|
+
|
|
19
|
+
### 🚀 Features
|
|
20
|
+
|
|
21
|
+
- Add support for ttft (#1161)
|
|
22
|
+
|
|
23
|
+
### ⚙️ CI
|
|
24
|
+
|
|
25
|
+
- Adopt uv as installer (#1142)
|
|
26
|
+
|
|
27
|
+
### 🌀 Miscellaneous
|
|
28
|
+
|
|
29
|
+
- Fixed TypeError in LangfuseTrace (#1184)
|
|
30
|
+
|
|
31
|
+
## [integrations/langfuse-v0.5.0] - 2024-10-01
|
|
32
|
+
|
|
33
|
+
### 🧹 Chores
|
|
34
|
+
|
|
35
|
+
- Update ruff linting scripts and settings (#1105)
|
|
36
|
+
|
|
37
|
+
### 🌀 Miscellaneous
|
|
38
|
+
|
|
39
|
+
- Fix: Add delay to flush the Langfuse traces (#1091)
|
|
40
|
+
- Add invocation_context to identify traces (#1089)
|
|
41
|
+
|
|
42
|
+
## [integrations/langfuse-v0.4.0] - 2024-09-17
|
|
43
|
+
|
|
44
|
+
### 🚀 Features
|
|
45
|
+
|
|
46
|
+
- Langfuse - support generation span for more LLMs (#1087)
|
|
47
|
+
|
|
48
|
+
### 🚜 Refactor
|
|
49
|
+
|
|
50
|
+
- Remove usage of deprecated `ChatMessage.to_openai_format` (#1001)
|
|
51
|
+
|
|
52
|
+
### 📚 Documentation
|
|
53
|
+
|
|
54
|
+
- Add link to langfuse in LangfuseConnector (#981)
|
|
55
|
+
|
|
56
|
+
### 🧪 Testing
|
|
57
|
+
|
|
58
|
+
- Do not retry tests in `hatch run test` command (#954)
|
|
59
|
+
|
|
60
|
+
### ⚙️ CI
|
|
61
|
+
|
|
62
|
+
- Retry tests to reduce flakyness (#836)
|
|
63
|
+
|
|
64
|
+
### 🧹 Chores
|
|
65
|
+
|
|
66
|
+
- `Langfuse` - replace DynamicChatPromptBuilder with ChatPromptBuilder (#925)
|
|
67
|
+
- Remove all `DynamicChatPromptBuilder` references in Langfuse integration (#931)
|
|
68
|
+
|
|
69
|
+
### 🌀 Miscellaneous
|
|
70
|
+
|
|
71
|
+
- Ci: install `pytest-rerunfailures` where needed; add retry config to `test-cov` script (#845)
|
|
72
|
+
- Chore: Update Langfuse README to avoid common initialization issues (#952)
|
|
73
|
+
- Chore: langfuse - ruff update, don't ruff tests (#992)
|
|
74
|
+
|
|
75
|
+
## [integrations/langfuse-v0.2.0] - 2024-06-18
|
|
76
|
+
|
|
77
|
+
### 🌀 Miscellaneous
|
|
78
|
+
|
|
79
|
+
- Feat: add support for Azure generators (#815)
|
|
80
|
+
|
|
81
|
+
## [integrations/langfuse-v0.1.0] - 2024-06-13
|
|
82
|
+
|
|
83
|
+
### 🚀 Features
|
|
84
|
+
|
|
85
|
+
- Langfuse integration (#686)
|
|
86
|
+
|
|
87
|
+
### 🐛 Bug Fixes
|
|
88
|
+
|
|
89
|
+
- Performance optimizations and value error when streaming in langfuse (#798)
|
|
90
|
+
|
|
91
|
+
### 🧹 Chores
|
|
92
|
+
|
|
93
|
+
- Use ChatMessage to_openai_format, update unit tests, pydocs (#725)
|
|
94
|
+
|
|
95
|
+
### 🌀 Miscellaneous
|
|
96
|
+
|
|
97
|
+
- Chore: change the pydoc renderer class (#718)
|
|
98
|
+
- Docs: add missing api references (#728)
|
|
99
|
+
|
|
100
|
+
<!-- generated by git-cliff -->
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: langfuse-haystack
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.2
|
|
4
4
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/langfuse#readme
|
|
5
5
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
6
6
|
Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/langfuse
|
|
7
7
|
Author-email: deepset GmbH <info@deepset.ai>
|
|
8
|
-
License: Apache-2.0
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE.txt
|
|
9
10
|
Classifier: Development Status :: 4 - Beta
|
|
10
11
|
Classifier: Programming Language :: Python
|
|
11
12
|
Classifier: Programming Language :: Python :: 3.8
|
|
@@ -5,13 +5,17 @@ from datetime import datetime
|
|
|
5
5
|
from typing import Any, Dict, Iterator, List, Optional, Union
|
|
6
6
|
|
|
7
7
|
from haystack import logging
|
|
8
|
-
from haystack.components.generators.openai_utils import _convert_message_to_openai_format
|
|
9
8
|
from haystack.dataclasses import ChatMessage
|
|
10
|
-
from haystack.
|
|
9
|
+
from haystack.lazy_imports import LazyImport
|
|
10
|
+
from haystack.tracing import Span, Tracer
|
|
11
|
+
from haystack.tracing import tracer as proxy_tracer
|
|
11
12
|
from haystack.tracing import utils as tracing_utils
|
|
12
13
|
|
|
13
14
|
import langfuse
|
|
14
15
|
|
|
16
|
+
with LazyImport("") as openai_utils_import:
|
|
17
|
+
from haystack.components.generators.openai_utils import _convert_message_to_openai_format
|
|
18
|
+
|
|
15
19
|
logger = logging.getLogger(__name__)
|
|
16
20
|
|
|
17
21
|
HAYSTACK_LANGFUSE_ENFORCE_FLUSH_ENV_VAR = "HAYSTACK_LANGFUSE_ENFORCE_FLUSH"
|
|
@@ -42,7 +46,7 @@ _COMPONENT_OUTPUT_KEY = "haystack.component.output"
|
|
|
42
46
|
|
|
43
47
|
# Context var used to keep track of tracing related info.
|
|
44
48
|
# This mainly useful for parents spans.
|
|
45
|
-
tracing_context_var: ContextVar[Dict[Any, Any]] = ContextVar("tracing_context"
|
|
49
|
+
tracing_context_var: ContextVar[Dict[Any, Any]] = ContextVar("tracing_context")
|
|
46
50
|
|
|
47
51
|
|
|
48
52
|
class LangfuseSpan(Span):
|
|
@@ -78,18 +82,28 @@ class LangfuseSpan(Span):
|
|
|
78
82
|
:param key: The content tag key.
|
|
79
83
|
:param value: The content tag value.
|
|
80
84
|
"""
|
|
81
|
-
if not
|
|
85
|
+
if not proxy_tracer.is_content_tracing_enabled:
|
|
82
86
|
return
|
|
83
87
|
if key.endswith(".input"):
|
|
84
88
|
if "messages" in value:
|
|
85
|
-
|
|
89
|
+
if openai_utils_import.is_successful():
|
|
90
|
+
# Haystack < 2.9.0
|
|
91
|
+
messages = [_convert_message_to_openai_format(m) for m in value["messages"]]
|
|
92
|
+
else:
|
|
93
|
+
# Haystack >= 2.9.0
|
|
94
|
+
messages = [m.to_openai_dict_format() for m in value["messages"]]
|
|
86
95
|
self._span.update(input=messages)
|
|
87
96
|
else:
|
|
88
97
|
self._span.update(input=value)
|
|
89
98
|
elif key.endswith(".output"):
|
|
90
99
|
if "replies" in value:
|
|
91
100
|
if all(isinstance(r, ChatMessage) for r in value["replies"]):
|
|
92
|
-
|
|
101
|
+
if openai_utils_import.is_successful():
|
|
102
|
+
# Haystack < 2.9.0
|
|
103
|
+
replies = [_convert_message_to_openai_format(m) for m in value["replies"]]
|
|
104
|
+
else:
|
|
105
|
+
# Haystack >= 2.9.0
|
|
106
|
+
replies = [m.to_openai_dict_format() for m in value["replies"]]
|
|
93
107
|
else:
|
|
94
108
|
replies = value["replies"]
|
|
95
109
|
self._span.update(output=replies)
|
|
@@ -126,6 +140,12 @@ class LangfuseTracer(Tracer):
|
|
|
126
140
|
be publicly accessible to anyone with the tracing URL. If set to `False`, the tracing data will be private
|
|
127
141
|
and only accessible to the Langfuse account owner.
|
|
128
142
|
"""
|
|
143
|
+
if not proxy_tracer.is_content_tracing_enabled:
|
|
144
|
+
logger.warning(
|
|
145
|
+
"Traces will not be logged to Langfuse because Haystack tracing is disabled. "
|
|
146
|
+
"To enable, set the HAYSTACK_CONTENT_TRACING_ENABLED environment variable to true "
|
|
147
|
+
"before importing Haystack."
|
|
148
|
+
)
|
|
129
149
|
self._tracer = tracer
|
|
130
150
|
self._context: List[LangfuseSpan] = []
|
|
131
151
|
self._name = name
|
|
@@ -147,15 +167,16 @@ class LangfuseTracer(Tracer):
|
|
|
147
167
|
operation_name=operation_name,
|
|
148
168
|
)
|
|
149
169
|
# Create a new trace if no parent span is provided
|
|
170
|
+
context = tracing_context_var.get({})
|
|
150
171
|
span = LangfuseSpan(
|
|
151
172
|
self._tracer.trace(
|
|
152
173
|
name=self._name,
|
|
153
174
|
public=self._public,
|
|
154
|
-
id=
|
|
155
|
-
user_id=
|
|
156
|
-
session_id=
|
|
157
|
-
tags=
|
|
158
|
-
version=
|
|
175
|
+
id=context.get("trace_id"),
|
|
176
|
+
user_id=context.get("user_id"),
|
|
177
|
+
session_id=context.get("session_id"),
|
|
178
|
+
tags=context.get("tags"),
|
|
179
|
+
version=context.get("version"),
|
|
159
180
|
)
|
|
160
181
|
)
|
|
161
182
|
elif tags.get(_COMPONENT_TYPE_KEY) in _ALL_SUPPORTED_GENERATORS:
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import datetime
|
|
2
|
+
import logging
|
|
3
|
+
import sys
|
|
2
4
|
from unittest.mock import MagicMock, Mock, patch
|
|
3
5
|
|
|
4
6
|
from haystack.dataclasses import ChatMessage
|
|
@@ -149,3 +151,17 @@ class TestLangfuseTracer:
|
|
|
149
151
|
pass
|
|
150
152
|
|
|
151
153
|
assert tracer._context == []
|
|
154
|
+
|
|
155
|
+
def test_init_with_tracing_disabled(self, monkeypatch, caplog):
|
|
156
|
+
# Clear haystack modules because ProxyTracer is initialized whenever haystack is imported
|
|
157
|
+
modules_to_clear = [name for name in sys.modules if name.startswith('haystack')]
|
|
158
|
+
for name in modules_to_clear:
|
|
159
|
+
sys.modules.pop(name, None)
|
|
160
|
+
|
|
161
|
+
# Re-import LangfuseTracer and instantiate it with tracing disabled
|
|
162
|
+
with caplog.at_level(logging.WARNING):
|
|
163
|
+
monkeypatch.setenv("HAYSTACK_CONTENT_TRACING_ENABLED", "false")
|
|
164
|
+
from haystack_integrations.tracing.langfuse import LangfuseTracer
|
|
165
|
+
|
|
166
|
+
LangfuseTracer(tracer=MockTracer(), name="Haystack", public=False)
|
|
167
|
+
assert "tracing is disabled" in caplog.text
|
|
@@ -49,7 +49,7 @@ def test_tracing_integration(llm_class, env_var, expected_trace):
|
|
|
49
49
|
"tracer": {"invocation_context": {"user_id": "user_42"}},
|
|
50
50
|
}
|
|
51
51
|
)
|
|
52
|
-
assert "Berlin" in response["llm"]["replies"][0].
|
|
52
|
+
assert "Berlin" in response["llm"]["replies"][0].text
|
|
53
53
|
assert response["tracer"]["trace_url"]
|
|
54
54
|
|
|
55
55
|
trace_url = response["tracer"]["trace_url"]
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [integrations/langfuse-v0.5.0] - 2024-10-01
|
|
4
|
-
|
|
5
|
-
### ⚙️ Miscellaneous Tasks
|
|
6
|
-
|
|
7
|
-
- Update ruff linting scripts and settings (#1105)
|
|
8
|
-
|
|
9
|
-
### Langfuse
|
|
10
|
-
|
|
11
|
-
- Add invocation_context to identify traces (#1089)
|
|
12
|
-
|
|
13
|
-
## [integrations/langfuse-v0.4.0] - 2024-09-17
|
|
14
|
-
|
|
15
|
-
### 🚀 Features
|
|
16
|
-
|
|
17
|
-
- Langfuse - support generation span for more LLMs (#1087)
|
|
18
|
-
|
|
19
|
-
### 🚜 Refactor
|
|
20
|
-
|
|
21
|
-
- Remove usage of deprecated `ChatMessage.to_openai_format` (#1001)
|
|
22
|
-
|
|
23
|
-
### 📚 Documentation
|
|
24
|
-
|
|
25
|
-
- Add link to langfuse in LangfuseConnector (#981)
|
|
26
|
-
|
|
27
|
-
### 🧪 Testing
|
|
28
|
-
|
|
29
|
-
- Do not retry tests in `hatch run test` command (#954)
|
|
30
|
-
|
|
31
|
-
### ⚙️ Miscellaneous Tasks
|
|
32
|
-
|
|
33
|
-
- Retry tests to reduce flakyness (#836)
|
|
34
|
-
- `Langfuse` - replace DynamicChatPromptBuilder with ChatPromptBuilder (#925)
|
|
35
|
-
- Remove all `DynamicChatPromptBuilder` references in Langfuse integration (#931)
|
|
36
|
-
|
|
37
|
-
## [integrations/langfuse-v0.2.0] - 2024-06-18
|
|
38
|
-
|
|
39
|
-
## [integrations/langfuse-v0.1.0] - 2024-06-13
|
|
40
|
-
|
|
41
|
-
### 🚀 Features
|
|
42
|
-
|
|
43
|
-
- Langfuse integration (#686)
|
|
44
|
-
|
|
45
|
-
### 🐛 Bug Fixes
|
|
46
|
-
|
|
47
|
-
- Performance optimizations and value error when streaming in langfuse (#798)
|
|
48
|
-
|
|
49
|
-
### ⚙️ Miscellaneous Tasks
|
|
50
|
-
|
|
51
|
-
- Use ChatMessage to_openai_format, update unit tests, pydocs (#725)
|
|
52
|
-
|
|
53
|
-
<!-- generated by git-cliff -->
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|