tracingapi

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatCompletionRecorder

ChatCompletionRecorder records attributes to a span according to a semantic convention.

type ChatCompletionSpan

ChatCompletionSpan represents an OpenAI chat completion.

type ChatCompletionTracer

ChatCompletionTracer creates spans for OpenAI chat completion requests.

type CompletionRecorder

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

CompletionSpan represents an OpenAI completion request. Note: Completion streaming chunks are full CompletionResponse objects, not deltas like chat completions.

type CompletionTracer

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

MessageRecorder records attributes to a span according to a semantic convention.

type MessageSpan

MessageSpan represents an Anthropic messages request span.

type MessageTracer

MessageTracer creates spans for Anthropic messages requests.

type NoopChatCompletionTracer

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

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.

func (NoopMCPTracer) StartSpanAndInjectMeta

func (NoopMCPTracer) StartSpanAndInjectMeta(context.Context, *jsonrpc.Request, mcp.Params, http.Header) MCPSpan

StartSpanAndInjectMeta implements [MCPTracer.StartSpanAndInjectMeta].

type NoopMessageTracer

NoopMessageTracer implements MessageTracer.

type NoopRerankTracer

type NoopRerankTracer = NoopTracer[cohere.RerankV2Request, cohere.RerankV2Response, struct{}]

NoopRerankTracer implements RerankTracer.

type NoopResponsesTracer

NoopResponsesTracer implements ResponsesTracer.

type NoopTracer

type NoopTracer[ReqT any, RespT any, RespChunkT any] struct{}

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.

func (NoopTracing) Shutdown

func (NoopTracing) Shutdown(context.Context) error

Shutdown implements Tracing.Shutdown.

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

ResponsesRecorder records attributes to a span according to a semantic convention.

type ResponsesSpan

ResponsesSpan represents an OpenAI responses request span.

type ResponsesTracer

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL