Skip to content

Commit

Permalink
feat(traces): configurable endpoint for the exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeldking committed Nov 21, 2023
1 parent 20ab6e5 commit 57cfe3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/phoenix/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
11 changes: 9 additions & 2 deletions src/phoenix/trace/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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`.
Expand All @@ -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)
Expand Down

0 comments on commit 57cfe3c

Please sign in to comment.