diff --git a/agentops/legacy/__init__.py b/agentops/legacy/__init__.py index ea097dec1..f405fa42a 100644 --- a/agentops/legacy/__init__.py +++ b/agentops/legacy/__init__.py @@ -15,7 +15,6 @@ from agentops.sdk.core import TracingCore from agentops.semconv.span_kinds import SpanKind from agentops.exceptions import AgentOpsClientNotInitializedException - _current_session: Optional["Session"] = None @@ -95,6 +94,23 @@ def _create_session_span(tags: Union[Dict[str, Any], List[str], None] = None) -> attributes["tags"] = tags return _make_span("session", span_kind=SpanKind.SESSION, attributes=attributes) +def _create_session_span(tags: Union[Dict[str, Any], List[str], None] = None) -> tuple: + """ + Helper function to create a session span with tags. + + Args: + tags: Optional tags to attach to the span + + Returns: + A tuple of (span, context, token) + """ + from agentops.sdk.decorators.utility import _make_span + + attributes = {} + if tags: + attributes["tags"] = tags + return _make_span("session", span_kind=SpanKind.SESSION, attributes=attributes) + def start_session( tags: Union[Dict[str, Any], List[str], None] = None, @@ -152,7 +168,6 @@ def _set_span_attributes(span: Any, attributes: Dict[str, Any]) -> None: for key, value in attributes.items(): span.set_attribute(f"agentops.status.{key}", str(value)) - def _flush_span_processors() -> None: """ Helper to force flush all span processors. diff --git a/tests/unit/test_session_legacy.py b/tests/unit/test_session_legacy.py index e63557787..baacdb8aa 100644 --- a/tests/unit/test_session_legacy.py +++ b/tests/unit/test_session_legacy.py @@ -6,7 +6,6 @@ def test_session_auto_start(instrumentation): # Pass a dummy API key for the test session = agentops.init(api_key="test-api-key", auto_start_session=True) - assert isinstance(session, Session) @@ -157,4 +156,4 @@ def test_crewai_kwargs_force_flush(): ) # Explicitly ensure the core isn't already shut down for the test - assert TracingCore.get_instance()._initialized, "TracingCore should still be initialized" \ No newline at end of file + assert TracingCore.get_instance()._initialized, "TracingCore should still be initialized" diff --git a/uv.lock b/uv.lock index 92a77505b..2fbe38acb 100644 --- a/uv.lock +++ b/uv.lock @@ -1,4 +1,5 @@ version = 1 +revision = 1 requires-python = ">=3.9, <3.14" resolution-markers = [ "python_full_version >= '3.13' and platform_python_implementation == 'PyPy'",