update ot endpoint config

pull/22492/head
hieheihei 10 months ago
parent da53bf511f
commit cdadf6f7cd

@ -505,6 +505,8 @@ LOGIN_LOCKOUT_DURATION=86400
# Enable OpenTelemetry # Enable OpenTelemetry
ENABLE_OTEL=false ENABLE_OTEL=false
OTLP_TRACE_ENDPOINT=
OTLP_METRIC_ENDPOINT=
OTLP_BASE_ENDPOINT=http://localhost:4318 OTLP_BASE_ENDPOINT=http://localhost:4318
OTLP_API_KEY= OTLP_API_KEY=
OTEL_EXPORTER_OTLP_PROTOCOL= OTEL_EXPORTER_OTLP_PROTOCOL=

@ -12,6 +12,16 @@ class OTelConfig(BaseSettings):
default=False, 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( OTLP_BASE_ENDPOINT: str = Field(
description="OTLP base endpoint", description="OTLP base endpoint",
default="http://localhost:4318", default="http://localhost:4318",

@ -193,12 +193,19 @@ def init_app(app: DifyApp):
insecure=True, insecure=True,
) )
else: else:
trace_endpoint = dify_config.OTLP_TRACE_ENDPOINT
if not trace_endpoint:
trace_endpoint = dify_config.OTLP_BASE_ENDPOINT + "/v1/traces"
exporter = HTTPSpanExporter( exporter = HTTPSpanExporter(
endpoint=dify_config.OTLP_BASE_ENDPOINT + "/v1/traces", endpoint=trace_endpoint,
headers={"Authorization": f"Bearer {dify_config.OTLP_API_KEY}"}, 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( metric_exporter = HTTPMetricExporter(
endpoint=dify_config.OTLP_BASE_ENDPOINT + "/v1/metrics", endpoint=metric_endpoint,
headers={"Authorization": f"Bearer {dify_config.OTLP_API_KEY}"}, headers={"Authorization": f"Bearer {dify_config.OTLP_API_KEY}"},
) )
else: else:

Loading…
Cancel
Save