fix: URL encode OTEL_EXPORTER_OTLP_TRACES_HEADERS for Phoenix Integration (#10654)

* fix: URL encode OTEL_EXPORTER_OTLP_TRACES_HEADERS for Arize Phoenix integration

- Add URL encoding for Bearer token in authorization header
- Follow OpenTelemetry Protocol Exporter specification
- Fix header format validation error in Phoenix integration

* add mock test for arize phoenix
This commit is contained in:
Dat Daryl Ngo
2025-05-13 09:45:39 -07:00
committed by GitHub
parent 3130c4f8f9
commit f1136fd217
2 changed files with 36 additions and 1 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import os
import urllib.parse
from typing import TYPE_CHECKING, Any, Union
from litellm._logging import verbose_logger
@@ -69,7 +70,7 @@ class ArizePhoenixLogger:
otlp_auth_headers = f"api_key={api_key}"
elif api_key is not None:
# api_key/auth is optional for self hosted phoenix
otlp_auth_headers = f"Authorization=Bearer {api_key}"
otlp_auth_headers = f"Authorization={urllib.parse.quote(f'Bearer {api_key}')}"
return ArizePhoenixConfig(
otlp_auth_headers=otlp_auth_headers, protocol=protocol, endpoint=endpoint
@@ -0,0 +1,34 @@
import unittest
from unittest.mock import patch
from litellm.integrations.arize.arize_phoenix import ArizePhoenixLogger
class TestArizePhoenixConfig(unittest.TestCase):
@patch.dict('os.environ', {
'PHOENIX_API_KEY': 'test_api_key',
'PHOENIX_COLLECTOR_HTTP_ENDPOINT': 'http://test.endpoint'
})
def test_get_arize_phoenix_config_http(self):
# Call the function to get the configuration
config = ArizePhoenixLogger.get_arize_phoenix_config()
# Verify the configuration
self.assertEqual(config.otlp_auth_headers, 'Authorization=Bearer%20test_api_key')
self.assertEqual(config.endpoint, 'http://test.endpoint')
self.assertEqual(config.protocol, 'otlp_http')
@patch.dict('os.environ', {
'PHOENIX_API_KEY': 'test_api_key',
'PHOENIX_COLLECTOR_ENDPOINT': 'grpc://test.endpoint'
})
def test_get_arize_phoenix_config_grpc(self):
# Call the function to get the configuration
config = ArizePhoenixLogger.get_arize_phoenix_config()
# Verify the configuration
self.assertEqual(config.otlp_auth_headers, 'Authorization=Bearer%20test_api_key')
self.assertEqual(config.endpoint, 'grpc://test.endpoint')
self.assertEqual(config.protocol, 'otlp_grpc')
if __name__ == '__main__':
unittest.main()