Documentation
¶
Overview ¶
OTel GenAI emission (G3): when an OTLP endpoint is configured via env (OTEL_EXPORTER_OTLP_ENDPOINT / OTEL_EXPORTER_OTLP_TRACES_ENDPOINT), every gateway request is mirrored as a trace span with the minimal gen_ai.* attribute set (model, tokens, operation, status). OTEL_SDK_DISABLED=true turns the whole thing off; without an endpoint the wrapper is a no-op that forwards to the underlying recorder untouched (zero dependency on the OTel runtime in default deployments).
Index ¶
Constants ¶
const ( DefaultCapacity = 1024 DefaultBatchSize = 10 DefaultFlushInterval = time.Second )
Variables ¶
This section is empty.
Functions ¶
func OTelEnabled ¶
func OTelEnabled() bool
OTelEnabled reports whether an OTLP exporter should be started: an endpoint env var is set and the SDK is not explicitly disabled.
func VirtualKeyFromContext ¶
Types ¶
type AsyncOptions ¶
type AsyncRecorder ¶
type AsyncRecorder struct {
// contains filtered or unexported fields
}
func NewAsyncRecorder ¶
func NewAsyncRecorder(publisher Publisher, options AsyncOptions) *AsyncRecorder
func (*AsyncRecorder) Dropped ¶
func (r *AsyncRecorder) Dropped() uint64
func (*AsyncRecorder) FailedBatches ¶
func (r *AsyncRecorder) FailedBatches() uint64
func (*AsyncRecorder) Record ¶
func (r *AsyncRecorder) Record(event Event)
type Event ¶
type Event struct {
RequestID string `json:"request_id"`
GatewayID string `json:"gateway_id,omitempty"`
OccurredAt time.Time `json:"occurred_at"`
Endpoint string `json:"endpoint"`
PublicModel string `json:"public_model"`
UpstreamModel string `json:"upstream_model"`
VirtualKey string `json:"virtual_key"`
VirtualKeyID string `json:"virtual_key_id,omitempty"`
FinalStatus int `json:"final_status"`
Success bool `json:"success"`
TotalLatencyMS int64 `json:"total_latency_ms"`
// OverheadMS and UpstreamTTFBMS are gateway-internal latency metrics.
// They are excluded from the wire format (json:"-") because the
// control-plane RequestEventSchema is strict and rejects unknown fields.
OverheadMS int64 `json:"-"`
UpstreamTTFBMS int64 `json:"-"`
Streaming bool `json:"streaming"`
ConfigVersion int64 `json:"config_version,omitempty"`
InputTokens int64 `json:"input_tokens,omitempty"`
OutputTokens int64 `json:"output_tokens,omitempty"`
TotalTokens int64 `json:"total_tokens,omitempty"`
CostUSD float64 `json:"cost_usd,omitempty"`
Attempts []Attempt `json:"attempts"`
}
type Recorder ¶
type Recorder interface {
Record(Event)
}
func NewOTelRecorder ¶
func NewOTelRecorder(base Recorder, serviceName string) (Recorder, func(ctx context.Context) error, error)
NewOTelRecorder wraps base with span emission. When OTel is not configured (or disabled) it returns (nil, noopShutdown, nil) so callers can keep one code path. base may be nil when the gateway otherwise has no recorder (lite mode) — spans still flow, plain telemetry does not.