Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
817d1a1
Cleanup __init__.py from legacy implementations
teocns Mar 13, 2025
b7cc190
Format: core.py
teocns Mar 13, 2025
94229b2
end_session: cleanup attrs
teocns Mar 13, 2025
a9a56a1
examples/opentelemetry/token_importance.py
teocns Mar 13, 2025
14ad0d8
utility record i/o: use agentops.semconv.SpanAttributes
teocns Mar 13, 2025
ea429fe
examples/opentelemetry/token_importance_2.py
teocns Mar 13, 2025
479f906
sdk/tracing mod
teocns Mar 13, 2025
ef52379
Improve token_importance example
teocns Mar 13, 2025
61babbb
Cleanup legacy
teocns Mar 13, 2025
81c22fd
cleanup providers/
teocns Mar 13, 2025
df021eb
cleanup tests/ from legacy
teocns Mar 13, 2025
6822086
cleanup partners/
teocns Mar 13, 2025
6d0175e
Move sdk examples to examples/sdk/
teocns Mar 13, 2025
2a41d1b
fix: tracing utility span_kind closure nonlocal reference
teocns Mar 13, 2025
a095fac
examples/sdk/basic: add a second nest level
teocns Mar 13, 2025
dcc79ff
cleanup tests/factory
teocns Mar 13, 2025
6ca3cf4
fix instrumentation_tester
teocns Mar 13, 2025
b5f473e
cleanup tests/integration/test_time_factory
teocns Mar 13, 2025
2c1a19a
tests/unit/sdk/test_decorators.py
teocns Mar 13, 2025
c5963aa
cleanup tests/unit/test_decorators.py (old)
teocns Mar 13, 2025
024d347
test_decorators: more precise testing
teocns Mar 13, 2025
d2de1b9
refactor decorators
teocns Mar 13, 2025
afc7a8d
semconv.span_kinds: +workflow
teocns Mar 13, 2025
2bf8cf3
suppress wrapper linter
teocns Mar 14, 2025
07d28ea
test_decorators: adapt to refactor
teocns Mar 14, 2025
7c57374
operation decorator
teocns Mar 14, 2025
75dfd68
utility-rebase
teocns Mar 14, 2025
363ae37
threadlocal context mgmt
teocns Mar 14, 2025
fe99181
test_decorators correction
teocns Mar 14, 2025
24f3b9b
test multiple levels of nesting
teocns Mar 14, 2025
8f17cb8
Revert "threadlocal context mgmt"
teocns Mar 14, 2025
fbfdb99
Implement create_as_current_span
teocns Mar 14, 2025
82943d8
DRAFT
teocns Mar 14, 2025
f8fbd56
Use proper classes wrapping
teocns Mar 14, 2025
f8e7db1
Merge branch 'dev-fix-nesting' into dev
teocns Mar 14, 2025
5072488
decorators factory - use lengthier attr names to avoid collisions
teocns Mar 14, 2025
f1d77f3
fix test_decorators
teocns Mar 14, 2025
91b006f
Add multiple tests_decorators (async, async gen, etc)
teocns Mar 14, 2025
039f797
get rid of "commands"
teocns Mar 14, 2025
2058675
Session(span,token)
teocns Mar 14, 2025
9b70fc5
__init__ exports
teocns Mar 14, 2025
50af51f
backward compat +legacy
teocns Mar 14, 2025
ea0d7bf
deprecate pre-legacy core manual tests
teocns Mar 14, 2025
d2b3ea6
legacy: agentops.start_session(+tags)
teocns Mar 14, 2025
65f46c6
Auto end Session.span on __del__
teocns Mar 14, 2025
69ebf9f
Session + backwards compat methods (create_agent, record, end_session)
teocns Mar 14, 2025
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
121 changes: 15 additions & 106 deletions agentops/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Dict, List, Optional, Union, Any
from typing import Any, Dict, List, Optional, Union

from agentops.legacy import ErrorEvent, ToolEvent, end_session, start_session

from .client import Client
from .sdk.commands import record as sdk_record, start_span as sdk_start_span, end_span as sdk_end_span
from .semconv.span_kinds import SpanKind
import agentops.legacy as legacy
from agentops.legacy import ErrorEvent, ToolEvent

# Client global instance; one per process runtime
_client = Client()
Expand Down Expand Up @@ -126,110 +124,21 @@ def configure(**kwargs):

_client.configure(**kwargs)

# For backwards compatibility and testing

def start_session(**kwargs):
"""Start a new session for recording events.

Args:
tags (List[str], optional): Tags that can be used for grouping or sorting later.
e.g. ["test_run"]

Returns:
Optional[Session]: Returns Session if successful, None otherwise.
"""
return _client.start_session(**kwargs)


def end_session(span, token):
"""
End a previously started AgentOps session.

This function ends the session span and detaches the context token,
completing the session lifecycle.

Args:
span: The span returned by start_session
token: The token returned by start_session
"""
legacy.end_session(span, token)


def start_span(
name: str = "manual_span",
span_kind: str = SpanKind.OPERATION,
attributes: Optional[Dict[str, Any]] = None,
version: Optional[int] = None,
):
"""
Start a new span manually.

This function creates and starts a new span, which can be used to track
operations. The span will remain active until end_span is called with
the returned span and token.

Args:
name: Name of the span
span_kind: Kind of span (defaults to SpanKind.OPERATION)
attributes: Optional attributes to set on the span
version: Optional version identifier for the span

Returns:
A tuple of (span, token) that should be passed to end_span
"""
return sdk_start_span(name, span_kind, attributes, version)


def end_span(span, token):
"""
End a previously started span.

This function ends the span and detaches the context token,
completing the span lifecycle.

Args:
span: The span returned by start_span
token: The token returned by start_span
"""
sdk_end_span(span, token)


def record(message: str, attributes: Optional[Dict[str, Any]] = None):
"""
Record an event with a message within the current session.

This function creates a simple operation span with the provided message
and attributes, which will be automatically associated with the current session.

Args:
message: The message to record
attributes: Optional attributes to set on the span
"""
sdk_record(message, attributes)


def add_tags(tags: List[str]):
"""
Append to session tags at runtime.

TODO: How do we retrieve the session context to add tags to?

Args:
tags (List[str]): The list of tags to append.
"""
raise NotImplementedError

def get_client() -> Client:
"""Get the singleton client instance"""
return _client

def set_tags(tags: List[str]):
"""
Replace session tags at runtime.

Args:
tags (List[str]): The list of tags to set.
"""
raise NotImplementedError

from agentops.legacy import * # type: ignore

# For backwards compatibility and testing
def get_client() -> Client:
"""Get the singleton client instance"""
return _client
__all__ = [
"init",
"configure",
"get_client",
"start_session",
"end_session",
]
35 changes: 0 additions & 35 deletions agentops/cli.py

This file was deleted.

Loading
Loading