diff --git a/src/phoenix/config.py b/src/phoenix/config.py index c01e83d748..bd370ef8f8 100644 --- a/src/phoenix/config.py +++ b/src/phoenix/config.py @@ -7,6 +7,7 @@ ENV_PHOENIX_PORT = "PHOENIX_PORT" ENV_PHOENIX_HOST = "PHOENIX_HOST" ENV_NOTEBOOK_ENV = "PHOENIX_NOTEBOOK_ENV" +ENV_TRACE_ENDPOINT = "PHOENIX_TRACE_ENDPOINT" def _get_temp_path() -> Path: @@ -76,3 +77,7 @@ def get_env_port() -> int: def get_env_host() -> str: return os.getenv(ENV_PHOENIX_HOST) or HOST + + +def get_env_trace_endpoint() -> Optional[str]: + return os.getenv(ENV_TRACE_ENDPOINT) or None diff --git a/src/phoenix/trace/exporter.py b/src/phoenix/trace/exporter.py index f7b71fad4e..f46b554f74 100644 --- a/src/phoenix/trace/exporter.py +++ b/src/phoenix/trace/exporter.py @@ -11,7 +11,7 @@ from typing_extensions import TypeAlias import phoenix.trace.v1 as pb -from phoenix.config import get_env_host, get_env_port +from phoenix.config import get_env_host, get_env_port, get_env_trace_endpoint from phoenix.trace.schemas import Span from phoenix.trace.v1.utils import encode @@ -31,6 +31,7 @@ def export(self, _: Any) -> None: class HttpExporter: def __init__( self, + endpoint: Optional[str] = None, host: Optional[str] = None, port: Optional[int] = None, ) -> None: @@ -39,6 +40,10 @@ def __init__( Parameters ---------- + endpoint: Optional[str] + The endpoint of the Phoenix server (collector). This should be set if the Phoenix + server is running on a remote instance. It can also be set using environment + variable `PHOENIX_TRACES_ENDPOINT`, otherwise it defaults to `http://127.0.0.1:6006` host: Optional[str] The host of the Phoenix server. It can also be set using environment variable `PHOENIX_HOST`, otherwise it defaults to `127.0.0.1`. @@ -48,7 +53,9 @@ def __init__( """ self._host = host or get_env_host() self._port = port or get_env_port() - self._base_url = f"http://{self._host}:{self._port}" + endpoint = endpoint or get_env_trace_endpoint() or f"http://{self._host}:{self._port}" + # Make sure the url does not end with a slash + self._base_url = endpoint.rstrip("/") self._warn_if_phoenix_is_not_running() self._session = Session() weakref.finalize(self, self._session.close)