Documentation
¶
Overview ¶
Package internal provides shared middleware functionality for OpenTelemetry tracers.
Package internal provides shared utilities for OpenTelemetry middleware tracers.
Index ¶
- func Middleware(getMiddlewareTracer TracerRouter, log logger.Logger) func(*http.Request, NextMiddleware) (*http.Response, error)
- func NormalizeClaudeToolChoice(value any) any
- func NormalizeClaudeTools(value any) []any
- func SetJSONAttr(span trace.Span, key string, value any) error
- func ToInt64(v any) (bool, int64)
- type BufferedReader
- type ClaudeStreamAccumulator
- func (a *ClaudeStreamAccumulator) Add(event map[string]any) bool
- func (a *ClaudeStreamAccumulator) ContextManagement() map[string]any
- func (a *ClaudeStreamAccumulator) Model() string
- func (a *ClaudeStreamAccumulator) Output() []map[string]any
- func (a *ClaudeStreamAccumulator) StopReason() any
- func (a *ClaudeStreamAccumulator) Usage() map[string]any
- type MiddlewareTracer
- type NextMiddleware
- type TracerRouter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(getMiddlewareTracer TracerRouter, log logger.Logger) func(*http.Request, NextMiddleware) (*http.Response, error)
Middleware creates a shared OpenTelemetry middleware that uses the provided router to determine which tracer to use for each endpoint. An optional logger can be provided for debug and error logging. If nil, logging is disabled.
func NormalizeClaudeToolChoice ¶ added in v0.15.0
NormalizeClaudeToolChoice maps Claude's tool_choice onto the OpenAI vocabulary, returning nil for unrecognized values.
func NormalizeClaudeTools ¶ added in v0.15.0
NormalizeClaudeTools converts user-defined tools into the OpenAI Chat Completions shape for metadata.tools. Built-in server-side tools (web_search, computer, bash, ...) pass through untouched: they aren't function-like, so a fabricated function name or schema would misrepresent them.
func SetJSONAttr ¶
SetJSONAttr is a helper function to set JSON attributes on spans
Types ¶
type BufferedReader ¶
type BufferedReader struct {
// contains filtered or unexported fields
}
BufferedReader saves data read from the readCloser and triggers an action when fully read or closed.
func NewBufferedReader ¶
func NewBufferedReader(src io.ReadCloser, onDone func(io.Reader)) *BufferedReader
NewBufferedReader creates a new buffered reader that calls onDone when fully read or closed.
func (*BufferedReader) Close ¶
func (r *BufferedReader) Close() error
Close closes the underlying reader and triggers the onDone callback.
type ClaudeStreamAccumulator ¶ added in v0.11.0
type ClaudeStreamAccumulator struct {
// contains filtered or unexported fields
}
ClaudeStreamAccumulator incrementally reduces Claude Messages API stream events into one assistant message and merged usage data.
func NewClaudeStreamAccumulator ¶ added in v0.11.0
func NewClaudeStreamAccumulator() *ClaudeStreamAccumulator
NewClaudeStreamAccumulator creates an empty Claude stream accumulator.
func (*ClaudeStreamAccumulator) Add ¶ added in v0.11.0
func (a *ClaudeStreamAccumulator) Add(event map[string]any) bool
Add consumes one decoded Claude event. It reports whether the event contains generated text, reasoning, or tool-input content suitable for TTFT.
func (*ClaudeStreamAccumulator) ContextManagement ¶ added in v0.14.0
func (a *ClaudeStreamAccumulator) ContextManagement() map[string]any
ContextManagement returns the context_management field from the stream's message events, if present. This reports which context-editing strategies actually fired during the request (e.g. applied_edits), distinct from the request-side context_management config captured before the stream starts.
func (*ClaudeStreamAccumulator) Model ¶ added in v0.11.0
func (a *ClaudeStreamAccumulator) Model() string
Model returns the model resolved from message_start, if present.
func (*ClaudeStreamAccumulator) Output ¶ added in v0.11.0
func (a *ClaudeStreamAccumulator) Output() []map[string]any
Output returns the accumulated assistant message, or nil when no content blocks were observed.
func (*ClaudeStreamAccumulator) StopReason ¶ added in v0.11.0
func (a *ClaudeStreamAccumulator) StopReason() any
StopReason returns the final provider stop reason, if present.
func (*ClaudeStreamAccumulator) Usage ¶ added in v0.11.0
func (a *ClaudeStreamAccumulator) Usage() map[string]any
Usage returns the merged usage fields from message_start and message_delta.
type MiddlewareTracer ¶
type MiddlewareTracer interface {
StartSpan(ctx context.Context, start time.Time, request io.Reader) (context.Context, trace.Span, error)
TagSpan(span trace.Span, response io.Reader) error
}
MiddlewareTracer adds tracing to API requests by parsing bodies of the request and response.
type NextMiddleware ¶
NextMiddleware represents the next middleware to run in the client middleware chain.
type TracerRouter ¶
type TracerRouter func(path string) MiddlewareTracer
TracerRouter maps URL paths to specific tracers for different endpoints.