langfuse-haystack 5.2.0__tar.gz → 6.0.0__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.
Files changed (21) hide show
  1. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/CHANGELOG.md +35 -8
  2. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/LICENSE.txt +1 -1
  3. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/PKG-INFO +3 -3
  4. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/pyproject.toml +2 -1
  5. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/src/haystack_integrations/components/connectors/langfuse/langfuse_connector.py +20 -8
  6. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/tests/test_langfuse_connector.py +78 -38
  7. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/.gitignore +0 -0
  8. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/README.md +0 -0
  9. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/example/basic_rag.py +0 -0
  10. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/example/chat.py +0 -0
  11. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/example/requirements.txt +0 -0
  12. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/pydoc/config_docusaurus.yml +0 -0
  13. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/src/haystack_integrations/components/connectors/langfuse/__init__.py +0 -0
  14. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/src/haystack_integrations/components/connectors/py.typed +0 -0
  15. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/src/haystack_integrations/tracing/langfuse/__init__.py +0 -0
  16. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/src/haystack_integrations/tracing/langfuse/tracer.py +0 -0
  17. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/src/haystack_integrations/tracing/py.typed +0 -0
  18. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/tests/__init__.py +0 -0
  19. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/tests/conftest.py +0 -0
  20. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/tests/test_tracer.py +0 -0
  21. {langfuse_haystack-5.2.0 → langfuse_haystack-6.0.0}/tests/test_tracing.py +0 -0
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/langfuse-v5.2.0] - 2026-07-15
4
+
5
+ ### 🐛 Bug Fixes
6
+
7
+ - *(langfuse)* Replace noisy ToolInvoker input with focused tool call arguments (#3520)
8
+
9
+
3
10
  ## [integrations/langfuse-v5.1.0] - 2026-07-08
4
11
 
5
12
  ### 🐛 Bug Fixes
@@ -184,14 +191,19 @@
184
191
 
185
192
  - Properly cleanup Langfuse tracing context after pipeline run failures (#1999)
186
193
 
194
+ ### 🧹 Chores
195
+
196
+ - Remove black (#1985)
197
+
198
+
199
+ ## [integrations/langfuse-v2.1.0] - 2025-06-16
200
+
187
201
 
188
202
  ### 🧹 Chores
189
203
 
190
204
  - Pin langfuse<3.0.0 (#1904)
191
205
  - Align core-integrations Hatch scripts (#1898)
192
206
  - Update md files for new hatch scripts (#1911)
193
- - Remove black (#1985)
194
-
195
207
 
196
208
  ## [integrations/langfuse-v2.0.1] - 2025-06-02
197
209
 
@@ -248,10 +260,15 @@
248
260
 
249
261
  ### 🚀 Features
250
262
 
251
- - Adapt Ollama metadata to OpenAI format; support Ollama in Langfuse (#1577)
252
263
  - Unify traces of sub-pipelines within pipelines with Langfuse (#1624)
253
264
 
254
265
 
266
+ ## [integrations/langfuse-v0.10.0] - 2025-04-04
267
+
268
+ ### 🚀 Features
269
+
270
+ - Adapt Ollama metadata to OpenAI format; support Ollama in Langfuse (#1577)
271
+
255
272
 
256
273
  ## [integrations/langfuse-v0.9.0] - 2025-04-04
257
274
 
@@ -311,6 +328,12 @@
311
328
 
312
329
  ## [integrations/langfuse-v0.6.2] - 2025-01-02
313
330
 
331
+ ### 🌀 Miscellaneous
332
+
333
+ - Fix messages conversion to OpenAI format (#1272)
334
+
335
+ ## [integrations/langfuse-v0.6.1] - 2024-12-11
336
+
314
337
  ### 🚀 Features
315
338
 
316
339
  - Warn if LangfuseTracer initialized without tracing enabled (#1231)
@@ -322,7 +345,6 @@
322
345
  ### 🌀 Miscellaneous
323
346
 
324
347
  - Chore: Fix tracing_context_var lint errors (#1220)
325
- - Fix messages conversion to OpenAI format (#1272)
326
348
 
327
349
  ## [integrations/langfuse-v0.6.0] - 2024-11-18
328
350
 
@@ -355,6 +377,9 @@
355
377
 
356
378
  - Langfuse - support generation span for more LLMs (#1087)
357
379
 
380
+
381
+ ## [integrations/langfuse-v0.3.0] - 2024-09-11
382
+
358
383
  ### 🚜 Refactor
359
384
 
360
385
  - Remove usage of deprecated `ChatMessage.to_openai_format` (#1001)
@@ -390,10 +415,6 @@
390
415
 
391
416
  ## [integrations/langfuse-v0.1.0] - 2024-06-13
392
417
 
393
- ### 🚀 Features
394
-
395
- - Langfuse integration (#686)
396
-
397
418
  ### 🐛 Bug Fixes
398
419
 
399
420
  - Performance optimizations and value error when streaming in langfuse (#798)
@@ -407,4 +428,10 @@
407
428
  - Chore: change the pydoc renderer class (#718)
408
429
  - Docs: add missing api references (#728)
409
430
 
431
+ ## [integrations/langfuse-v0.0.4] - 2024-05-02
432
+
433
+ ### 🚀 Features
434
+
435
+ - Langfuse integration (#686)
436
+
410
437
  <!-- generated by git-cliff -->
@@ -58,7 +58,7 @@ APPENDIX: How to apply the Apache License to your work.
58
58
 
59
59
  To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
60
60
 
61
- Copyright [yyyy] [name of copyright owner]
61
+ Copyright 2023-present deepset GmbH
62
62
 
63
63
  Licensed under the Apache License, Version 2.0 (the "License");
64
64
  you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: langfuse-haystack
3
- Version: 5.2.0
3
+ Version: 6.0.0
4
4
  Summary: Langfuse integration for Haystack
5
5
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/langfuse#readme
6
6
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Programming Language :: Python :: Implementation :: CPython
18
18
  Classifier: Programming Language :: Python :: Implementation :: PyPy
19
19
  Requires-Python: >=3.10
20
- Requires-Dist: haystack-ai>=2.22.0
20
+ Requires-Dist: haystack-ai>=3.0.0
21
21
  Requires-Dist: langfuse>=4.0.0
22
22
  Description-Content-Type: text/markdown
23
23
 
@@ -21,7 +21,7 @@ classifiers = [
21
21
  "Programming Language :: Python :: Implementation :: CPython",
22
22
  "Programming Language :: Python :: Implementation :: PyPy",
23
23
  ]
24
- dependencies = ["haystack-ai>=2.22.0", "langfuse>=4.0.0"]
24
+ dependencies = ["haystack-ai>=3.0.0", "langfuse>=4.0.0"]
25
25
 
26
26
  [project.urls]
27
27
  Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/langfuse#readme"
@@ -130,6 +130,7 @@ ignore = [
130
130
  "PLR0912",
131
131
  "PLR0913",
132
132
  "PLR0915",
133
+ "PLR0917",
133
134
  # Asserts
134
135
  "S101",
135
136
  # Allow `Any` - used legitimately for dynamic types and SDK boundaries
@@ -157,18 +157,28 @@ class LangfuseConnector:
157
157
  self.span_handler = span_handler
158
158
  self.host = host
159
159
  self.langfuse_client_kwargs = langfuse_client_kwargs
160
+ self._httpx_client = httpx_client
161
+ self.tracer: LangfuseTracer | None = None
162
+
163
+ def warm_up(self) -> None:
164
+ """
165
+ Initialize the Langfuse client and enable tracing once.
166
+ """
167
+ if self.tracer is not None:
168
+ return
169
+
160
170
  resolved_langfuse_client_kwargs = {
161
- "secret_key": secret_key.resolve_value() if secret_key else None,
162
- "public_key": public_key.resolve_value() if public_key else None,
163
- "httpx_client": httpx_client,
164
- "host": host,
165
- **(langfuse_client_kwargs or {}),
171
+ "secret_key": self.secret_key.resolve_value() if self.secret_key else None,
172
+ "public_key": self.public_key.resolve_value() if self.public_key else None,
173
+ "httpx_client": self._httpx_client,
174
+ "host": self.host,
175
+ **(self.langfuse_client_kwargs or {}),
166
176
  }
167
177
  self.tracer = LangfuseTracer(
168
178
  tracer=Langfuse(**resolved_langfuse_client_kwargs),
169
- name=name,
170
- public=public,
171
- span_handler=span_handler,
179
+ name=self.name,
180
+ public=self.public,
181
+ span_handler=self.span_handler,
172
182
  )
173
183
  tracing.enable_tracing(self.tracer)
174
184
 
@@ -186,6 +196,8 @@ class LangfuseConnector:
186
196
  - `trace_url`: The URL to the tracing data.
187
197
  - `trace_id`: The ID of the trace.
188
198
  """
199
+ self.warm_up()
200
+ assert self.tracer is not None
189
201
  logger.debug(
190
202
  "Langfuse tracer invoked with the following context: '{invocation_context}'",
191
203
  invocation_context=invocation_context,
@@ -6,48 +6,53 @@ import os
6
6
 
7
7
  os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
8
8
 
9
- from unittest.mock import Mock
9
+ from unittest.mock import Mock, patch
10
10
 
11
- from haystack import Pipeline
11
+ import httpx
12
+ import pytest
13
+ from haystack import Pipeline, tracing
12
14
  from haystack.components.builders import ChatPromptBuilder
13
15
  from haystack.components.generators.chat import OpenAIChatGenerator
16
+ from haystack.tracing.tracer import NullTracer
14
17
  from haystack.utils import Secret
15
18
 
16
19
  from haystack_integrations.components.connectors.langfuse import LangfuseConnector
17
20
  from haystack_integrations.tracing.langfuse import DefaultSpanHandler
18
21
 
19
22
 
23
+ @pytest.fixture
24
+ def mock_langfuse(monkeypatch):
25
+ monkeypatch.setattr(tracing.tracer, "actual_tracer", NullTracer())
26
+ with patch("haystack_integrations.components.connectors.langfuse.langfuse_connector.Langfuse") as constructor:
27
+ constructor.return_value.get_trace_url.return_value = "https://example.com/trace"
28
+ constructor.return_value.get_current_trace_id.return_value = "12345"
29
+ yield constructor
30
+
31
+
20
32
  class CustomSpanHandler(DefaultSpanHandler):
21
33
  def handle(self, span, component_type=None):
22
34
  pass
23
35
 
24
36
 
25
- class TestLangfuseConnector:
26
- def test_run(self, monkeypatch):
27
- monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
28
- monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
29
-
37
+ class TestRun:
38
+ def test_run(self, mock_langfuse):
30
39
  langfuse_connector = LangfuseConnector(
31
40
  name="Chat example - OpenAI",
32
41
  public=True,
33
- secret_key=Secret.from_env_var("LANGFUSE_SECRET_KEY"),
34
- public_key=Secret.from_env_var("LANGFUSE_PUBLIC_KEY"),
42
+ secret_key=Secret.from_token("secret"),
43
+ public_key=Secret.from_token("public"),
35
44
  )
36
45
 
37
- mock_tracer = Mock()
38
- mock_tracer.get_trace_url.return_value = "https://example.com/trace"
39
- mock_tracer.get_trace_id.return_value = "12345"
40
- langfuse_connector.tracer = mock_tracer
41
-
42
46
  response = langfuse_connector.run(invocation_context={"some_key": "some_value"})
43
47
  assert response["name"] == "Chat example - OpenAI"
44
48
  assert response["trace_url"] == "https://example.com/trace"
45
49
  assert response["trace_id"] == "12345"
50
+ mock_langfuse.assert_called_once()
51
+ assert tracing.tracer.actual_tracer is langfuse_connector.tracer
46
52
 
47
- def test_to_dict(self, monkeypatch):
48
- monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
49
- monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
50
53
 
54
+ class TestSerialization:
55
+ def test_to_dict(self):
51
56
  langfuse_connector = LangfuseConnector(name="Chat example - OpenAI")
52
57
  serialized = langfuse_connector.to_dict()
53
58
 
@@ -72,10 +77,7 @@ class TestLangfuseConnector:
72
77
  },
73
78
  }
74
79
 
75
- def test_to_dict_with_params(self, monkeypatch):
76
- monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
77
- monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
78
-
80
+ def test_to_dict_with_params(self):
79
81
  langfuse_connector = LangfuseConnector(
80
82
  name="Chat example - OpenAI",
81
83
  public=True,
@@ -111,10 +113,7 @@ class TestLangfuseConnector:
111
113
  },
112
114
  }
113
115
 
114
- def test_from_dict(self, monkeypatch):
115
- monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
116
- monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
117
-
116
+ def test_from_dict(self):
118
117
  data = {
119
118
  "type": "haystack_integrations.components.connectors.langfuse.langfuse_connector.LangfuseConnector",
120
119
  "init_parameters": {
@@ -144,10 +143,7 @@ class TestLangfuseConnector:
144
143
  assert langfuse_connector.host is None
145
144
  assert langfuse_connector.langfuse_client_kwargs is None
146
145
 
147
- def test_from_dict_without_span_handler(self, monkeypatch):
148
- monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
149
- monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
150
-
146
+ def test_from_dict_without_span_handler(self):
151
147
  # All keys that would point to None (span_handler, host, langfuse_client_kwargs) are intentionally absent
152
148
  data = {
153
149
  "type": "haystack_integrations.components.connectors.langfuse.langfuse_connector.LangfuseConnector",
@@ -175,10 +171,7 @@ class TestLangfuseConnector:
175
171
  assert langfuse_connector.host is None
176
172
  assert langfuse_connector.langfuse_client_kwargs is None
177
173
 
178
- def test_from_dict_with_params(self, monkeypatch):
179
- monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
180
- monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
181
-
174
+ def test_from_dict_with_params(self):
182
175
  data = {
183
176
  "type": "haystack_integrations.components.connectors.langfuse.langfuse_connector.LangfuseConnector",
184
177
  "init_parameters": {
@@ -212,10 +205,8 @@ class TestLangfuseConnector:
212
205
  assert langfuse_connector.host == "https://example.com"
213
206
  assert langfuse_connector.langfuse_client_kwargs == {"timeout": 30.0}
214
207
 
215
- def test_from_dict_with_legacy_span_handler_format(self, monkeypatch):
208
+ def test_from_dict_with_legacy_span_handler_format(self):
216
209
  # Pipelines serialized before this fix wrap span_handler as {"type": ..., "data": {...}}
217
- monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
218
- monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
219
210
 
220
211
  data = {
221
212
  "type": "haystack_integrations.components.connectors.langfuse.langfuse_connector.LangfuseConnector",
@@ -249,8 +240,6 @@ class TestLangfuseConnector:
249
240
 
250
241
  def test_pipeline_serialization(self, monkeypatch):
251
242
  # Set test env vars
252
- monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
253
- monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
254
243
  monkeypatch.setenv("OPENAI_API_KEY", "openai_api_key")
255
244
 
256
245
  # Create pipeline with OpenAI LLM
@@ -285,3 +274,54 @@ class TestLangfuseConnector:
285
274
 
286
275
  # Verify pipeline is the same
287
276
  assert new_pipe == pipe
277
+
278
+
279
+ class TestComponentLifecycle:
280
+ @pytest.mark.parametrize("key", ["LANGFUSE_SECRET_KEY", "LANGFUSE_PUBLIC_KEY"])
281
+ def test_key_resolved_at_warm_up_not_init(self, key, monkeypatch, mock_langfuse):
282
+ monkeypatch.setenv("LANGFUSE_SECRET_KEY", "secret")
283
+ monkeypatch.setenv("LANGFUSE_PUBLIC_KEY", "public")
284
+ monkeypatch.delenv(key)
285
+ connector = LangfuseConnector("test")
286
+ assert connector.tracer is None
287
+ mock_langfuse.assert_not_called()
288
+ assert not tracing.is_tracing_enabled()
289
+
290
+ with pytest.raises(ValueError, match=key):
291
+ connector.warm_up()
292
+ assert connector.tracer is None
293
+ mock_langfuse.assert_not_called()
294
+
295
+ monkeypatch.setenv(key, "available-now")
296
+ connector.warm_up()
297
+ assert connector.tracer is not None
298
+ mock_langfuse.assert_called_once()
299
+
300
+ def test_warm_up_passes_configuration_and_is_idempotent(self, mock_langfuse):
301
+ client = Mock(spec=httpx.Client)
302
+ handler = CustomSpanHandler()
303
+ connector = LangfuseConnector(
304
+ "configured",
305
+ public=True,
306
+ public_key=Secret.from_token("public"),
307
+ secret_key=Secret.from_token("secret"),
308
+ httpx_client=client,
309
+ span_handler=handler,
310
+ host="https://example.com",
311
+ langfuse_client_kwargs={"timeout": 30, "host": "https://override.example.com"},
312
+ )
313
+ connector.warm_up()
314
+ first_tracer = connector.tracer
315
+ connector.warm_up()
316
+ assert connector.tracer is first_tracer
317
+ mock_langfuse.assert_called_once_with(
318
+ public_key="public",
319
+ secret_key="secret",
320
+ httpx_client=client,
321
+ host="https://override.example.com",
322
+ timeout=30,
323
+ )
324
+ assert handler.tracer is mock_langfuse.return_value
325
+ assert connector.tracer is not None
326
+ assert connector.tracer._name == "configured"
327
+ assert connector.tracer._public is True