浏览代码

feat: Enable Tracing Support For Phoenix Cloud Instance (#23196)

tags/1.7.2
Ali Saleh 3 个月前
父节点
当前提交
142ab74784
没有帐户链接到提交者的电子邮件

+ 9
- 2
api/core/ops/arize_phoenix_trace/arize_phoenix_trace.py 查看文件

import os import os
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Any, Optional, Union, cast from typing import Any, Optional, Union, cast
from urllib.parse import urlparse


from openinference.semconv.trace import OpenInferenceSpanKindValues, SpanAttributes from openinference.semconv.trace import OpenInferenceSpanKindValues, SpanAttributes
from opentelemetry import trace from opentelemetry import trace
try: try:
# Choose the appropriate exporter based on config type # Choose the appropriate exporter based on config type
exporter: Union[GrpcOTLPSpanExporter, HttpOTLPSpanExporter] exporter: Union[GrpcOTLPSpanExporter, HttpOTLPSpanExporter]

# Inspect the provided endpoint to determine its structure
parsed = urlparse(arize_phoenix_config.endpoint)
base_endpoint = f"{parsed.scheme}://{parsed.netloc}"
path = parsed.path.rstrip("/")

if isinstance(arize_phoenix_config, ArizeConfig): if isinstance(arize_phoenix_config, ArizeConfig):
arize_endpoint = f"{arize_phoenix_config.endpoint}/v1"
arize_endpoint = f"{base_endpoint}/v1"
arize_headers = { arize_headers = {
"api_key": arize_phoenix_config.api_key or "", "api_key": arize_phoenix_config.api_key or "",
"space_id": arize_phoenix_config.space_id or "", "space_id": arize_phoenix_config.space_id or "",
timeout=30, timeout=30,
) )
else: else:
phoenix_endpoint = f"{arize_phoenix_config.endpoint}/v1/traces"
phoenix_endpoint = f"{base_endpoint}{path}/v1/traces"
phoenix_headers = { phoenix_headers = {
"api_key": arize_phoenix_config.api_key or "", "api_key": arize_phoenix_config.api_key or "",
"authorization": f"Bearer {arize_phoenix_config.api_key or ''}", "authorization": f"Bearer {arize_phoenix_config.api_key or ''}",

+ 1
- 1
api/core/ops/entities/config_entity.py 查看文件

@field_validator("endpoint") @field_validator("endpoint")
@classmethod @classmethod
def endpoint_validator(cls, v, info: ValidationInfo): def endpoint_validator(cls, v, info: ValidationInfo):
return cls.validate_endpoint_url(v, "https://app.phoenix.arize.com")
return validate_url_with_path(v, "https://app.phoenix.arize.com")




class LangfuseConfig(BaseTracingConfig): class LangfuseConfig(BaseTracingConfig):

+ 12
- 5
api/tests/unit_tests/core/ops/test_config_entity.py 查看文件

assert config.project == "default" assert config.project == "default"


def test_endpoint_validation_with_path(self): def test_endpoint_validation_with_path(self):
"""Test endpoint validation normalizes URL by removing path"""
config = PhoenixConfig(endpoint="https://custom.phoenix.com/api/v1")
assert config.endpoint == "https://custom.phoenix.com"
"""Test endpoint validation with path"""
config = PhoenixConfig(endpoint="https://app.phoenix.arize.com/s/dify-integration")
assert config.endpoint == "https://app.phoenix.arize.com/s/dify-integration"

def test_endpoint_validation_without_path(self):
"""Test endpoint validation without path"""
config = PhoenixConfig(endpoint="https://app.phoenix.arize.com")
assert config.endpoint == "https://app.phoenix.arize.com"




class TestLangfuseConfig: class TestLangfuseConfig:
"""Test that URL normalization works consistently across configs""" """Test that URL normalization works consistently across configs"""
# Test that paths are removed from endpoints # Test that paths are removed from endpoints
arize_config = ArizeConfig(endpoint="https://arize.com/api/v1/test") arize_config = ArizeConfig(endpoint="https://arize.com/api/v1/test")
phoenix_config = PhoenixConfig(endpoint="https://phoenix.com/api/v2/")
phoenix_with_path_config = PhoenixConfig(endpoint="https://app.phoenix.arize.com/s/dify-integration")
phoenix_without_path_config = PhoenixConfig(endpoint="https://app.phoenix.arize.com")
aliyun_config = AliyunConfig( aliyun_config = AliyunConfig(
license_key="test_license", endpoint="https://tracing-analysis-dc-hz.aliyuncs.com/api/v1/traces" license_key="test_license", endpoint="https://tracing-analysis-dc-hz.aliyuncs.com/api/v1/traces"
) )


assert arize_config.endpoint == "https://arize.com" assert arize_config.endpoint == "https://arize.com"
assert phoenix_config.endpoint == "https://phoenix.com"
assert phoenix_with_path_config.endpoint == "https://app.phoenix.arize.com/s/dify-integration"
assert phoenix_without_path_config.endpoint == "https://app.phoenix.arize.com"
assert aliyun_config.endpoint == "https://tracing-analysis-dc-hz.aliyuncs.com" assert aliyun_config.endpoint == "https://tracing-analysis-dc-hz.aliyuncs.com"


def test_project_default_values(self): def test_project_default_values(self):

正在加载...
取消
保存