diff --git a/litellm/integrations/langfuse/langfuse_sdk.py b/litellm/integrations/langfuse/langfuse_sdk.py index b0254005d54..378590aca13 100644 --- a/litellm/integrations/langfuse/langfuse_sdk.py +++ b/litellm/integrations/langfuse/langfuse_sdk.py @@ -9,6 +9,7 @@ from contextlib import contextmanager from contextvars import ContextVar from datetime import datetime from hashlib import sha256 +from importlib.metadata import version from types import MappingProxyType from typing import Final from weakref import WeakKeyDictionary, WeakSet @@ -448,11 +449,8 @@ def _build_verified_span_exporter(*, public_key: object, secret_key: object, bas client_certificate: Final = configured_certificate if isinstance(configured_certificate, str) else None if ca_bundle is None and client_certificate is None: return None - import langfuse as langfuse_package from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter - langfuse_version: Final = getattr(langfuse_package, "__version__", "unknown") - export_path: Final = os.getenv("LANGFUSE_OTEL_TRACES_EXPORT_PATH") endpoint: Final = f"{base_url}/{export_path}" if export_path else f"{base_url}/api/public/otel/v1/traces" encoded_auth: Final = b64encode(f"{public_key}:{secret_key}".encode()).decode("ascii") @@ -461,7 +459,7 @@ def _build_verified_span_exporter(*, public_key: object, secret_key: object, bas headers={ # mutable-ok: the exporter copies these into its session headers "Authorization": "Basic " + encoded_auth, "x-langfuse-sdk-name": "python", - "x-langfuse-sdk-version": langfuse_version, + "x-langfuse-sdk-version": version("langfuse"), "x-langfuse-public-key": str(public_key), }, certificate_file=ca_bundle, diff --git a/tests/test_litellm/integrations/langfuse/test_langfuse_sdk.py b/tests/test_litellm/integrations/langfuse/test_langfuse_sdk.py index 1ea48d342ba..9e091983685 100644 --- a/tests/test_litellm/integrations/langfuse/test_langfuse_sdk.py +++ b/tests/test_litellm/integrations/langfuse/test_langfuse_sdk.py @@ -941,6 +941,7 @@ def test_ssl_exporter_is_only_built_with_custom_tls_material(monkeypatch, tmp_pa assert exporter._endpoint == "https://lf.internal.example/api/public/otel/v1/traces" assert exporter._certificate_file == str(ca_path) assert exporter._headers["x-langfuse-public-key"] == "pk" + assert exporter._headers["x-langfuse-sdk-version"] == installed_langfuse_version() def test_second_client_on_the_same_key_does_not_build_another_provider():