1212from typing import Optional , Any , Dict , List , Union
1313
1414from agentops .logging import logger
15- from agentops .sdk .core import TracingCore , TraceContext
15+ from agentops .sdk .core import TraceContext , tracer
1616
1717_current_session : Optional ["Session" ] = None
1818_current_trace_context : Optional [TraceContext ] = None
@@ -68,14 +68,13 @@ def start_session(
6868 Starts a legacy AgentOps session. Calls TracingCore.start_trace internally.
6969 """
7070 global _current_session , _current_trace_context
71- tracing_core = TracingCore .get_instance ()
7271
73- if not tracing_core .initialized :
72+ if not tracer .initialized :
7473 from agentops import Client
7574
7675 try :
7776 Client ().init (auto_start_session = False )
78- if not tracing_core .initialized :
77+ if not tracer .initialized :
7978 logger .warning ("AgentOps client init failed during legacy start_session. Creating dummy session." )
8079 dummy_session = Session (None )
8180 _current_session = dummy_session
@@ -88,7 +87,7 @@ def start_session(
8887 _current_trace_context = None
8988 return dummy_session
9089
91- trace_context = tracing_core .start_trace (trace_name = "session" , tags = tags )
90+ trace_context = tracer .start_trace (trace_name = "session" , tags = tags )
9291 if trace_context is None :
9392 logger .error ("Failed to start trace via TracingCore. Returning dummy session." )
9493 dummy_session = Session (None )
@@ -129,9 +128,8 @@ def end_session(session_or_status: Any = None, **kwargs: Any) -> None:
129128 Supports multiple calling patterns for backward compatibility.
130129 """
131130 global _current_session , _current_trace_context
132- tracing_core = TracingCore .get_instance ()
133131
134- if not tracing_core .initialized :
132+ if not tracer .initialized :
135133 logger .debug ("Ignoring end_session: TracingCore not initialized." )
136134 return
137135
@@ -164,7 +162,7 @@ def end_session(session_or_status: Any = None, **kwargs: Any) -> None:
164162 if target_trace_context .span and extra_attributes :
165163 _set_span_attributes (target_trace_context .span , extra_attributes )
166164
167- tracing_core .end_trace (target_trace_context , end_state = end_state_from_args )
165+ tracer .end_trace (target_trace_context , end_state = end_state_from_args )
168166
169167 if target_trace_context is _current_trace_context :
170168 _current_session = None
@@ -190,15 +188,12 @@ def end_session(session_or_status: Any = None, **kwargs: Any) -> None:
190188
191189def end_all_sessions () -> None :
192190 """@deprecated Ends all active sessions/traces."""
193- from agentops .sdk .core import TracingCore
194-
195- tracing_core = TracingCore .get_instance ()
196- if not tracing_core .initialized :
191+ if not tracer .initialized :
197192 logger .debug ("Ignoring end_all_sessions: TracingCore not initialized." )
198193 return
199194
200195 # Use the new end_trace functionality to end all active traces
201- tracing_core .end_trace (trace_context = None , end_state = "Success" )
196+ tracer .end_trace (trace_context = None , end_state = "Success" )
202197
203198 # Clear legacy global state
204199 global _current_session , _current_trace_context
0 commit comments