otlpemit

package
v1.0.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 25 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

Package otlpemit sends a rows file to an OpenTelemetry backend as traces over OTLP/HTTP: one span per model request.

Token counts travel as integers under the OpenTelemetry GenAI attributes. A request's cost travels as three strings, costroid.cost.amount, costroid.cost.currency and costroid.cost.basis, so no backend reads it as a float and rounds it. Amounts are summed only within one request, whose rows share one currency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromEnvironment

func FromEnvironment(getenv func(string) string) (Config, []Warning, error)

FromEnvironment reads the OTLP exporter variables. A value the specification says to ignore is read as unset and returned as a warning. An endpoint that is not http or https, the grpc protocol and a certificate that does not load are errors.

func Redacted

func Redacted(endpoint *url.URL) string

Redacted is an endpoint as a line may print it: scheme, host and path, with no user information and no query.

Types

type Config

type Config struct {
	Endpoint *url.URL
	// Headers are sent with every request. Their values are credentials as
	// often as not, so nothing prints them.
	Headers  [][2]string
	Protocol Protocol
	Timeout  time.Duration
	Gzip     bool
	// TLS is nil unless a certificate variable is set.
	TLS *tls.Config
}

Config is where and how the spans go.

type Emitter

type Emitter struct {
	Config  Config
	Version string
	// Sleep waits between tries. Nil waits on a timer.
	Sleep func(context.Context, time.Duration) error
}

Emitter sends rows as spans.

func (Emitter) Emit

func (e Emitter) Emit(ctx context.Context, rows []byte) (Result, error)

Emit sends a rows file. It sends nothing when a line is not a row of the contract. It stops at the first request the endpoint refuses, and Result counts what went before.

type Protocol

type Protocol string

Protocol is an OTLP/HTTP body encoding.

const (
	Protobuf Protocol = "http/protobuf"
	JSON     Protocol = "http/json"
)

The protocols of OTEL_EXPORTER_OTLP_PROTOCOL that emit-otlp sends.

type RefusedError

type RefusedError struct {
	Status int
	Spans  int
}

RefusedError is an endpoint that answered a request with a status other than 2xx, after any retries. The spans of that request were not taken.

func (*RefusedError) Error

func (e *RefusedError) Error() string

type Result

type Result struct {
	Rows, Spans int
	// Rejected counts the spans an endpoint answered as refused in a partial
	// success, and Message is its reason, cleaned of control characters.
	Rejected int64
	Message  string
}

Result is what one Emit sent.

type Warning

type Warning struct {
	Variable string
	// Value and Want are empty for an entry of the headers, whose values are
	// credentials as often as not.
	Value, Want string
}

Warning is a variable whose value the exporter specification says to ignore: it was read as unset, or one entry of it was.

func (Warning) String

func (w Warning) String() string

Jump to

Keyboard shortcuts

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