Skip to content

Commit 9511139

Browse files
committed
Clean up docstrings in legacy
1 parent f6fa7d4 commit 9511139

2 files changed

Lines changed: 22 additions & 23 deletions

File tree

agentops/legacy/__init__.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
class Session:
2323
"""
24-
A session object that holds a span and token for OpenTelemetry tracing.
25-
2624
This class provides compatibility with CrewAI >= 0.105.0, which uses an event-based
2725
integration pattern where it calls methods directly on the Session object:
2826
@@ -67,7 +65,6 @@ def end_session(self, **kwargs):
6765
- end_state="Success"
6866
- end_state_reason="Finished Execution"
6967
70-
This implementation properly ends the OpenTelemetry span and
7168
forces a flush to ensure the span is exported immediately.
7269
"""
7370
_set_span_attributes(self.span, kwargs)
@@ -80,7 +77,6 @@ def _create_session_span(tags: Union[Dict[str, Any], List[str], None] = None) ->
8077
Helper function to create a session span with tags.
8178
8279
This is an internal function used by start_session() to create the
83-
OpenTelemetry span for the session. It uses the _make_span utility
8480
from the SDK to create a span with kind=SpanKind.SESSION.
8581
8682
Args:
@@ -89,7 +85,6 @@ def _create_session_span(tags: Union[Dict[str, Any], List[str], None] = None) ->
8985
9086
Returns:
9187
A tuple of (span, context, token) where:
92-
- span is the OpenTelemetry span object
9388
- context is the span context
9489
- token is the context token needed for detaching
9590
"""
@@ -105,6 +100,7 @@ def start_session(
105100
tags: Union[Dict[str, Any], List[str], None] = None,
106101
) -> Session:
107102
"""
103+
@deprecated
108104
Start a new AgentOps session manually.
109105
110106
This function creates and starts a new session span, which can be used to group
@@ -160,12 +156,8 @@ def _set_span_attributes(span: Any, attributes: Dict[str, Any]) -> None:
160156
def _flush_span_processors() -> None:
161157
"""
162158
Helper to force flush all span processors.
163-
164-
Returns:
165-
True if flush was successful, False otherwise
166159
"""
167160
try:
168-
# Use OpenTelemetry API directly to force flush
169161
from opentelemetry.trace import get_tracer_provider
170162
tracer_provider = get_tracer_provider()
171163
tracer_provider.force_flush()
@@ -175,6 +167,7 @@ def _flush_span_processors() -> None:
175167

176168
def end_session(session_or_status: Any = None, **kwargs) -> None:
177169
"""
170+
@deprecated
178171
End a previously started AgentOps session.
179172
180173
This function ends the session span and detaches the context token,
@@ -219,15 +212,11 @@ def end_session(session_or_status: Any = None, **kwargs) -> None:
219212
if session_or_status is None and kwargs:
220213
global _current_session
221214

222-
# Use the globally stored session if available
223215
if _current_session is not None:
224216
_set_span_attributes(_current_session.span, kwargs)
225217
_finalize_span(_current_session.span, _current_session.token)
226218
_flush_span_processors()
227219
_current_session = None
228-
else:
229-
logger.warning("CrewAI called end_session with kwargs, but no global session was found")
230-
231220
return
232221

233222
# Handle the standard pattern and CrewAI >= 0.105.0 pattern where a Session object is passed.
@@ -240,7 +229,12 @@ def end_session(session_or_status: Any = None, **kwargs) -> None:
240229

241230

242231
def end_all_sessions():
243-
pass
232+
"""
233+
@deprecated
234+
We don't automatically track more than one session, so just end the session
235+
that we are tracking.
236+
"""
237+
end_session()
244238

245239

246240
def ToolEvent(*args, **kwargs) -> None:
@@ -306,8 +300,13 @@ def noop(f):
306300

307301

308302
def track_tool(*args, **kwargs):
309-
"""@deprecated"""
310-
pass
303+
"""
304+
@deprecated
305+
Decorator for marking tools and legacy projects.
306+
"""
307+
def noop(f):
308+
return f
309+
return noop
311310

312311

313312
__all__ = [

tests/unit/test_session_legacy.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def __init__(self):
7272

7373
def test_crewai_kwargs_pattern(instrumentation):
7474
"""
75-
Test the CrewAI 0.9x-0.10x pattern where end_session is called with only kwargs.
75+
Test the CrewAI < 0.105.0 pattern where end_session is called with only kwargs.
7676
77-
In versions 0.9x-0.10x, CrewAI directly calls:
77+
In versions < 0.105.0, CrewAI directly calls:
7878
agentops.end_session(
7979
end_state="Success",
8080
end_state_reason="Finished Execution",
@@ -91,7 +91,7 @@ def test_crewai_kwargs_pattern(instrumentation):
9191
session = agentops.start_session(tags=["test", "crewai-kwargs"])
9292
assert isinstance(session, Session)
9393

94-
# Test the CrewAI 0.9x-0.10x pattern - calling end_session with only kwargs
94+
# Test the CrewAI < 0.105.0 pattern - calling end_session with only kwargs
9595
agentops.end_session(
9696
end_state="Success",
9797
end_state_reason="Finished Execution",
@@ -106,7 +106,7 @@ def test_crewai_kwargs_pattern(instrumentation):
106106

107107
def test_crewai_kwargs_pattern_no_session(instrumentation):
108108
"""
109-
Test the CrewAI 0.9x-0.10x pattern where end_session is called with only kwargs,
109+
Test the CrewAI < 0.105.0 pattern where end_session is called with only kwargs,
110110
but no session has been created.
111111
112112
This should log a warning but not fail.
@@ -119,7 +119,7 @@ def test_crewai_kwargs_pattern_no_session(instrumentation):
119119
# We don't need to explicitly clear the session state
120120
# Just make sure we start with a clean state by calling init
121121

122-
# Test the CrewAI 0.9x-0.10x pattern - calling end_session with only kwargs
122+
# Test the CrewAI < 0.105.0 pattern - calling end_session with only kwargs
123123
# when no session exists. This should not raise an error.
124124
agentops.end_session(
125125
end_state="Success",
@@ -130,7 +130,7 @@ def test_crewai_kwargs_pattern_no_session(instrumentation):
130130

131131
def test_crewai_kwargs_force_flush():
132132
"""
133-
Test that when using the CrewAI 0.9x-0.10x pattern (end_session with kwargs),
133+
Test that when using the CrewAI < 0.105.0 pattern (end_session with kwargs),
134134
the spans are properly exported to the backend with force_flush.
135135
136136
This is a more comprehensive test that ensures spans are actually sent
@@ -149,7 +149,7 @@ def test_crewai_kwargs_force_flush():
149149
# Simulate some work
150150
time.sleep(0.1)
151151

152-
# End session with kwargs (CrewAI 0.9x-0.10x pattern)
152+
# End session with kwargs (CrewAI < 0.105.0 pattern)
153153
agentops.end_session(
154154
end_state="Success",
155155
end_state_reason="Test Finished",

0 commit comments

Comments
 (0)