Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(traces): configurable endpoint for the exporter #1795

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

@RogerHYang RogerHYang Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep it generic?

Suggested change
ENV_TRACE_ENDPOINT = "PHOENIX_TRACE_ENDPOINT"
ENV_PHOENIX_RECEIVER_ENDPOINT = "PHOENIX_RECEIVER_ENDPOINT"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah evals. Was copying OTEL naming but maybe I'll just call it collector



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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return os.getenv(ENV_TRACE_ENDPOINT) or None
return os.getenv(ENV_TRACE_ENDPOINT)

os.getenv returns None if the environment variable can't be found.

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
Loading