Skip to content

Commit c9faca8

Browse files
teocnsdot-agidevin-ai-integration[bot]Constantin-Doru Teodorescutcdent
authored
0.4.4 (#848)
* 0.4.4 Signed-off-by: Teo <[email protected]> * Client.init() | auto_start_session | forward tags Signed-off-by: Teo <[email protected]> * client: recreate Config on init() Signed-off-by: Teo <[email protected]> * mock_req: /v3/auth/token to return { project_id, token, api_key } Signed-off-by: Teo <[email protected]> * cleanup dirty files Signed-off-by: Teo <[email protected]> * Isolate telemetry setup (`setup_telemetry`) Signed-off-by: Teo <[email protected]> * core shutdown: remove redundant initialized check Signed-off-by: Teo <[email protected]> * Simplify core shutdown (flush SynchronousSpanProcessor instead of iterating processors) Signed-off-by: Teo <[email protected]> * Improved TracingCore Config Signed-off-by: Teo <[email protected]> * tests: couple instrumentation tester with TracingCore's lifecycle Signed-off-by: Teo <[email protected]> * Base for test_session_legacy Signed-off-by: Teo <[email protected]> * uv lock Signed-off-by: Teo <[email protected]> * tests/benchmark/benchmark_init.py Signed-off-by: Teo <[email protected]> * Remove deprecated SDK tests - favor test_decorators Signed-off-by: Teo <[email protected]> * update `openai` dep and `uv.lock` file * fix: display session url when using `agentops.init` (#856) * show session url on init * fix: pass tags to start_session when auto-starting sessions Co-Authored-By: Constantin-Doru Teodorescu <[email protected]> * backwards compat: track_agent, end_all_sessions (#847) Signed-off-by: Teo <[email protected]> * Client.init() | auto_start_session | forward tags Signed-off-by: Teo <[email protected]> * client: recreate Config on init() Signed-off-by: Teo <[email protected]> * mock_req: /v3/auth/token to return { project_id, token, api_key } Signed-off-by: Teo <[email protected]> * cleanup dirty files Signed-off-by: Teo <[email protected]> * Isolate telemetry setup (`setup_telemetry`) Signed-off-by: Teo <[email protected]> * core shutdown: remove redundant initialized check Signed-off-by: Teo <[email protected]> * Simplify core shutdown (flush SynchronousSpanProcessor instead of iterating processors) Signed-off-by: Teo <[email protected]> * Improved TracingCore Config Signed-off-by: Teo <[email protected]> * tests: couple instrumentation tester with TracingCore's lifecycle Signed-off-by: Teo <[email protected]> * Base for test_session_legacy Signed-off-by: Teo <[email protected]> * uv lock Signed-off-by: Teo <[email protected]> * tests/benchmark/benchmark_init.py Signed-off-by: Teo <[email protected]> * Remove deprecated SDK tests - favor test_decorators Signed-off-by: Teo <[email protected]> * update `openai` dep and `uv.lock` file * fix: pass tags to start_session when auto-starting sessions Co-Authored-By: Constantin-Doru Teodorescu <[email protected]> * forgot `{` in `start_session` * remove `getattr` * fix for recursion and passing `default_tags` * client: recreate Config on init() Signed-off-by: Teo <[email protected]> * cleanup dirty files Signed-off-by: Teo <[email protected]> * Simplify core shutdown (flush SynchronousSpanProcessor instead of iterating processors) Signed-off-by: Teo <[email protected]> --------- Signed-off-by: Teo <[email protected]> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Constantin-Doru Teodorescu <[email protected]> Co-authored-by: teocns <[email protected]> Co-authored-by: Teo <[email protected]> * `auto_start_session` must be `False` by default * Legacy session support on `end_session`. Backwards-compatible `record` event. * CrewAI compat tests. track_tool decorator for compat. * Use valid type. * I don't think Event ever passed type checks. * Type checking runs clean. Fix import. * Auto start sessions. * track_agent noop should be a decorator * Handle trace lifecycle in legacy with backwards compatibility for Crew 105 and Crew < 105. * drop session export delay to one second and expose it as a public configuration parameter. * Clean up docstrings in legacy * type checking * agentops.config: dataclass -slots | compat 3.9 Signed-off-by: Teo <[email protected]> * deps: py3.9 backward compat | constraints | resolver Signed-off-by: Teo <[email protected]> --------- Signed-off-by: Teo <[email protected]> Co-authored-by: Pratyush Shukla <[email protected]> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Constantin-Doru Teodorescu <[email protected]> Co-authored-by: Travis Dent <[email protected]>
1 parent d5dcdde commit c9faca8

26 files changed

+888
-1478
lines changed

agentops/__init__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
from typing import Any, Dict, List, Optional, Union
22

3-
from agentops.legacy import ErrorEvent, ToolEvent, end_session, start_session
3+
from agentops.legacy import ActionEvent, ErrorEvent, ToolEvent, start_session, end_session
44

55
from .client import Client
66

77
# Client global instance; one per process runtime
88
_client = Client()
99

10+
def record(event):
11+
"""
12+
Legacy function to record an event. This is kept for backward compatibility.
13+
14+
In the current version, this simply sets the end_timestamp on the event.
15+
16+
Args:
17+
event: The event to record
18+
"""
19+
from agentops.helpers.time import get_ISO_time
20+
21+
# TODO: Manual timestamp assignment is a temporary fix; should use proper event lifecycle
22+
if event and hasattr(event, 'end_timestamp'):
23+
event.end_timestamp = get_ISO_time()
24+
25+
return event
26+
1027

1128
def init(
1229
api_key: Optional[str] = None,
@@ -139,6 +156,9 @@ def get_client() -> Client:
139156
"init",
140157
"configure",
141158
"get_client",
159+
"record",
142160
"start_session",
143161
"end_session",
162+
"track_agent",
163+
"track_tool",
144164
]

agentops/client/client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def __init__(self):
2929
self.config = Config()
3030

3131
def init(self, **kwargs):
32+
# Recreate the Config object to parse environment variables at the time of initialization
33+
self.config = Config()
3234
self.configure(**kwargs)
3335

3436
if not self.config.api_key:
@@ -56,10 +58,18 @@ def init(self, **kwargs):
5658

5759
self.initialized = True
5860

61+
# Start a session if auto_start_session is True
62+
session = None
5963
if self.config.auto_start_session:
6064
from agentops.legacy import start_session
6165

62-
start_session()
66+
# Pass default_tags if they exist
67+
if self.config.default_tags:
68+
session = start_session(tags=list(self.config.default_tags))
69+
else:
70+
session = start_session()
71+
72+
return session
6373

6474
def configure(self, **kwargs):
6575
"""Update client configuration"""

agentops/config.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ConfigDict(TypedDict):
2020
api_key: Optional[str]
2121
endpoint: Optional[str]
2222
max_wait_time: Optional[int]
23+
export_flush_interval: Optional[int]
2324
max_queue_size: Optional[int]
2425
default_tags: Optional[List[str]]
2526
instrument_llm_calls: Optional[bool]
@@ -32,7 +33,7 @@ class ConfigDict(TypedDict):
3233
prefetch_jwt_token: Optional[bool]
3334

3435

35-
@dataclass(slots=True)
36+
@dataclass
3637
class Config:
3738
api_key: Optional[str] = field(
3839
default_factory=lambda: os.getenv("AGENTOPS_API_KEY"),
@@ -48,6 +49,11 @@ class Config:
4849
default_factory=lambda: get_env_int("AGENTOPS_MAX_WAIT_TIME", 5000),
4950
metadata={"description": "Maximum time in milliseconds to wait for API responses"},
5051
)
52+
53+
export_flush_interval: int = field(
54+
default_factory=lambda: get_env_int("AGENTOPS_EXPORT_FLUSH_INTERVAL", 1000),
55+
metadata={"description": "Time interval in milliseconds between automatic exports of telemetry data"},
56+
)
5157

5258
max_queue_size: int = field(
5359
default_factory=lambda: get_env_int("AGENTOPS_MAX_QUEUE_SIZE", 512),
@@ -65,7 +71,7 @@ class Config:
6571
)
6672

6773
auto_start_session: bool = field(
68-
default_factory=lambda: get_env_bool("AGENTOPS_AUTO_START_SESSION", False),
74+
default_factory=lambda: get_env_bool("AGENTOPS_AUTO_START_SESSION", True),
6975
metadata={"description": "Whether to automatically start a session when initializing"},
7076
)
7177

@@ -85,7 +91,7 @@ class Config:
8591
)
8692

8793
log_level: Union[str, int] = field(
88-
default_factory=lambda: os.getenv("AGENTOPS_LOG_LEVEL", "WARNING"),
94+
default_factory=lambda: os.getenv("AGENTOPS_LOG_LEVEL", "INFO"),
8995
metadata={"description": "Logging level for AgentOps logs"},
9096
)
9197

@@ -119,6 +125,7 @@ def configure(
119125
api_key: Optional[str] = None,
120126
endpoint: Optional[str] = None,
121127
max_wait_time: Optional[int] = None,
128+
export_flush_interval: Optional[int] = None,
122129
max_queue_size: Optional[int] = None,
123130
default_tags: Optional[List[str]] = None,
124131
instrument_llm_calls: Optional[bool] = None,
@@ -147,6 +154,9 @@ def configure(
147154

148155
if max_wait_time is not None:
149156
self.max_wait_time = max_wait_time
157+
158+
if export_flush_interval is not None:
159+
self.export_flush_interval = export_flush_interval
150160

151161
if max_queue_size is not None:
152162
self.max_queue_size = max_queue_size
@@ -170,7 +180,14 @@ def configure(
170180
self.env_data_opt_out = env_data_opt_out
171181

172182
if log_level is not None:
173-
self.log_level = log_level
183+
if isinstance(log_level, str):
184+
log_level_str = log_level.upper()
185+
if hasattr(logging, log_level_str):
186+
self.log_level = getattr(logging, log_level_str)
187+
else:
188+
self.log_level = logging.INFO
189+
else:
190+
self.log_level = log_level
174191

175192
if fail_safe is not None:
176193
self.fail_safe = fail_safe
@@ -195,6 +212,7 @@ def dict(self):
195212
"api_key": self.api_key,
196213
"endpoint": self.endpoint,
197214
"max_wait_time": self.max_wait_time,
215+
"export_flush_interval": self.export_flush_interval,
198216
"max_queue_size": self.max_queue_size,
199217
"default_tags": self.default_tags,
200218
"instrument_llm_calls": self.instrument_llm_calls,

agentops/instrumentation/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dataclasses import dataclass
44
import importlib
55

6-
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore
77

88
from agentops.logging import logger
99
from agentops.sdk.core import TracingCore

0 commit comments

Comments
 (0)