From cdadf6f7cdda2f22748a3cfc3b867b7b9fa0d19f Mon Sep 17 00:00:00 2001 From: hieheihei <270985384@qq.com> Date: Tue, 15 Jul 2025 21:00:23 +0800 Subject: [PATCH] update ot endpoint config --- api/.env.example | 2 ++ api/configs/observability/otel/otel_config.py | 10 ++++++++++ api/extensions/ext_otel.py | 11 +++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/api/.env.example b/api/.env.example index eab017a624..c09c6c230e 100644 --- a/api/.env.example +++ b/api/.env.example @@ -505,6 +505,8 @@ LOGIN_LOCKOUT_DURATION=86400 # Enable OpenTelemetry ENABLE_OTEL=false +OTLP_TRACE_ENDPOINT= +OTLP_METRIC_ENDPOINT= OTLP_BASE_ENDPOINT=http://localhost:4318 OTLP_API_KEY= OTEL_EXPORTER_OTLP_PROTOCOL= diff --git a/api/configs/observability/otel/otel_config.py b/api/configs/observability/otel/otel_config.py index 1b88ddcfe6..7572a696ce 100644 --- a/api/configs/observability/otel/otel_config.py +++ b/api/configs/observability/otel/otel_config.py @@ -12,6 +12,16 @@ class OTelConfig(BaseSettings): default=False, ) + OTLP_TRACE_ENDPOINT: str = Field( + description="OTLP trace endpoint", + default="", + ) + + OTLP_METRIC_ENDPOINT: str = Field( + description="OTLP metric endpoint", + default="", + ) + OTLP_BASE_ENDPOINT: str = Field( description="OTLP base endpoint", default="http://localhost:4318", diff --git a/api/extensions/ext_otel.py b/api/extensions/ext_otel.py index b62b0b60d6..f214589cc6 100644 --- a/api/extensions/ext_otel.py +++ b/api/extensions/ext_otel.py @@ -193,12 +193,19 @@ def init_app(app: DifyApp): insecure=True, ) else: + trace_endpoint = dify_config.OTLP_TRACE_ENDPOINT + if not trace_endpoint: + trace_endpoint = dify_config.OTLP_BASE_ENDPOINT + "/v1/traces" exporter = HTTPSpanExporter( - endpoint=dify_config.OTLP_BASE_ENDPOINT + "/v1/traces", + endpoint=trace_endpoint, headers={"Authorization": f"Bearer {dify_config.OTLP_API_KEY}"}, ) + + metric_endpoint = dify_config.OTLP_METRIC_ENDPOINT + if not metric_endpoint: + metric_endpoint = dify_config.OTLP_BASE_ENDPOINT + "/v1/traces" metric_exporter = HTTPMetricExporter( - endpoint=dify_config.OTLP_BASE_ENDPOINT + "/v1/metrics", + endpoint=metric_endpoint, headers={"Authorization": f"Bearer {dify_config.OTLP_API_KEY}"}, ) else: