Skip to content

Commit

Permalink
Updated trace url link (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverre authored Oct 11, 2024
1 parent 29ca4fe commit 8a29238
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
18 changes: 17 additions & 1 deletion sdks/python/src/opik/api_objects/opik_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ..rest_api import client as rest_api_client
from ..rest_api.types import dataset_public, trace_public, span_public, project_public
from ..rest_api.core.api_error import ApiError
from .. import datetime_helpers, config, httpx_client
from .. import datetime_helpers, config, httpx_client, url_helpers


LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -51,6 +51,7 @@ def __init__(
self._workspace: str = config_.workspace
self._project_name: str = config_.project_name
self._flush_timeout: Optional[int] = config_.default_flush_timeout
self._project_name_most_recent_trace: Optional[str] = None

self._initialize_streamer(
base_url=config_.url_override,
Expand Down Expand Up @@ -79,6 +80,18 @@ def _initialize_streamer(
use_batching=use_batching,
)

def _display_trace_url(self, workspace: str, project_name: str) -> None:
projects_url = url_helpers.get_projects_url(workspace=workspace)

if (
self._project_name_most_recent_trace is None
or self._project_name_most_recent_trace != project_name
):
LOGGER.info(
f'Started logging traces to the "{project_name}" project at {projects_url}.'
)
self._project_name_most_recent_trace = project_name

def trace(
self,
id: Optional[str] = None,
Expand Down Expand Up @@ -126,6 +139,9 @@ def trace(
tags=tags,
)
self._streamer.put(create_trace_message)
self._display_trace_url(
workspace=self._workspace, project_name=project_name or self._project_name
)

if feedback_scores is not None:
for feedback_score in feedback_scores:
Expand Down
18 changes: 0 additions & 18 deletions sdks/python/src/opik/message_processing/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from .. import synchronization
from .batching import batch_manager

from .. import url_helpers

LOGGER = logging.getLogger(__name__)


Expand All @@ -31,9 +29,6 @@ def __init__(
if self._batch_manager is not None:
self._batch_manager.start()

# Used to know when to display the project URL
self._project_name_most_recent_trace: Optional[str] = None

def put(self, message: messages.BaseMessage) -> None:
with self._lock:
if self._drain:
Expand All @@ -47,19 +42,6 @@ def put(self, message: messages.BaseMessage) -> None:
else:
self._message_queue.put(message)

# Display message in console
if isinstance(message, messages.CreateTraceMessage):
projects_url = url_helpers.get_projects_url()
project_name = message.project_name
if (
self._project_name_most_recent_trace is None
or self._project_name_most_recent_trace != project_name
):
LOGGER.info(
f'Started logging traces to the "{project_name}" project at {projects_url}.'
)
self._project_name_most_recent_trace = project_name

def close(self, timeout: Optional[int]) -> bool:
"""
Stops data sending threads
Expand Down
7 changes: 2 additions & 5 deletions sdks/python/src/opik/url_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import opik.config
import opik.api_objects.opik_client


def get_ui_url() -> str:
Expand All @@ -24,8 +23,6 @@ def get_experiment_url(dataset_name: str, experiment_id: str) -> str:
return f"{ui_url}/{config.workspace}/experiments/{dataset_id}/compare?experiments=%5B%22{experiment_id}%22%5D"


def get_projects_url() -> str:
config = opik.config.OpikConfig()
def get_projects_url(workspace: str) -> str:
ui_url = get_ui_url()

return f"{ui_url}/{config.workspace}/projects"
return f"{ui_url}/{workspace}/projects"

0 comments on commit 8a29238

Please sign in to comment.