Adding scope and span_data doc strings (#463)
Built docs and tested outputs locally
This commit is contained in:
parent
d089886f01
commit
84fb734ba0
2 changed files with 64 additions and 0 deletions
|
|
@ -18,6 +18,10 @@ _current_trace: contextvars.ContextVar["Trace | None"] = contextvars.ContextVar(
|
||||||
|
|
||||||
|
|
||||||
class Scope:
|
class Scope:
|
||||||
|
"""
|
||||||
|
Manages the current span and trace in the context.
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_current_span(cls) -> "Span[Any] | None":
|
def get_current_span(cls) -> "Span[Any] | None":
|
||||||
return _current_span.get()
|
return _current_span.get()
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,28 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
|
|
||||||
class SpanData(abc.ABC):
|
class SpanData(abc.ABC):
|
||||||
|
"""
|
||||||
|
Represents span data in the trace.
|
||||||
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def export(self) -> dict[str, Any]:
|
def export(self) -> dict[str, Any]:
|
||||||
|
"""Export the span data as a dictionary."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def type(self) -> str:
|
def type(self) -> str:
|
||||||
|
"""Return the type of the span."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AgentSpanData(SpanData):
|
class AgentSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents an Agent Span in the trace.
|
||||||
|
Includes name, handoffs, tools, and output type.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = ("name", "handoffs", "tools", "output_type")
|
__slots__ = ("name", "handoffs", "tools", "output_type")
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -49,6 +60,11 @@ class AgentSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class FunctionSpanData(SpanData):
|
class FunctionSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents a Function Span in the trace.
|
||||||
|
Includes input, output and MCP data (if applicable).
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = ("name", "input", "output", "mcp_data")
|
__slots__ = ("name", "input", "output", "mcp_data")
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -78,6 +94,11 @@ class FunctionSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class GenerationSpanData(SpanData):
|
class GenerationSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents a Generation Span in the trace.
|
||||||
|
Includes input, output, model, model configuration, and usage.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
"input",
|
"input",
|
||||||
"output",
|
"output",
|
||||||
|
|
@ -116,6 +137,11 @@ class GenerationSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class ResponseSpanData(SpanData):
|
class ResponseSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents a Response Span in the trace.
|
||||||
|
Includes response and input.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = ("response", "input")
|
__slots__ = ("response", "input")
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -140,6 +166,11 @@ class ResponseSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class HandoffSpanData(SpanData):
|
class HandoffSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents a Handoff Span in the trace.
|
||||||
|
Includes source and desitnation agents.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = ("from_agent", "to_agent")
|
__slots__ = ("from_agent", "to_agent")
|
||||||
|
|
||||||
def __init__(self, from_agent: str | None, to_agent: str | None):
|
def __init__(self, from_agent: str | None, to_agent: str | None):
|
||||||
|
|
@ -159,6 +190,11 @@ class HandoffSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class CustomSpanData(SpanData):
|
class CustomSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents a Custom Span in the trace.
|
||||||
|
Includes name and data property bag.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = ("name", "data")
|
__slots__ = ("name", "data")
|
||||||
|
|
||||||
def __init__(self, name: str, data: dict[str, Any]):
|
def __init__(self, name: str, data: dict[str, Any]):
|
||||||
|
|
@ -178,6 +214,11 @@ class CustomSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class GuardrailSpanData(SpanData):
|
class GuardrailSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents a Guardrail Span in the trace.
|
||||||
|
Includes name and triggered status.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = ("name", "triggered")
|
__slots__ = ("name", "triggered")
|
||||||
|
|
||||||
def __init__(self, name: str, triggered: bool = False):
|
def __init__(self, name: str, triggered: bool = False):
|
||||||
|
|
@ -197,6 +238,11 @@ class GuardrailSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class TranscriptionSpanData(SpanData):
|
class TranscriptionSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents a Transcription Span in the trace.
|
||||||
|
Includes input, output, model, and model configuration.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
"input",
|
"input",
|
||||||
"output",
|
"output",
|
||||||
|
|
@ -236,6 +282,11 @@ class TranscriptionSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class SpeechSpanData(SpanData):
|
class SpeechSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents a Speech Span in the trace.
|
||||||
|
Includes input, output, model, model configuration, and first content timestamp.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = ("input", "output", "model", "model_config", "first_content_at")
|
__slots__ = ("input", "output", "model", "model_config", "first_content_at")
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -273,6 +324,10 @@ class SpeechSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class SpeechGroupSpanData(SpanData):
|
class SpeechGroupSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents a Speech Group Span in the trace.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = "input"
|
__slots__ = "input"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -293,6 +348,11 @@ class SpeechGroupSpanData(SpanData):
|
||||||
|
|
||||||
|
|
||||||
class MCPListToolsSpanData(SpanData):
|
class MCPListToolsSpanData(SpanData):
|
||||||
|
"""
|
||||||
|
Represents an MCP List Tools Span in the trace.
|
||||||
|
Includes server and result.
|
||||||
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
"server",
|
"server",
|
||||||
"result",
|
"result",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue