Documentation
¶
Overview ¶
Package tracingapi provides types for OpenTelemetry tracing support, notably to reduce chance of cyclic imports. No implementations besides no-op are here.
Index ¶
- type ChatCompletionRecorder
- type ChatCompletionSpan
- type ChatCompletionTracer
- type CompletionRecorder
- type CompletionSpan
- type CompletionTracer
- type EmbeddingsRecorder
- type EmbeddingsSpan
- type EmbeddingsTracer
- type ImageGenerationRecorder
- type ImageGenerationSpan
- type ImageGenerationTracer
- type MCPSpan
- type MCPTracer
- type MessageRecorder
- type MessageSpan
- type MessageTracer
- type NoopChatCompletionTracer
- type NoopChunkRecorder
- type NoopCompletionTracer
- type NoopEmbeddingsTracer
- type NoopImageGenerationTracer
- type NoopMCPTracer
- type NoopMessageTracer
- type NoopRerankTracer
- type NoopResponsesTracer
- type NoopTracer
- type NoopTracing
- func (NoopTracing) ChatCompletionTracer() ChatCompletionTracer
- func (NoopTracing) CompletionTracer() CompletionTracer
- func (NoopTracing) EmbeddingsTracer() EmbeddingsTracer
- func (NoopTracing) ImageGenerationTracer() ImageGenerationTracer
- func (t NoopTracing) MCPTracer() MCPTracer
- func (NoopTracing) MessageTracer() MessageTracer
- func (NoopTracing) RerankTracer() RerankTracer
- func (NoopTracing) ResponsesTracer() ResponsesTracer
- func (NoopTracing) Shutdown(context.Context) error
- type RequestTracer
- type RerankRecorder
- type RerankSpan
- type RerankTracer
- type ResponsesRecorder
- type ResponsesSpan
- type ResponsesTracer
- type Span
- type SpanRecorder
- type SpanResponseRecorder
- type Tracing
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatCompletionRecorder ¶
type ChatCompletionRecorder = SpanRecorder[openai.ChatCompletionRequest, openai.ChatCompletionResponse, openai.ChatCompletionResponseChunk]
ChatCompletionRecorder records attributes to a span according to a semantic convention.
type ChatCompletionSpan ¶
type ChatCompletionSpan = Span[openai.ChatCompletionResponse, openai.ChatCompletionResponseChunk]
ChatCompletionSpan represents an OpenAI chat completion.
type ChatCompletionTracer ¶
type ChatCompletionTracer = RequestTracer[openai.ChatCompletionRequest, openai.ChatCompletionResponse, openai.ChatCompletionResponseChunk]
ChatCompletionTracer creates spans for OpenAI chat completion requests.
type CompletionRecorder ¶
type CompletionRecorder = SpanRecorder[openai.CompletionRequest, openai.CompletionResponse, openai.CompletionResponse]
CompletionRecorder records attributes to a span according to a semantic convention. Note: Completion streaming chunks are full CompletionResponse objects, not deltas like chat completions.
type CompletionSpan ¶
type CompletionSpan = Span[openai.CompletionResponse, openai.CompletionResponse]
CompletionSpan represents an OpenAI completion request. Note: Completion streaming chunks are full CompletionResponse objects, not deltas like chat completions.
type CompletionTracer ¶
type CompletionTracer = RequestTracer[openai.CompletionRequest, openai.CompletionResponse, openai.CompletionResponse]
CompletionTracer creates spans for OpenAI completion requests.
type EmbeddingsRecorder ¶
type EmbeddingsRecorder = SpanRecorder[openai.EmbeddingRequest, openai.EmbeddingResponse, struct{}]
EmbeddingsRecorder records attributes to a span according to a semantic convention.
type EmbeddingsSpan ¶
type EmbeddingsSpan = Span[openai.EmbeddingResponse, struct{}]
EmbeddingsSpan represents an OpenAI embeddings request. The chunk type is unused and therefore set to struct{}.
type EmbeddingsTracer ¶
type EmbeddingsTracer = RequestTracer[openai.EmbeddingRequest, openai.EmbeddingResponse, struct{}]
EmbeddingsTracer creates spans for OpenAI embeddings requests.
type ImageGenerationRecorder ¶
type ImageGenerationRecorder = SpanRecorder[openai.ImageGenerationRequest, openai.ImageGenerationResponse, struct{}]
ImageGenerationRecorder records attributes to a span according to a semantic convention.
type ImageGenerationSpan ¶
type ImageGenerationSpan = Span[openai.ImageGenerationResponse, struct{}]
ImageGenerationSpan represents an OpenAI image generation.
type ImageGenerationTracer ¶
type ImageGenerationTracer = RequestTracer[openai.ImageGenerationRequest, openai.ImageGenerationResponse, struct{}]
ImageGenerationTracer creates spans for OpenAI image generation requests.
type MCPSpan ¶
type MCPSpan interface {
// RecordRouteToBackend records the backend that was routed to.
RecordRouteToBackend(backend string, session string, isNew bool)
// EndSpan finalizes and ends the span.
EndSpan()
// EndSpanOnError finalizes and ends the span with an error status.
EndSpanOnError(errType string, err error)
}
MCPSpan represents an MCP span.
type MCPTracer ¶
type MCPTracer interface {
// StartSpanAndInjectMeta starts a span and injects trace context into
// the _meta mutation.
//
// Parameters:
// - ctx: might include a parent span context.
// - req: Incoming MCP request message.
// - param: Incoming MCP parameter used to extract parent trace context.
// - headers: Request HTTP request headers.
//
// Returns nil unless the span is sampled.
StartSpanAndInjectMeta(ctx context.Context, req *jsonrpc.Request, param mcp.Params, headers http.Header) MCPSpan
}
MCPTracer creates spans for MCP requests.
type MessageRecorder ¶
type MessageRecorder = SpanRecorder[anthropicschema.MessagesRequest, anthropicschema.MessagesResponse, anthropicschema.MessagesStreamChunk]
MessageRecorder records attributes to a span according to a semantic convention.
type MessageSpan ¶
type MessageSpan = Span[anthropicschema.MessagesResponse, anthropicschema.MessagesStreamChunk]
MessageSpan represents an Anthropic messages request span.
type MessageTracer ¶
type MessageTracer = RequestTracer[anthropicschema.MessagesRequest, anthropicschema.MessagesResponse, anthropicschema.MessagesStreamChunk]
MessageTracer creates spans for Anthropic messages requests.
type NoopChatCompletionTracer ¶
type NoopChatCompletionTracer = NoopTracer[openai.ChatCompletionRequest, openai.ChatCompletionResponse, openai.ChatCompletionResponseChunk]
NoopChatCompletionTracer implements ChatCompletionTracer.
type NoopChunkRecorder ¶
type NoopChunkRecorder[ChunkT any] struct{}
NoopChunkRecorder provides a no-op RecordResponseChunks implementation for recorders that don't emit streaming chunks.
func (NoopChunkRecorder[ChunkT]) RecordResponseChunks ¶
func (NoopChunkRecorder[ChunkT]) RecordResponseChunks(trace.Span, []*ChunkT)
RecordResponseChunks implements SpanRecorder.RecordResponseChunks as a no-op.
type NoopCompletionTracer ¶
type NoopCompletionTracer = NoopTracer[openai.CompletionRequest, openai.CompletionResponse, openai.CompletionResponse]
NoopCompletionTracer implements CompletionTracer.
type NoopEmbeddingsTracer ¶
type NoopEmbeddingsTracer = NoopTracer[openai.EmbeddingRequest, openai.EmbeddingResponse, struct{}]
NoopEmbeddingsTracer implements EmbeddingsTracer.
type NoopImageGenerationTracer ¶
type NoopImageGenerationTracer = NoopTracer[openai.ImageGenerationRequest, openai.ImageGenerationResponse, struct{}]
NoopImageGenerationTracer implements ImageGenerationTracer.
type NoopMCPTracer ¶
type NoopMCPTracer struct{}
NoopMCPTracer is a no-op implementation of MCPTracer.
type NoopMessageTracer ¶
type NoopMessageTracer = NoopTracer[anthropicschema.MessagesRequest, anthropicschema.MessagesResponse, anthropicschema.MessagesStreamChunk]
NoopMessageTracer implements MessageTracer.
type NoopRerankTracer ¶
type NoopRerankTracer = NoopTracer[cohere.RerankV2Request, cohere.RerankV2Response, struct{}]
NoopRerankTracer implements RerankTracer.
type NoopResponsesTracer ¶
type NoopResponsesTracer = NoopTracer[openai.ResponseRequest, openai.Response, openai.ResponseStreamEventUnion]
NoopResponsesTracer implements ResponsesTracer.
type NoopTracer ¶
NoopTracer implements RequestTracer without producing spans.
func (NoopTracer[ReqT, RespT, RespChunkT]) StartSpanAndInjectHeaders ¶
func (NoopTracer[ReqT, RespT, RespChunkT]) StartSpanAndInjectHeaders(context.Context, map[string]string, propagation.TextMapCarrier, *ReqT, []byte) Span[RespT, RespChunkT]
StartSpanAndInjectHeaders implements RequestTracer.StartSpanAndInjectHeaders.
type NoopTracing ¶
type NoopTracing struct{}
NoopTracing is a Tracing that doesn't do anything.
func (NoopTracing) ChatCompletionTracer ¶
func (NoopTracing) ChatCompletionTracer() ChatCompletionTracer
ChatCompletionTracer implements Tracing.ChatCompletionTracer.
func (NoopTracing) CompletionTracer ¶
func (NoopTracing) CompletionTracer() CompletionTracer
CompletionTracer implements Tracing.CompletionTracer.
func (NoopTracing) EmbeddingsTracer ¶
func (NoopTracing) EmbeddingsTracer() EmbeddingsTracer
EmbeddingsTracer implements Tracing.EmbeddingsTracer.
func (NoopTracing) ImageGenerationTracer ¶
func (NoopTracing) ImageGenerationTracer() ImageGenerationTracer
ImageGenerationTracer implements Tracing.ImageGenerationTracer.
func (NoopTracing) MCPTracer ¶
func (t NoopTracing) MCPTracer() MCPTracer
func (NoopTracing) MessageTracer ¶
func (NoopTracing) MessageTracer() MessageTracer
func (NoopTracing) RerankTracer ¶
func (NoopTracing) RerankTracer() RerankTracer
RerankTracer implements Tracing.RerankTracer.
func (NoopTracing) ResponsesTracer ¶
func (NoopTracing) ResponsesTracer() ResponsesTracer
ResponsesTracer implements Tracing.ResponsesTracer.
type RequestTracer ¶
type RequestTracer[ReqT any, RespT any, RespChunkT any] interface { // StartSpanAndInjectHeaders starts a span and injects trace context into the header mutation. // // Parameters: // - ctx: might include a parent span context. // - headers: Incoming HTTP headers used to extract parent trace context. // - headerMutation: The new span will have its context written to these headers unless NoopTracing is used. // - req: The typed request used to detect streaming and record request attributes. // - body: contains the original raw request body as a byte slice. // // Returns nil unless the span is sampled. StartSpanAndInjectHeaders(ctx context.Context, headers map[string]string, carrier propagation.TextMapCarrier, req *ReqT, body []byte) Span[RespT, RespChunkT] }
RequestTracer standardizes tracer implementations for non-MCP requests.
type RerankRecorder ¶
type RerankRecorder = SpanRecorder[cohere.RerankV2Request, cohere.RerankV2Response, struct{}]
RerankRecorder records attributes to a span according to a semantic convention.
type RerankSpan ¶
type RerankSpan = Span[cohere.RerankV2Response, struct{}]
RerankSpan represents a rerank request span.
type RerankTracer ¶
type RerankTracer = RequestTracer[cohere.RerankV2Request, cohere.RerankV2Response, struct{}]
RerankTracer creates spans for rerank requests.
type ResponsesRecorder ¶
type ResponsesRecorder = SpanRecorder[openai.ResponseRequest, openai.Response, openai.ResponseStreamEventUnion]
ResponsesRecorder records attributes to a span according to a semantic convention.
type ResponsesSpan ¶
type ResponsesSpan = Span[openai.Response, openai.ResponseStreamEventUnion]
ResponsesSpan represents an OpenAI responses request span.
type ResponsesTracer ¶
type ResponsesTracer = RequestTracer[openai.ResponseRequest, openai.Response, openai.ResponseStreamEventUnion]
ResponsesTracer creates spans for OpenAI responses requests.
type Span ¶
type Span[RespT any, RespChunkT any] interface { // RecordResponseChunk records streaming response chunks. Implementations that do not support streaming should provide a no-op implementation. RecordResponseChunk(resp *RespChunkT) // RecordResponse records the response attributes to the span. RecordResponse(resp *RespT) // EndSpanOnError finalizes and ends the span with an error status. EndSpanOnError(statusCode int, body []byte) // EndSpan finalizes and ends the span. EndSpan() }
Span standardizes span interfaces, supporting both streaming and non-streaming endpoints.
type SpanRecorder ¶
type SpanRecorder[ReqT any, RespT any, RespChunkT any] interface { SpanResponseRecorder[RespT, RespChunkT] // StartParams returns the name and options to start the span with. // // Parameters: // - req: contains the typed request. // - body: contains the complete request body. // // Note: Avoid expensive data conversions since the span might not be sampled. StartParams(req *ReqT, body []byte) (spanName string, opts []trace.SpanStartOption) // RecordRequest records request attributes to the span. RecordRequest(span trace.Span, req *ReqT, body []byte) }
SpanRecorder standardizes recorder implementations for non-MCP tracers.
type SpanResponseRecorder ¶
type SpanResponseRecorder[RespT, RespChunkT any] interface { // RecordResponse records response attributes to the span. RecordResponse(span trace.Span, resp *RespT) // RecordResponseOnError ends recording the span with an error status. RecordResponseOnError(span trace.Span, statusCode int, body []byte) // RecordResponseChunks records response chunk attributes to the span for streaming response. RecordResponseChunks(span trace.Span, chunks []*RespChunkT) }
SpanResponseRecorder standardizes response recording for non-MCP tracers.
It is separated from SpanRecorder to allow reusing response recording logic.
type Tracing ¶
type Tracing interface {
// ChatCompletionTracer creates spans for OpenAI chat completion requests on /chat/completions endpoint.
ChatCompletionTracer() ChatCompletionTracer
// ImageGenerationTracer creates spans for OpenAI image generation requests.
ImageGenerationTracer() ImageGenerationTracer
// CompletionTracer creates spans for OpenAI completion requests on /completions endpoint.
CompletionTracer() CompletionTracer
// EmbeddingsTracer creates spans for OpenAI embeddings requests on /embeddings endpoint.
EmbeddingsTracer() EmbeddingsTracer
// ResponsesTracer creates spans for OpenAI responses requests on /v1/responses endpoint.
ResponsesTracer() ResponsesTracer
// RerankTracer creates spans for rerank requests.
RerankTracer() RerankTracer
// MessageTracer creates spans for Anthropic messages requests.
MessageTracer() MessageTracer
// MCPTracer creates spans for MCP requests.
MCPTracer() MCPTracer
// Shutdown shuts down the tracer, flushing any buffered spans.
Shutdown(context.Context) error
}
Tracing gives access to tracer types needed for endpoints such as OpenAI chat completions, image generation, embeddings, and MCP requests.