MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / start_session

Function start_session

agentops/legacy/__init__.py:65–112  ·  view source on GitHub ↗

@deprecated Use agentops.start_trace() instead. Starts a legacy AgentOps session. Calls tracer.start_trace internally.

(
    tags: Union[Dict[str, Any], List[str], None] = None,
)

Source from the content-addressed store, hash-verified

63
64@deprecated("Use agentops.start_trace() instead.")
65def start_session(
66 tags: Union[Dict[str, Any], List[str], None] = None,
67) -> Session:
68 """
69 @deprecated Use agentops.start_trace() instead.
70 Starts a legacy AgentOps session. Calls tracer.start_trace internally.
71 """
72 global _current_session, _current_trace_context
73
74 if not tracer.initialized:
75 from agentops import Client
76
77 try:
78 Client().init(auto_start_session=False)
79 if not tracer.initialized:
80 logger.warning("AgentOps client init failed during legacy start_session. Creating dummy session.")
81 dummy_session = Session(None)
82 _current_session = dummy_session
83 _current_trace_context = None
84 return dummy_session
85 except Exception as e:
86 logger.warning(f"AgentOps client init failed: {str(e)}. Creating dummy session.")
87 dummy_session = Session(None)
88 _current_session = dummy_session
89 _current_trace_context = None
90 return dummy_session
91
92 trace_context = tracer.start_trace(trace_name="session", tags=tags)
93 if trace_context is None:
94 logger.error("Failed to start trace via global tracer. Returning dummy session.")
95 dummy_session = Session(None)
96 _current_session = dummy_session
97 _current_trace_context = None
98 return dummy_session
99
100 session_obj = Session(trace_context)
101 _current_session = session_obj
102 _current_trace_context = trace_context
103
104 try:
105 import agentops.client.client
106
107 agentops.client.client._active_session = session_obj # type: ignore
108 if hasattr(agentops.client.client, "_active_trace_context"):
109 agentops.client.client._active_trace_context = trace_context # type: ignore
110 except (ImportError, AttributeError):
111 pass
112 return session_obj
113
114
115def _set_span_attributes(span: Any, attributes: Dict[str, Any]) -> None:

Callers

nothing calls this directly

Calls 4

ClientClass · 0.90
initMethod · 0.80
start_traceMethod · 0.80
SessionClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…