telemetry

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func VirtualKeyFromContext(ctx context.Context) string

func WithVirtualKey

func WithVirtualKey(ctx context.Context, name string) context.Context

Types

type AsyncOptions

type AsyncOptions struct {
	Capacity      int
	BatchSize     int
	FlushInterval time.Duration
}

type AsyncRecorder

type AsyncRecorder struct {
	// contains filtered or unexported fields
}

func NewAsyncRecorder

func NewAsyncRecorder(publisher Publisher, options AsyncOptions) *AsyncRecorder

func (*AsyncRecorder) Close

func (r *AsyncRecorder) Close(ctx context.Context) error

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 Attempt

type Attempt struct {
	Account    string `json:"account"`
	Adapter    string `json:"adapter"`
	Alias      string `json:"alias,omitempty"`
	Status     int    `json:"status"`
	LatencyMS  int64  `json:"latency_ms"`
	Outcome    string `json:"outcome"`
	CooldownMS int64  `json:"cooldown_ms,omitempty"`
}

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"`
}

func (Event) String

func (e Event) String() string

type Publisher

type Publisher interface {
	Publish(context.Context, []Event) error
}

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.

Jump to

Keyboard shortcuts

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