telemetry

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package telemetry is what Tern's logging and tracing exporters share: sending a batch over HTTP with gzip, status codes mapped to retries and Retry-After, and OTLP's JSON encoding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, r Request) error

Do sends r. Errors that retrying can fix (connection errors, 408, 429 and 5xx) are returned as they are, or with batch.RetryAfter; the rest are batch.Permanent.

func Endpoint

func Endpoint(explicit, signal string) string

Endpoint is where an OTLP signal ("logs", "traces") is posted: explicit, or OTEL_EXPORTER_OTLP_<SIGNAL>_ENDPOINT, or OTEL_EXPORTER_OTLP_ENDPOINT with /v1/<signal> added, or a collector on localhost.

func Headers

func Headers(signal string, extra http.Header) http.Header

Headers are the signal's headers from the environment, then extra.

func ParseHeaders

func ParseHeaders(s string) http.Header

ParseHeaders reads ParsePairs' format as headers.

Types

type AnyValue

type AnyValue struct {
	StringValue *string  `json:"stringValue,omitempty"`
	IntValue    *string  `json:"intValue,omitempty"`
	DoubleValue *float64 `json:"doubleValue,omitempty"`
	BoolValue   *bool    `json:"boolValue,omitempty"`
	KvlistValue *KVList  `json:"kvlistValue,omitempty"`
}

AnyValue is an attribute's value: one of its fields is set.

func String

func String(s string) AnyValue

String is a string value.

func Value

func Value(v slog.Value) AnyValue

Value encodes a slog value as OTLP's AnyValue.

type KVList

type KVList struct {
	Values []KeyValue `json:"values"`
}

KVList is a group of attributes.

type KeyValue

type KeyValue struct {
	Key   string   `json:"key"`
	Value AnyValue `json:"value"`
}

KeyValue is an attribute.

func Attrs

func Attrs(attrs []slog.Attr) []KeyValue

Attrs encodes attributes, groups as key-value lists.

type Pair

type Pair struct{ Key, Value string }

Pair is a key and its value.

func ParsePairs

func ParsePairs(s string) []Pair

ParsePairs reads "k=v,k2=v2", as OTEL_EXPORTER_OTLP_HEADERS and OTEL_RESOURCE_ATTRIBUTES have them, with URL-encoded values.

type Request

type Request struct {
	Client      *http.Client // nil: http.DefaultClient
	URL         string
	ContentType string
	Header      http.Header
	Body        []byte
	Gzip        bool
}

Request is one push.

type Resource

type Resource struct {
	Attributes []KeyValue `json:"attributes,omitempty"`
}

Resource describes what sent the data: service.name and the rest.

func NewResource

func NewResource(service string, extra map[string]string) Resource

NewResource is service.name and the other resource attributes: OTEL_RESOURCE_ATTRIBUTES', then extra's, sorted by key. The service is named by service, OTEL_SERVICE_NAME, the attributes, or the program.

type Scope

type Scope struct {
	Name string `json:"name"`
}

Scope names the library that made the data.

Jump to

Keyboard shortcuts

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