Skip to content

Commit f9a01c7

Browse files
dot-agiDwij1704
andauthored
feat: Codebase sanitization to improve maintainability & readability (#1055)
* remove all unused methods * `LiveSpanProcessor` you are no longer live * new deprecation helper utility for warning about deprecation * use deprecation utility for warning about deprecated methods/params * some more modules purged * merge session tests * convert to absolute imports * correct state to `"Indeterminate"` * better docs * this should be `"error"` --------- Co-authored-by: Dwij <96073160+Dwij1704@users.noreply.github.com>
1 parent a61baa6 commit f9a01c7

31 files changed

Lines changed: 637 additions & 636 deletions

agentops/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from opentelemetry.trace.status import StatusCode
2121

2222
from agentops.logging.config import logger
23+
from agentops.helpers.deprecation import deprecated, warn_deprecated_param
2324
import threading
2425

2526
# Thread-safe client management
@@ -40,6 +41,7 @@ def get_client() -> Client:
4041
return _client
4142

4243

44+
@deprecated("Automatically tracked in v4.")
4345
def record(event):
4446
"""
4547
Legacy function to record an event. This is kept for backward compatibility.
@@ -107,6 +109,10 @@ def init(
107109
"""
108110
global _client
109111

112+
# Check for deprecated parameters and emit warnings
113+
if tags is not None:
114+
warn_deprecated_param("tags", "default_tags")
115+
110116
# Merge tags and default_tags if both are provided
111117
merged_tags = None
112118
if tags and default_tags:
@@ -241,7 +247,7 @@ def end_trace(
241247
242248
Args:
243249
trace_context: The TraceContext object returned by start_trace. If None, ends all active traces.
244-
end_state: The final state of the trace (e.g., "Success", "Failure", "Error").
250+
end_state: The final state of the trace (e.g., "Success", "Indeterminate", "Error").
245251
"""
246252
if not tracer.initialized:
247253
logger.warning("AgentOps SDK not initialized. Cannot end trace.")

agentops/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .client import Client
2-
from .api import ApiClient
1+
from agentops.client.client import Client
2+
from agentops.client.api import ApiClient
33

44

55
__all__ = ["Client", "ApiClient"]

agentops/helpers/__init__.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from .time import get_ISO_time, iso_to_unix_nano, from_unix_nano_to_iso
2-
from .serialization import (
1+
from agentops.helpers.time import get_ISO_time
2+
from agentops.helpers.serialization import (
33
AgentOpsJSONEncoder,
44
serialize_uuid,
55
safe_serialize,
66
is_jsonable,
77
filter_unjsonable,
88
)
9-
from .system import (
9+
from agentops.helpers.system import (
1010
get_host_env,
1111
get_sdk_details,
1212
get_os_details,
@@ -17,14 +17,11 @@
1717
get_current_directory,
1818
get_virtual_env,
1919
)
20-
from .version import get_agentops_version, check_agentops_update
21-
from .debug import debug_print_function_params
22-
from .env import get_env_bool, get_env_int, get_env_list
20+
from agentops.helpers.version import get_agentops_version, check_agentops_update
21+
from agentops.helpers.env import get_env_bool, get_env_int, get_env_list
2322

2423
__all__ = [
2524
"get_ISO_time",
26-
"iso_to_unix_nano",
27-
"from_unix_nano_to_iso",
2825
"AgentOpsJSONEncoder",
2926
"serialize_uuid",
3027
"safe_serialize",
@@ -41,7 +38,6 @@
4138
"get_virtual_env",
4239
"get_agentops_version",
4340
"check_agentops_update",
44-
"debug_print_function_params",
4541
"get_env_bool",
4642
"get_env_int",
4743
"get_env_list",

agentops/helpers/debug.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

agentops/helpers/deprecation.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Deprecation utilities for AgentOps SDK.
3+
"""
4+
5+
import functools
6+
from typing import Set, Callable, Any
7+
from agentops.logging import logger
8+
9+
# Track which deprecation warnings have been shown to avoid spam
10+
_shown_warnings: Set[str] = set()
11+
12+
13+
def deprecated(message: str):
14+
"""
15+
Decorator to mark functions as deprecated.
16+
17+
Args:
18+
message: Deprecation message to show
19+
"""
20+
21+
def decorator(func: Callable) -> Callable:
22+
@functools.wraps(func)
23+
def wrapper(*args: Any, **kwargs: Any) -> Any:
24+
warning_key = f"{func.__module__}.{func.__name__}"
25+
if warning_key not in _shown_warnings:
26+
logger.warning(f"{func.__name__}() is deprecated and will be removed in v4 in the future. {message}")
27+
_shown_warnings.add(warning_key)
28+
return func(*args, **kwargs)
29+
30+
return wrapper
31+
32+
return decorator
33+
34+
35+
def warn_deprecated_param(param_name: str, replacement: str = None):
36+
"""
37+
Warn about deprecated parameter usage.
38+
39+
Args:
40+
param_name: Name of the deprecated parameter
41+
replacement: Suggested replacement parameter
42+
"""
43+
warning_key = f"param.{param_name}"
44+
if warning_key not in _shown_warnings:
45+
if replacement:
46+
message = f"Parameter '{param_name}' is deprecated and will be removed in v4 in the future. Use '{replacement}' instead."
47+
else:
48+
message = f"Parameter '{param_name}' is deprecated and will be removed in v4 in the future."
49+
logger.warning(message)
50+
_shown_warnings.add(warning_key)

agentops/helpers/system.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,6 @@ def get_sdk_details():
6161
return {}
6262

6363

64-
def get_python_details():
65-
try:
66-
return {"Python Version": platform.python_version()}
67-
except:
68-
return {}
69-
70-
71-
def get_agentops_details():
72-
try:
73-
return {"AgentOps SDK Version": get_agentops_version()}
74-
except:
75-
return {}
76-
77-
7864
def get_sys_packages():
7965
sys_packages = {}
8066
for module in sys.modules:

agentops/helpers/time.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,3 @@ def get_ISO_time():
99
str: The current UTC time as a string in ISO 8601 format.
1010
"""
1111
return datetime.now(timezone.utc).isoformat()
12-
13-
14-
def iso_to_unix_nano(iso_time: str) -> int:
15-
dt = datetime.fromisoformat(iso_time)
16-
return int(dt.timestamp() * 1_000_000_000)
17-
18-
19-
def from_unix_nano_to_iso(unix_nano: int) -> str:
20-
return datetime.fromtimestamp(unix_nano / 1_000_000_000, timezone.utc).isoformat()

agentops/helpers/validation.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

agentops/instrumentation/ag2/instrumentor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def wrapper(wrapped, instance, args, kwargs):
424424

425425
if tool_type == "function" and isinstance(result, tuple) and len(result) > 0:
426426
success = result[0] if isinstance(result[0], bool) else False
427-
span.set_attribute(ToolAttributes.TOOL_STATUS, "success" if success else "failure")
427+
span.set_attribute(ToolAttributes.TOOL_STATUS, "success" if success else "error")
428428

429429
if len(result) > 1 and isinstance(result[1], dict):
430430
try:
@@ -435,7 +435,7 @@ def wrapper(wrapped, instance, args, kwargs):
435435
if tool_type == "code" and isinstance(result, tuple) and len(result) >= 3:
436436
exit_code = result[0]
437437
span.set_attribute("exit_code", exit_code)
438-
span.set_attribute(ToolAttributes.TOOL_STATUS, "success" if exit_code == 0 else "failure")
438+
span.set_attribute(ToolAttributes.TOOL_STATUS, "success" if exit_code == 0 else "error")
439439

440440
if len(result) > 1 and result[1]:
441441
stdout = result[1]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .attributes import AttributeMap, _extract_attributes_from_mapping
2-
from .wrappers import _with_tracer_wrapper
1+
from agentops.instrumentation.common.attributes import AttributeMap, _extract_attributes_from_mapping
2+
from agentops.instrumentation.common.wrappers import _with_tracer_wrapper
33

44
__all__ = ["AttributeMap", "_extract_attributes_from_mapping", "_with_tracer_wrapper"]

0 commit comments

Comments
 (0)