Documentation
¶
Overview ¶
Package otlpreceiver records model calls that clients report over OpenTelemetry instead of sending through relay. It serves the OTLP/HTTP export endpoints for traces and logs: each exported span or log record that a registered convention recognises as a model call becomes a usage event attributed to the authenticated caller and priced from the catalog. When the operator turns content capture on, the message content a client reports with a call is stored as the event's payload record.
Reported usage is self-declared, so nothing here is an enforcement point: no policy grant or key pool is consulted, any valid credential may report except one whose governing policy is disabled, and every event carries the source "otlp" so readers can tell it from traffic relay carried. The one limit applied is the rate limit on export requests, which protects the receiver itself. Records that are not model calls are not stored. The metrics signal is out of scope.
Exporters retry, and a client may report one call as a span and as an event, so a call is identified by its reporter's project (or principal), trace id and span id and recorded once: an export that cannot be queued whole is refused and sent again, and the calls already recorded are skipped. Content is marked separately from usage, so content that arrives after the usage row is still stored, once. Whether content is stored at all is the operator's decision, not the client's: a policy that governs the reporter must allow payload logging, and only a reporter with no policy has what it sends kept. The usage and payload queues are shared with proxied traffic, which drops records when they are full, so reported records are queued only while a queue is under half full.
Expected kv ops per export: 1 RunScript for the rate limit reservation, and 1 batched round trip marking the export's calls (one script call per distinct trace id, pipelined when the store batches). An export carrying content while capture is on adds 1 batched round trip marking that content. A further batched round trip removes markers only when a queue filled while the export was being queued.
Index ¶
Constants ¶
const ( ExtrasKeyConvention = "telemetry_convention" ExtrasKeyTraceID = "trace_id" ExtrasKeySpanID = "span_id" ExtrasKeyResponseID = "response_id" ExtrasKeyService = "service" ExtrasKeyOperation = "operation" ExtrasKeyReportedProvider = "reported_provider" // ExtrasKeyReportedError holds the error type of a failed call as the client reported it; the event's error kind is relay's own classification of it. ExtrasKeyReportedError = "reported_error_type" )
Extras keys stamped on reported events, beside the instance and session keys proxied traffic already uses.
const ( TracesPath = "/otlp/v1/traces" LogsPath = "/otlp/v1/logs" )
TracesPath and LogsPath are where the export endpoints mount. An OTLP exporter appends /v1/<signal> to its configured endpoint, so clients point at <inference url>/otlp.
const DefaultMaxBodyBytes = 16 << 20
DefaultMaxBodyBytes bounds a decompressed export when Options.MaxBodyBytes is unset.
const MaxRecords = 10_000
MaxRecords is the most model calls one export may report.
const RateLimitName = "otlp-export"
RateLimitName is the system RateLimit that caps export requests per credential.
const Source = "otlp"
Source is the usage event source of every model call recorded from telemetry.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Call ¶
Call identifies one reported model call within a tenant. Every signal that reports the same call uses the same identity: the ids of the span the call ran in. A call reported without them is identified by a digest of its response id in TraceID.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the OTLP/HTTP export endpoints. It expects the inference authentication middleware in front of it.
type Limiter ¶
type Limiter interface {
Reserve(ctx context.Context, scope string, rules []pkgratelimit.Rule) (*pkgratelimit.Reservation, error)
}
Limiter is the rate limiter the receiver reserves one request on per export.
type MarkerKind ¶
type MarkerKind string
MarkerKind names what was stored for a reported call. The kinds are marked independently, so content that arrives after a call's usage is still stored once.
const ( MarkerUsage MarkerKind = "usage" MarkerContent MarkerKind = "content" )
type Markers ¶
type Markers struct {
// contains filtered or unexported fields
}
Markers remembers which reported calls were already stored, so a call an exporter sends again is stored once. Every method takes the tenant the calls were reported for: the same ids reported by two tenants are two calls. Safe for concurrent use.
func NewMarkers ¶
NewMarkers returns Markers over s, which may also implement kv.BatchScripter to mark an export in one round trip.
func (*Markers) Mark ¶
func (m *Markers) Mark(ctx context.Context, tenant string, kind MarkerKind, calls []Call) ([]bool, error)
Mark marks kind as stored for each call and reports, per call, whether this was the first time. calls must not repeat a call. When the store fails, the calls it could not answer for are reported as first-time and the error is returned, so a failing store never loses a record.
type Options ¶
type Options struct {
// Enabled reports whether the receiver currently accepts exports. Read per request so the setting applies without a restart.
Enabled func() bool
// Snapshot returns the current catalog snapshot, used when the request context carries none.
Snapshot func() *appcatalog.Snapshot
// Usage takes the recorded events.
Usage UsageQueue
// Markers recognises calls that were already recorded. Nil records every call it is sent.
Markers *Markers
// Limiter enforces the export rate limit per credential. Nil applies none.
Limiter Limiter
// Pricer prices each event's tokens. Nil leaves events unpriced.
Pricer *usagelog.Pricer
// SpanMappers and LogMappers are the telemetry conventions understood per signal, tried in order.
SpanMappers []otlp.SpanMapper
LogMappers []otlp.LogMapper
// ProviderHints maps a provider name as telemetry reports it, lowercase, to what it refers to in the catalog.
ProviderHints map[string]ProviderHint
// CaptureContent reports whether the receiver is set to store the message content clients report. Read per request. Content is stored only while PayloadLog is enabled as well.
CaptureContent func() bool
// PayloadLog and Payloads are the payload store proxied traffic uses. Without both, content is never stored.
PayloadLog PayloadLog
Payloads PayloadQueue
// InstanceID is stamped on events the same way as on proxied traffic.
InstanceID string
// MaxBodyBytes bounds a decompressed export body.
MaxBodyBytes int64
// UsageRetention and ContentRetention report how long the usage store and the payload store keep a record, counted from the call's start; zero or a nil func means no limit. Read per request. A call older than the usage retention is rejected, and content older than the content retention is not stored: the store would delete either on arrival.
UsageRetention func() time.Duration
ContentRetention func() time.Duration
}
Options configures a Handler.
type PayloadLog ¶
PayloadLog is the payload store's live switch and its cap on a stored body in bytes (0 = none).
type PayloadQueue ¶
type PayloadQueue interface {
TryEmit(payload.Record) bool
// contains filtered or unexported methods
}
PayloadQueue is the payload pipeline as the receiver needs it, for the message content of reported calls.
type ProviderHint ¶
type ProviderHint struct {
// Provider is the slug of the catalog provider whose models are reported under the name.
Provider string
// Host is the slug of the catalog host that serves calls reported under the name; its pricing applies to them.
Host string
}
ProviderHint says what a provider name in telemetry refers to in the catalog. Telemetry conventions name providers their own way, and often name the service that served the call rather than the company whose model it is. Either field may be empty.
type UsageQueue ¶
type UsageQueue interface {
TryEmit(usagelog.Event) bool
// contains filtered or unexported methods
}
UsageQueue is the usage pipeline as the receiver needs it: a bounded queue that reports a full queue instead of dropping, so the export can be refused and sent again.