Documentation
¶
Overview ¶
Package otlp is the wire side of an OpenTelemetry receiver over OTLP/HTTP for the traces and logs signals: it reads and decodes export requests (protobuf and JSON), exposes their spans and log records in a neutral shape, and encodes the export response. A SpanMapper or LogMapper per telemetry convention turns the records that describe model calls into Inference records.
Authentication, attribution, pricing and storage belong to the caller. The metrics signal and the gRPC transport are out of scope.
Index ¶
- Constants
- Variables
- func ExportResponse(mediaType string, signal Signal, rejected int64, message string) []byte
- func MediaType(contentType string) (string, error)
- func ReadBody(body io.Reader, contentEncoding string, limit int64) ([]byte, error)
- func StatusBody(mediaType string, code int32, message string) []byte
- type Attrs
- type Content
- type Inference
- type LogMapper
- type LogRecord
- type Signal
- type Span
- type SpanMapper
- type TokenCounts
Constants ¶
const ( MediaTypeProtobuf = "application/x-protobuf" MediaTypeJSON = "application/json" )
The two encodings OTLP/HTTP defines.
const ( StatusInvalidArgument int32 = 3 StatusNotFound int32 = 5 StatusResourceExhausted int32 = 8 )
gRPC status codes carried in the Status body of an OTLP/HTTP error response.
Variables ¶
var ErrBodyTooLarge = errors.New("otlp: request body too large")
ErrBodyTooLarge reports a request body over the limit, measured after decompression.
var ErrUnsupportedEncoding = errors.New("otlp: unsupported content encoding")
ErrUnsupportedEncoding reports a Content-Encoding other than gzip or identity.
var ErrUnsupportedMediaType = errors.New("otlp: unsupported content type")
ErrUnsupportedMediaType reports a Content-Type that is neither OTLP/HTTP encoding.
Functions ¶
func ExportResponse ¶
ExportResponse encodes the export response of signal (ExportTraceServiceResponse, ExportLogsServiceResponse) in mediaType. rejected > 0 makes it a partial success naming how many records were refused and why. With nothing rejected, a message makes it a warning to the client about an export that was accepted in full, which OTLP carries as a partial success with a count of zero. With neither, the response is the empty success message.
Types ¶
type Attrs ¶
Attrs is a set of OpenTelemetry attributes with values converted to Go types: string, bool, int64, float64, []byte, []any and map[string]any.
The accessors take several keys because conventions rename attributes between releases; the first key that holds a usable value wins.
func (Attrs) Int ¶
Int returns the first integer among keys. Conventions type counts as int, but exporters also send them as whole doubles or numeric strings.
type Content ¶
type Content struct {
// Input holds what was sent to the model: instructions, messages, tool definitions.
Input map[string]any
// Output holds what the model returned.
Output map[string]any
}
Content is the message content a client chose to report with a model call. Each side maps the convention's attribute names to their values as sent: structured values, or the JSON text some exporters put on spans instead. A side the telemetry did not carry is nil.
type Inference ¶
type Inference struct {
// Convention is the Name of the mapper that produced the record.
Convention string
// TraceID and SpanID are those of the span the call ran in. A log record emitted outside a span has neither.
TraceID string
SpanID string
// Service is the reporting application's service.name resource attribute.
Service string
Start time.Time
Duration time.Duration
Operation string
Provider string
RequestModel string
ResponseModel string
// ResponseID is the provider's identifier for the response.
ResponseID string
ConversationID string
FinishReason string
// Host is the catalog host slug the client says served the call, from relay's own wyolet.relay.host attribute; empty from clients that do not know the catalog.
Host string
Streamed bool
TimeToFirstChunk time.Duration
// ErrorType is set when the call failed; HTTPStatus is the provider's response status when the telemetry carried one.
ErrorType string
HTTPStatus int
Tokens TokenCounts
Content Content
}
Inference is one model call as a client's telemetry reported it. Fields the telemetry did not carry stay zero.
type LogMapper ¶
type LogMapper interface {
// Name identifies the convention.
Name() string
// MapLog reports false for a record that is not a model call under this convention. Such a record is left for the next mapper.
MapLog(r LogRecord) (Inference, bool)
}
LogMapper recognises the log records of one telemetry convention that describe a model call.
type LogRecord ¶
type LogRecord struct {
// TraceID and SpanID are lowercase hex, and empty on a record emitted outside a span.
TraceID string
SpanID string
// EventName names the event the record is, when it is one. Exporters older than the field carry the name in the event.name attribute instead.
EventName string
// Time is when the event happened; Observed is when the collecting SDK saw it. Either may be zero.
Time time.Time
Observed time.Time
// Body is the record's body converted like an attribute value, nil when absent.
Body any
Attrs Attrs
Resource Attrs
// Scope is the instrumentation scope name.
Scope string
}
LogRecord is one exported log record with its resource and scope flattened onto it.
type Span ¶
type Span struct {
// TraceID, SpanID and ParentSpanID are lowercase hex; ParentSpanID is empty on a root span.
TraceID string
SpanID string
ParentSpanID string
Name string
Start time.Time
End time.Time
// Failed reports a span status of ERROR.
Failed bool
StatusMessage string
Attrs Attrs
Resource Attrs
// Scope is the instrumentation scope name.
Scope string
}
Span is one exported span with its resource and scope flattened onto it, so a mapper reads everything about the span from one value.
type SpanMapper ¶
type SpanMapper interface {
// Name identifies the convention.
Name() string
// MapSpan reports false for a span that is not a model call under this convention. Such a span is left for the next mapper.
MapSpan(s Span) (Inference, bool)
}
SpanMapper recognises the spans of one telemetry convention that describe a model call.
type TokenCounts ¶
type TokenCounts struct {
Input int64
Output int64
CacheRead int64
CacheWrite int64
Reasoning int64
AudioInput int64
AudioOutput int64
}
TokenCounts are the token counts of one model call. Input excludes cached tokens, which CacheRead and CacheWrite count. Reasoning and AudioOutput are parts of Output, and AudioInput is a part of the input, not additions to them.