Skip to content

Commit dcb7e55

Browse files
committed
feat: add log_session_replay_url configuration option
1 parent 6465823 commit dcb7e55

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

agentops/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def init(
9090
env_data_opt_out: Optional[bool] = None,
9191
log_level: Optional[Union[str, int]] = None,
9292
fail_safe: Optional[bool] = None,
93+
log_session_replay_url: Optional[bool] = None,
9394
exporter_endpoint: Optional[str] = None,
9495
**kwargs,
9596
):
@@ -117,6 +118,7 @@ def init(
117118
env_data_opt_out (bool): Whether to opt out of collecting environment data.
118119
log_level (str, int): The log level to use for the client. Defaults to 'CRITICAL'.
119120
fail_safe (bool): Whether to suppress errors and continue execution when possible.
121+
log_session_replay_url (bool): Whether to log session replay URLs to the console. Defaults to True.
120122
exporter_endpoint (str, optional): Endpoint for the exporter. If none is provided, key will
121123
be read from the AGENTOPS_EXPORTER_ENDPOINT environment variable.
122124
**kwargs: Additional configuration parameters to be passed to the client.
@@ -159,6 +161,7 @@ def init(
159161
"env_data_opt_out": env_data_opt_out,
160162
"log_level": log_level,
161163
"fail_safe": fail_safe,
164+
"log_session_replay_url": log_session_replay_url,
162165
"exporter_endpoint": exporter_endpoint,
163166
**kwargs,
164167
}

agentops/config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ConfigDict(TypedDict):
3131
log_level: Optional[Union[str, int]]
3232
fail_safe: Optional[bool]
3333
prefetch_jwt_token: Optional[bool]
34+
log_session_replay_url: Optional[bool]
3435

3536

3637
@dataclass
@@ -115,6 +116,11 @@ class Config:
115116
metadata={"description": "Whether to prefetch JWT token during initialization"},
116117
)
117118

119+
log_session_replay_url: bool = field(
120+
default_factory=lambda: get_env_bool("AGENTOPS_LOG_SESSION_REPLAY_URL", True),
121+
metadata={"description": "Whether to log session replay URLs to the console"},
122+
)
123+
118124
exporter_endpoint: Optional[str] = field(
119125
default_factory=lambda: os.getenv("AGENTOPS_EXPORTER_ENDPOINT", "https://otlp.agentops.ai/v1/traces"),
120126
metadata={
@@ -148,6 +154,7 @@ def configure(
148154
log_level: Optional[Union[str, int]] = None,
149155
fail_safe: Optional[bool] = None,
150156
prefetch_jwt_token: Optional[bool] = None,
157+
log_session_replay_url: Optional[bool] = None,
151158
exporter: Optional[SpanExporter] = None,
152159
processor: Optional[SpanProcessor] = None,
153160
exporter_endpoint: Optional[str] = None,
@@ -213,6 +220,9 @@ def configure(
213220
if prefetch_jwt_token is not None:
214221
self.prefetch_jwt_token = prefetch_jwt_token
215222

223+
if log_session_replay_url is not None:
224+
self.log_session_replay_url = log_session_replay_url
225+
216226
if exporter is not None:
217227
self.exporter = exporter
218228

@@ -243,6 +253,7 @@ def dict(self):
243253
"log_level": self.log_level,
244254
"fail_safe": self.fail_safe,
245255
"prefetch_jwt_token": self.prefetch_jwt_token,
256+
"log_session_replay_url": self.log_session_replay_url,
246257
"exporter": self.exporter,
247258
"processor": self.processor,
248259
"exporter_endpoint": self.exporter_endpoint,

agentops/helpers/dashboard.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ def log_trace_url(span: Union[Span, ReadableSpan], title: Optional[str] = None)
3939
4040
Args:
4141
span: The span to log the URL for.
42+
title: Optional title for the trace.
4243
"""
44+
from agentops import get_client
45+
46+
try:
47+
client = get_client()
48+
if not client.config.log_session_replay_url:
49+
return
50+
except Exception:
51+
return
52+
4353
session_url = get_trace_url(span)
4454
logger.info(colored(f"\x1b[34mSession Replay for {title} trace: {session_url}\x1b[0m", "blue"))

0 commit comments

Comments
 (0)