kodeagent.tracer#
Interfaces for hierarchical tracing and agent observability.
Supports multiple observability backends (e.g., Langfuse and LangSmith) with a unified API for creating traces, spans, and generations. Provides no-op implementations when tracing is disabled.
Factory function to create a tracer manager based on the specified type. |
|
Abstract interface for trace observations. |
|
Abstract interface for tracer management. |
|
LangSmith implementation of observation. |
|
LangSmith implementation of TracerManager. |
|
Langfuse implementation of observation. |
|
Langfuse implementation of TracerManager. |
|
No-op observation implementation. |
|
No-op tracer manager implementation. |
Interfaces for hierarchical tracing and agent observability.
Supports multiple observability backends (e.g., Langfuse and LangSmith) with a unified API for creating traces, spans, and generations. Provides no-op implementations when tracing is disabled.
- class kodeagent.tracer.AbstractObservation[source]#
Bases:
ABCAbstract interface for trace observations.
Represents a single node in a hierarchical trace tree. Can be a top-level trace, a nested span, or an LLM generation. Implements context manager protocol for use with ‘with’ statements.
- class kodeagent.tracer.AbstractTracerManager[source]#
Bases:
ABCAbstract interface for tracer management.
Factory for creating hierarchical observations. Handles initialization and backend-specific configuration. Implementations should support at least one tracing backend (Langfuse, LangSmith, etc.) or be a no-op when tracing is disabled.
- abstract flush() None[source]#
Flush any buffered traces to the backend.
Ensures that all recorded traces and spans are sent to the observability platform before the application exits.
- abstract start_generation(parent: AbstractObservation, name: str, input_data: Any) AbstractObservation[source]#
Start a nested LLM generation under a parent observation.
Used specifically for LLM calls within a trace or span.
- Parameters:
parent – Parent observation (trace or span).
name – Identifier for the generation operation.
input_data – Input data (e.g., prompt) to log for the generation.
- Returns:
An observation object for the generation.
- abstract start_span(parent: AbstractObservation, name: str, input_data: Any) AbstractObservation[source]#
Start a nested span under a parent observation.
Used for logical sub-operations within a trace or parent span.
- Parameters:
parent – Parent observation (trace or span).
name – Identifier for the span operation.
input_data – Input data to log for the span.
- Returns:
An observation object for the span.
- abstract start_trace(name: str, input_data: Any) AbstractObservation[source]#
Start a new top-level trace.
- Parameters:
name – Identifier for the trace operation.
input_data – Input data to log for the trace.
- Returns:
An observation object for the trace root.
- class kodeagent.tracer.LangSmithObservation(run_tree: Any)[source]#
Bases:
AbstractObservationLangSmith implementation of observation.
Wraps a LangSmith RunTree object to manage hierarchical runs.
Initialize LangSmith observation.
- Parameters:
run_tree – The LangSmith RunTree object.
- class kodeagent.tracer.LangSmithTracerManager[source]#
Bases:
AbstractTracerManagerLangSmith implementation of TracerManager.
Uses LangSmith RunTree to manage hierarchical runs.
Initialize the LangSmith client.
- start_generation(parent: AbstractObservation, name: str, input_data: Any) AbstractObservation[source]#
Start a nested LLM generation.
- Parameters:
parent – Parent observation (assumes LangSmithObservation).
name – Identifier for the generation operation.
input_data – Input data (e.g., prompt) to log for the generation.
- Returns:
A LangSmith generation object wrapped as AbstractObservation.
- start_span(parent: AbstractObservation, name: str, input_data: Any) AbstractObservation[source]#
Start a nested span under a parent observation.
- Parameters:
parent – Parent observation (assumes LangSmithObservation).
name – Identifier for the span operation.
input_data – Input data to log for the span.
- Returns:
A LangSmith span object wrapped as AbstractObservation.
- start_trace(name: str, input_data: Any) AbstractObservation[source]#
Start a new trace with LangSmith.
- class kodeagent.tracer.LangfuseObservation(obj: Any)[source]#
Bases:
AbstractObservationLangfuse implementation of observation.
Wraps Langfuse Trace, Span, or Generation objects to provide a consistent interface.
Initialize Langfuse observation.
- Parameters:
obj – The Langfuse Trace, Span, or Generation object.
- class kodeagent.tracer.LangfuseTracerManager[source]#
Bases:
AbstractTracerManagerLangfuse implementation of TracerManager.
Integrates with Langfuse observability platform to create and manage hierarchical traces, spans, and generations. Tracing is disabled if the Langfuse package is not installed.
Initialize the Langfuse client.
- start_generation(parent: AbstractObservation, name: str, input_data: Any) AbstractObservation[source]#
Start a nested LLM generation under a parent observation with Langfuse.
- Parameters:
parent – Parent observation (assumes LangfuseObservation).
name – Identifier for the generation operation.
input_data – Input data (e.g., prompt) to log for the generation.
- Returns:
A Langfuse generation object wrapped as AbstractObservation.
- start_span(parent: AbstractObservation, name: str, input_data: Any) AbstractObservation[source]#
Start a nested span under a parent observation with Langfuse.
- Parameters:
parent – Parent observation (assumes LangfuseObservation).
name – Identifier for the span operation.
input_data – Input data to log for the span.
- Returns:
A Langfuse span object wrapped as AbstractObservation.
- start_trace(name: str, input_data: Any) AbstractObservation[source]#
Start a new trace with Langfuse.
- Parameters:
name – Identifier for the trace operation.
input_data – Input data to log for the trace.
- Returns:
A Langfuse trace object wrapped as AbstractObservation.
- class kodeagent.tracer.NoOpObservation[source]#
Bases:
AbstractObservationNo-op observation implementation.
Used when tracing is disabled. All methods are no-ops and return self to support hierarchical nesting without side effects.
- class kodeagent.tracer.NoOpTracerManager[source]#
Bases:
AbstractTracerManagerNo-op tracer manager implementation.
Used when no observability backend is enabled. Provides a complete no-op implementation of the TracerManager interface that satisfies the contract while performing no actual tracing operations.
- start_generation(parent: AbstractObservation, name: str, input_data: Any) AbstractObservation[source]#
No-op: return a no-op observation.
- start_span(parent: AbstractObservation, name: str, input_data: Any) AbstractObservation[source]#
No-op: return a no-op observation.
- start_trace(name: str, input_data: Any) AbstractObservation[source]#
No-op: return a no-op observation.
- kodeagent.tracer.create_tracer_manager(tracing_type: Literal['langfuse', 'langsmith'] | None = None) AbstractTracerManager[source]#
Factory function to create a tracer manager based on the specified type.
- Parameters:
tracing_type – The type of tracing backend to use. Defaults to None for no-op tracing.
- Returns:
An instance of LangfuseTracerManager, LangSmithTracerManager, or NoOpTracerManager for the specified tracing backend.