Documentation
¶
Overview ¶
Package otlp reads OTLP/HTTP traces and logs into per-request usage.
It is the ingest edge for telemetry. Decoding keeps only allowlisted scalar attributes, so content never reaches a Usage, and every field left behind is counted by name. A record that carries no token counts yields nothing.
Index ¶
Constants ¶
const ( // DropClientCost counts a sender's own cost figure. DropClientCost = "client_cost" // DropContent counts a field whose name reads as content but is not listed. DropContent = "content_other" // DropUnlisted counts anything else outside the allowlist. DropUnlisted = "unlisted" // DropOversized counts an allowed attribute over maxValueBytes. DropOversized = "oversized_value" // DropNonScalar counts an allowed attribute that is an array or a map. DropNonScalar = "non_scalar_value" // DropLogBody counts a log body, which is free text. DropLogBody = "log.body" // DropStatusMessage counts a span status message, which is free text. DropStatusMessage = "span.status.message" // DropEmail counts a user.email, replaced by a login or a pseudonym. DropEmail = "user.email" // DropMetrics counts a metrics export. Rows come from logs and spans. DropMetrics = "metrics_export" )
Counter labels for fields the edge drops. Labels are a closed set, so a sender cannot grow the counter table by naming new attributes.
const MaxTokens = 1_000_000_000_000
MaxTokens bounds one class of one request, far above any model's context, so a sum of counts cannot overflow.
const NoteTotalDisagrees = "the agent's total token count is not the sum of its counts, so this figure may read low or high"
NoteTotalDisagrees marks a request whose stated total is not the sum of its counts. The server logs a warning for each such request.
Variables ¶
var ErrMalformed = errors.New("otlp: malformed payload")
ErrMalformed means a body did not decode.
Functions ¶
Types ¶
type Batch ¶
type Batch struct {
Usage []Usage
// Rejected counts records the edge could not use: a record that did not
// decode, or one whose token counts could not be read.
Rejected int
// Drops counts every field left behind, by label.
Drops map[string]int64
}
Batch is one decoded request.
type Count ¶
type Count struct {
Class focus.TokenClass
Tokens int64
}
Count is one token class of one request.
type Usage ¶
type Usage struct {
// ID is the provider's request or response id when the record has one, and
// a stand-in derived from the record when it does not.
ID string
Dialect Dialect
Provider string
Model string
ServiceTier string
ContextInputTokens int64
Start, End time.Time
Counts []Count
// AssumedWrite is the cache write class that took tokens whose lifetime the
// dialect did not report. Empty when it reported all.
AssumedWrite focus.TokenClass
// Notes state a limit of this dialect in words and travel on the row.
Notes []string
Session string
Agent string
AgentVersion string
CostBasis focus.CostBasis
EnforcementGrade string
// Repo, PullRequest, CommitSHA and RunID are the sender's join keys.
Repo string
PullRequest string
CommitSHA string
RunID string
// Email is held in memory only, to be replaced before anything is stored.
Email string
// RequestID is the provider's id alone, empty when ID is a stand-in.
RequestID string
}
Usage is one model request as a dialect reports it.