@deprecated Use agentops.end_trace() instead. Ends a legacy AgentOps session. Calls tracer.end_trace internally. Supports multiple calling patterns for backward compatibility.
(session_or_status: Any = None, **kwargs: Any)
| 125 | |
| 126 | @deprecated("Use agentops.end_trace() instead.") |
| 127 | def end_session(session_or_status: Any = None, **kwargs: Any) -> None: |
| 128 | """ |
| 129 | @deprecated Use agentops.end_trace() instead. |
| 130 | Ends a legacy AgentOps session. Calls tracer.end_trace internally. |
| 131 | Supports multiple calling patterns for backward compatibility. |
| 132 | """ |
| 133 | global _current_session, _current_trace_context |
| 134 | |
| 135 | if not tracer.initialized: |
| 136 | logger.debug("Ignoring end_session: global tracer not initialized.") |
| 137 | return |
| 138 | |
| 139 | target_trace_context: Optional[TraceContext] = None |
| 140 | end_state_from_args = "Success" |
| 141 | extra_attributes = kwargs.copy() |
| 142 | |
| 143 | if isinstance(session_or_status, Session): |
| 144 | target_trace_context = session_or_status.trace_context |
| 145 | if "end_state" in extra_attributes: |
| 146 | end_state_from_args = str(extra_attributes.pop("end_state")) |
| 147 | elif isinstance(session_or_status, str): |
| 148 | end_state_from_args = session_or_status |
| 149 | target_trace_context = _current_trace_context |
| 150 | if "end_state" in extra_attributes: |
| 151 | end_state_from_args = str(extra_attributes.pop("end_state")) |
| 152 | elif session_or_status is None and kwargs: |
| 153 | target_trace_context = _current_trace_context |
| 154 | if "end_state" in extra_attributes: |
| 155 | end_state_from_args = str(extra_attributes.pop("end_state")) |
| 156 | else: |
| 157 | target_trace_context = _current_trace_context |
| 158 | if "end_state" in extra_attributes: |
| 159 | end_state_from_args = str(extra_attributes.pop("end_state")) |
| 160 | |
| 161 | if not target_trace_context: |
| 162 | logger.warning("end_session called but no active trace context found.") |
| 163 | return |
| 164 | |
| 165 | if target_trace_context.span and extra_attributes: |
| 166 | _set_span_attributes(target_trace_context.span, extra_attributes) |
| 167 | |
| 168 | tracer.end_trace(target_trace_context, end_state=end_state_from_args) |
| 169 | |
| 170 | if target_trace_context is _current_trace_context: |
| 171 | _current_session = None |
| 172 | _current_trace_context = None |
| 173 | |
| 174 | try: |
| 175 | import agentops.client.client |
| 176 | |
| 177 | if ( |
| 178 | hasattr(agentops.client.client, "_active_trace_context") |
| 179 | and agentops.client.client._active_trace_context is target_trace_context |
| 180 | ): # type: ignore |
| 181 | agentops.client.client._active_trace_context = None # type: ignore |
| 182 | agentops.client.client._active_session = None # type: ignore |
| 183 | elif ( |
| 184 | hasattr(agentops.client.client, "_init_trace_context") |
no test coverage detected
searching dependent graphs…