mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 14:23:44 +00:00
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:
@@ -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()
|
||||
Reference in New Issue
Block a user