mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-19 00:01:29 +00:00
refactor(langfuse): read the sdk version header from package metadata
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
09dfd7e50d
commit
093edce970
2 changed files with 3 additions and 4 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue