otlpexport

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package otlpexport describes where the runtime ships its own traces and how it authenticates there, for every path that sends them: the server's own SDK exporter, the relay that forwards CLI spans, and the loopback relay that buildkitd exports through.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

DefaultTimeout bounds one export. It matches the OTel SDK's own default, which stops applying once the exporter is handed a custom client.

View Source
const RelayAddr = "127.0.0.1:14318"

RelayAddr is where the server accepts OTLP/HTTP traces from processes it runs outside any sandbox, today only buildkitd. It is fixed rather than ephemeral because buildkitd's container spec, env included, outlives a server restart; a port that moved on every restart would force the container to be recreated each time. The 1xxxx range follows etcd's lead in staying clear of the standard 4318 an operator's own collector may hold.

Variables

This section is empty.

Functions

func LoadRelaySecret

func LoadRelaySecret(path string) (string, error)

LoadRelaySecret returns the secret the relay's callers must present, creating it at path the first time.

It is kept on disk rather than minted per boot because it rides in buildkitd's env, and that env is part of a container spec that outlives a server restart; a new secret every boot would recreate the container every boot. A file that holds anything but a secret this function wrote, say one cut short by a crash, is replaced, which costs buildkitd one recreation.

func NewRelay

func NewRelay(log *slog.Logger, d Destination, secret string) http.Handler

NewRelay returns a handler that forwards OTLP/HTTP trace exports to d with its credentials applied, so a process that cannot refresh a token on its own can still export as the cluster's telemetry writer. The collector's status and response body pass straight back, which keeps the sender's own retry logic working.

Loopback is reachable by every process on the host, so a caller has to present secret as a bearer token; see LoadRelaySecret. Only the body and its content headers are forwarded, which strips that secret and keeps a caller from steering the export with headers the collector routes on, such as a tenant.

func ParseHeaders

func ParseHeaders(raw string) map[string]string

ParseHeaders parses the OTEL_EXPORTER_OTLP_HEADERS format, key1=value1, key2=value2, with values URL-decoded as the OTel spec requires (so a basic credential is written Authorization=Basic%20...). A value that fails to decode is kept as written.

func RelayHeaders

func RelayHeaders(secret string) string

RelayHeaders is the OTEL_EXPORTER_OTLP_*_HEADERS value that authenticates an exporter to the relay.

Types

type Destination

type Destination struct {
	// Endpoint is the OTLP/HTTP base URL; TracesURL appends the signal path.
	Endpoint string

	// Headers are static headers from OTEL_EXPORTER_OTLP_HEADERS and
	// OTEL_EXPORTER_OTLP_TRACES_HEADERS, attached to every export.
	Headers map[string]string

	// Token, when set, authenticates every export with a workload identity
	// bearer that replaces any static Authorization.
	Token workloadidentity.TokenSource
}

Destination is an OTLP/HTTP traces collector and the credentials for it.

func Resolve

func Resolve(log *slog.Logger, endpoint string, token workloadidentity.TokenSource) Destination

Resolve builds the destination for endpoint from the standard OTel header env vars and an optional token source.

When a token source is set, a static Authorization header is dropped here rather than silently overwritten per request, so the operator hears about it once at startup. That is also the migration path: set an audience while the old header is still in the unit, confirm the collector sees tokens, then remove the header.

func (Destination) Client

func (d Destination) Client() *http.Client

Client is an HTTP client that sends to this destination with its credentials applied.

The credentials live in the transport, so they would ride along on every hop of a redirect. Go's default client strips Authorization when a redirect changes host; this keeps that promise by not following such a redirect at all. The export ends with the redirect status rather than carrying the token or a static API key somewhere it wasn't configured to go. Redirects within the configured host are still followed.

func (Destination) Forward

func (d Destination) Forward(ctx context.Context, client *http.Client, body []byte, contentType, contentEncoding string) (int, error)

Forward posts an already encoded OTLP traces request, carrying its content type and encoding through untouched. It returns the collector's status so a relay can hand it back to whoever sent the spans.

func (Destination) TracesURL

func (d Destination) TracesURL() string

TracesURL is where OTLP/HTTP traces are posted for this destination.

func (Destination) Transport

func (d Destination) Transport(base http.RoundTripper) http.RoundTripper

Transport wraps base so every request carries the destination's static headers and, when configured, its workload identity bearer.

Jump to

Keyboard shortcuts

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