Skip to content

Commit 71f443a

Browse files
authored
feat(client): support custom export path to export spans (#1342)
1 parent 8e54641 commit 71f443a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

langfuse/_client/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from langfuse._client.environment_variables import (
5050
LANGFUSE_DEBUG,
5151
LANGFUSE_HOST,
52+
LANGFUSE_OTEL_TRACES_EXPORT_PATH,
5253
LANGFUSE_PUBLIC_KEY,
5354
LANGFUSE_SAMPLE_RATE,
5455
LANGFUSE_SECRET_KEY,

langfuse/_client/environment_variables.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@
4444
**Default value:** ``"https://cloud.langfuse.com"``
4545
"""
4646

47+
LANGFUSE_OTEL_TRACES_EXPORT_PATH = "LANGFUSE_OTEL_TRACES_EXPORT_PATH"
48+
"""
49+
.. envvar:: LANGFUSE_OTEL_TRACES_EXPORT_PATH
50+
51+
URL path on the configured host to export traces to.
52+
53+
**Default value:** ``/api/public/otel/v1/traces``
54+
"""
55+
4756
LANGFUSE_DEBUG = "LANGFUSE_DEBUG"
4857
"""
4958
.. envvar:: LANGFUSE_DEBUG

langfuse/_client/span_processor.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from langfuse._client.environment_variables import (
2424
LANGFUSE_FLUSH_AT,
2525
LANGFUSE_FLUSH_INTERVAL,
26+
LANGFUSE_OTEL_TRACES_EXPORT_PATH,
2627
)
2728
from langfuse._client.utils import span_formatter
2829
from langfuse.logger import langfuse_logger
@@ -90,8 +91,16 @@ def __init__(
9091
# Merge additional headers if provided
9192
headers = {**default_headers, **(additional_headers or {})}
9293

94+
traces_export_path = os.environ.get(LANGFUSE_OTEL_TRACES_EXPORT_PATH, None)
95+
96+
endpoint = (
97+
f"{host}/{traces_export_path}"
98+
if traces_export_path
99+
else f"{host}/api/public/otel/v1/traces"
100+
)
101+
93102
langfuse_span_exporter = OTLPSpanExporter(
94-
endpoint=f"{host}/api/public/otel/v1/traces",
103+
endpoint=endpoint,
95104
headers=headers,
96105
timeout=timeout,
97106
)

0 commit comments

Comments
 (0)