Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion agentops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from opentelemetry.trace.status import StatusCode

from agentops.logging.config import logger
from agentops.helpers.deprecation import deprecated, warn_deprecated_param
import threading

# Thread-safe client management
Expand All @@ -40,6 +41,7 @@
return _client


@deprecated("Automatically tracked in v4.")
def record(event):
"""
Legacy function to record an event. This is kept for backward compatibility.
Expand Down Expand Up @@ -107,6 +109,10 @@
"""
global _client

# Check for deprecated parameters and emit warnings
if tags is not None:
warn_deprecated_param("tags", "default_tags")

Check warning on line 114 in agentops/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentops/__init__.py#L114

Added line #L114 was not covered by tests

# Merge tags and default_tags if both are provided
merged_tags = None
if tags and default_tags:
Expand Down Expand Up @@ -241,7 +247,7 @@

Args:
trace_context: The TraceContext object returned by start_trace. If None, ends all active traces.
end_state: The final state of the trace (e.g., "Success", "Failure", "Error").
end_state: The final state of the trace (e.g., "Success", "Indeterminate", "Error").
"""
if not tracer.initialized:
logger.warning("AgentOps SDK not initialized. Cannot end trace.")
Expand Down
4 changes: 2 additions & 2 deletions agentops/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .client import Client
from .api import ApiClient
from agentops.client.client import Client
from agentops.client.api import ApiClient


__all__ = ["Client", "ApiClient"]
14 changes: 5 additions & 9 deletions agentops/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from .time import get_ISO_time, iso_to_unix_nano, from_unix_nano_to_iso
from .serialization import (
from agentops.helpers.time import get_ISO_time
from agentops.helpers.serialization import (
AgentOpsJSONEncoder,
serialize_uuid,
safe_serialize,
is_jsonable,
filter_unjsonable,
)
from .system import (
from agentops.helpers.system import (
get_host_env,
get_sdk_details,
get_os_details,
Expand All @@ -17,14 +17,11 @@
get_current_directory,
get_virtual_env,
)
from .version import get_agentops_version, check_agentops_update
from .debug import debug_print_function_params
from .env import get_env_bool, get_env_int, get_env_list
from agentops.helpers.version import get_agentops_version, check_agentops_update
from agentops.helpers.env import get_env_bool, get_env_int, get_env_list

__all__ = [
"get_ISO_time",
"iso_to_unix_nano",
"from_unix_nano_to_iso",
"AgentOpsJSONEncoder",
"serialize_uuid",
"safe_serialize",
Expand All @@ -41,7 +38,6 @@
"get_virtual_env",
"get_agentops_version",
"check_agentops_update",
"debug_print_function_params",
"get_env_bool",
"get_env_int",
"get_env_list",
Expand Down
20 changes: 0 additions & 20 deletions agentops/helpers/debug.py

This file was deleted.

50 changes: 50 additions & 0 deletions agentops/helpers/deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Deprecation utilities for AgentOps SDK.
"""

import functools
from typing import Set, Callable, Any
from agentops.logging import logger

# Track which deprecation warnings have been shown to avoid spam
_shown_warnings: Set[str] = set()


def deprecated(message: str):
"""
Decorator to mark functions as deprecated.

Args:
message: Deprecation message to show
"""

def decorator(func: Callable) -> Callable:
@functools.wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Any:
warning_key = f"{func.__module__}.{func.__name__}"
if warning_key not in _shown_warnings:
logger.warning(f"{func.__name__}() is deprecated and will be removed in v4 in the future. {message}")
_shown_warnings.add(warning_key)
return func(*args, **kwargs)

return wrapper

return decorator


def warn_deprecated_param(param_name: str, replacement: str = None):
"""
Warn about deprecated parameter usage.

Args:
param_name: Name of the deprecated parameter
replacement: Suggested replacement parameter
"""
warning_key = f"param.{param_name}"
if warning_key not in _shown_warnings:
if replacement:
message = f"Parameter '{param_name}' is deprecated and will be removed in v4 in the future. Use '{replacement}' instead."

Check warning on line 46 in agentops/helpers/deprecation.py

View check run for this annotation

Codecov / codecov/patch

agentops/helpers/deprecation.py#L43-L46

Added lines #L43 - L46 were not covered by tests
else:
message = f"Parameter '{param_name}' is deprecated and will be removed in v4 in the future."
logger.warning(message)
_shown_warnings.add(warning_key)

Check warning on line 50 in agentops/helpers/deprecation.py

View check run for this annotation

Codecov / codecov/patch

agentops/helpers/deprecation.py#L48-L50

Added lines #L48 - L50 were not covered by tests
14 changes: 0 additions & 14 deletions agentops/helpers/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,6 @@ def get_sdk_details():
return {}


def get_python_details():
try:
return {"Python Version": platform.python_version()}
except:
return {}


def get_agentops_details():
try:
return {"AgentOps SDK Version": get_agentops_version()}
except:
return {}


def get_sys_packages():
sys_packages = {}
for module in sys.modules:
Expand Down
9 changes: 0 additions & 9 deletions agentops/helpers/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,3 @@ def get_ISO_time():
str: The current UTC time as a string in ISO 8601 format.
"""
return datetime.now(timezone.utc).isoformat()


def iso_to_unix_nano(iso_time: str) -> int:
dt = datetime.fromisoformat(iso_time)
return int(dt.timestamp() * 1_000_000_000)


def from_unix_nano_to_iso(unix_nano: int) -> str:
return datetime.fromtimestamp(unix_nano / 1_000_000_000, timezone.utc).isoformat()
8 changes: 0 additions & 8 deletions agentops/helpers/validation.py

This file was deleted.

4 changes: 2 additions & 2 deletions agentops/instrumentation/ag2/instrumentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@

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

Check warning on line 427 in agentops/instrumentation/ag2/instrumentor.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/ag2/instrumentor.py#L427

Added line #L427 was not covered by tests

if len(result) > 1 and isinstance(result[1], dict):
try:
Expand All @@ -435,7 +435,7 @@
if tool_type == "code" and isinstance(result, tuple) and len(result) >= 3:
exit_code = result[0]
span.set_attribute("exit_code", exit_code)
span.set_attribute(ToolAttributes.TOOL_STATUS, "success" if exit_code == 0 else "failure")
span.set_attribute(ToolAttributes.TOOL_STATUS, "success" if exit_code == 0 else "error")

Check warning on line 438 in agentops/instrumentation/ag2/instrumentor.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/ag2/instrumentor.py#L438

Added line #L438 was not covered by tests

if len(result) > 1 and result[1]:
stdout = result[1]
Expand Down
4 changes: 2 additions & 2 deletions agentops/instrumentation/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .attributes import AttributeMap, _extract_attributes_from_mapping
from .wrappers import _with_tracer_wrapper
from agentops.instrumentation.common.attributes import AttributeMap, _extract_attributes_from_mapping
from agentops.instrumentation.common.wrappers import _with_tracer_wrapper

__all__ = ["AttributeMap", "_extract_attributes_from_mapping", "_with_tracer_wrapper"]
2 changes: 1 addition & 1 deletion agentops/instrumentation/common/objects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from agentops.client.api.types import UploadedObjectResponse
from . import AttributeMap, _extract_attributes_from_mapping
from agentops.instrumentation.common import AttributeMap, _extract_attributes_from_mapping


UPLOADED_OBJECT_ATTRIBUTES: AttributeMap = {
Expand Down
2 changes: 1 addition & 1 deletion agentops/instrumentation/crewai/instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from agentops.instrumentation.crewai.version import __version__
from agentops.semconv import SpanAttributes, AgentOpsSpanKindValues, Meters, ToolAttributes, MessageAttributes
from agentops.semconv.core import CoreAttributes
from .crewai_span_attributes import CrewAISpanAttributes, set_span_attribute
from agentops.instrumentation.crewai.crewai_span_attributes import CrewAISpanAttributes, set_span_attribute

Check warning on line 17 in agentops/instrumentation/crewai/instrumentation.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/crewai/instrumentation.py#L17

Added line #L17 was not covered by tests
from agentops import get_client

# Initialize logger
Expand Down
2 changes: 1 addition & 1 deletion agentops/instrumentation/openai_agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_version() -> str:
LIBRARY_VERSION: str = get_version()

# Import after defining constants to avoid circular imports
from .instrumentor import OpenAIAgentsInstrumentor # noqa: E402
from agentops.instrumentation.openai_agents.instrumentor import OpenAIAgentsInstrumentor # noqa: E402

__all__ = [
"LIBRARY_NAME",
Expand Down
20 changes: 15 additions & 5 deletions agentops/legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from agentops.logging import logger
from agentops.sdk.core import TraceContext, tracer
from agentops.helpers.deprecation import deprecated

_current_session: Optional["Session"] = None
_current_trace_context: Optional[TraceContext] = None
Expand Down Expand Up @@ -60,6 +61,7 @@ def end_session(self, **kwargs: Any):
end_session(session_or_status=self, **kwargs)


@deprecated("Use agentops.start_trace() instead.")
def start_session(
tags: Union[Dict[str, Any], List[str], None] = None,
) -> Session:
Expand Down Expand Up @@ -121,6 +123,7 @@ def _set_span_attributes(span: Any, attributes: Dict[str, Any]) -> None:
span.set_attribute(f"agentops.legacy.{key}", str(value))


@deprecated("Use agentops.end_trace() instead.")
def end_session(session_or_status: Any = None, **kwargs: Any) -> None:
"""
@deprecated Use agentops.end_trace() instead.
Expand Down Expand Up @@ -186,6 +189,7 @@ def end_session(session_or_status: Any = None, **kwargs: Any) -> None:
pass


@deprecated("Use agentops.end_trace() instead.")
def end_all_sessions() -> None:
"""@deprecated Ends all active sessions/traces."""
if not tracer.initialized:
Expand All @@ -201,13 +205,15 @@ def end_all_sessions() -> None:
_current_trace_context = None


@deprecated("Automatically tracked in v4.")
def ToolEvent(*args: Any, **kwargs: Any) -> None:
"""@deprecated Use tracing instead."""
"""@deprecated Automatically tracked in v4."""
return None


@deprecated("Automatically tracked in v4.")
def ErrorEvent(*args: Any, **kwargs: Any) -> Any:
"""@deprecated Use tracing instead. Returns minimal object for test compatibility."""
"""@deprecated Automatically tracked in v4. Returns minimal object for test compatibility."""
from agentops.helpers.time import get_ISO_time

class LegacyErrorEvent:
Expand All @@ -218,8 +224,9 @@ def __init__(self):
return LegacyErrorEvent()


@deprecated("Automatically tracked in v4.")
def ActionEvent(*args: Any, **kwargs: Any) -> Any:
"""@deprecated Use tracing instead. Returns minimal object for test compatibility."""
"""@deprecated Automatically tracked in v4. Returns minimal object for test compatibility."""
from agentops.helpers.time import get_ISO_time

class LegacyActionEvent:
Expand All @@ -230,11 +237,13 @@ def __init__(self):
return LegacyActionEvent()


@deprecated("Automatically tracked in v4.")
def LLMEvent(*args: Any, **kwargs: Any) -> None:
"""@deprecated Use tracing instead."""
"""@deprecated Automatically tracked in v4."""
return None


@deprecated("Use @agent decorator instead.")
def track_agent(*args: Any, **kwargs: Any) -> Any:
"""@deprecated No-op decorator."""

Expand All @@ -244,6 +253,7 @@ def noop(f: Any) -> Any:
return noop


@deprecated("Use @tool decorator instead.")
def track_tool(*args: Any, **kwargs: Any) -> Any:
"""@deprecated No-op decorator."""

Expand All @@ -262,6 +272,6 @@ def noop(f: Any) -> Any:
"track_agent",
"track_tool",
"end_all_sessions",
"Session", # Exposing the legacy Session class itself
"Session",
"LLMEvent",
]
4 changes: 2 additions & 2 deletions agentops/logging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .config import configure_logging, logger
from .instrument_logging import setup_print_logger, upload_logfile
from agentops.logging.config import configure_logging, logger
from agentops.logging.instrument_logging import setup_print_logger, upload_logfile

__all__ = ["logger", "configure_logging", "setup_print_logger", "upload_logfile"]
2 changes: 1 addition & 1 deletion agentops/logging/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os

from .formatters import AgentOpsLogFileFormatter, AgentOpsLogFormatter
from agentops.logging.formatters import AgentOpsLogFileFormatter, AgentOpsLogFormatter

# Create the logger at module level
logger = logging.getLogger("agentops")
Expand Down
Loading
Loading