telemetry

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: BSD-3-Clause Imports: 38 Imported by: ? 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 telemetry is turnd's OpenTelemetry: traces, metrics and logs pushed over OTLP, with the official Go SDK. It is off, and costs nothing, until an endpoint is configured.

References opened for this package (2026-11-18):

  • OTLP specification, https://opentelemetry.io/docs/specs/otlp/ : OTLP/gRPC on 4317, OTLP/HTTP on 4318 with /v1/traces, /v1/metrics and /v1/logs and the application/x-protobuf content type.
  • W3C Trace Context, https://www.w3.org/TR/trace-context/ : section 3.4 (restarting a trace at the front gate of a secure network), 6.1 (privacy) and 7.2 (denial of monitoring by a public caller).
  • OpenTelemetry semantic conventions: HTTP spans (a server span is named "{method} {http.route}", a 4xx leaves the status unset, a 5xx sets Error), gRPC (rpc.system.name grpc, rpc.method, rpc.status_code) and the network attributes (network.transport, network.type).

The two things a collector must never learn from turnd are credentials and people: no token, code, cookie, password, room ID or TURN username, and no client or peer address, ever reaches a span, a metric or a log record. See the scrubbing in scrub.go, which applies to what the SDK instrumentation adds on its own as well.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Endpoint is the collector: https://host:4318 for Protocol "http" (the
	// signal paths /v1/traces, /v1/metrics and /v1/logs are appended), host:4317
	// for "grpc". Empty turns telemetry off.
	Endpoint string
	// Protocol is "http" (default) or "grpc".
	Protocol string
	// Token is the collector's bearer token, already read from its file. It is
	// sent as "Authorization: Bearer <token>" and nowhere else.
	Token string
	// Insecure allows http:// (or plaintext gRPC) to the collector.
	Insecure bool
	// SampleRatio is the fraction of traces kept, 0..1 (default 1: DefaultConfig).
	SampleRatio float64
	// ServiceName is service.name (default "turnd").
	ServiceName string
	// TrustClientContext continues a caller's W3C traceparent. Off, every
	// request starts its own trace: a public caller can neither join a trace
	// nor force sampling (W3C Trace Context 3.4 and 7.2).
	TrustClientContext bool
	// Version is service.version.
	Version string
	// MetricInterval is how often metrics are pushed (default 60 s).
	MetricInterval time.Duration
	// BatchInterval is how often spans and log records are flushed (the SDK
	// defaults: 5 s for spans, 1 s for logs). Zero keeps them; tests shorten it.
	BatchInterval time.Duration
}

Config is the telemetry configuration. The zero value (no Endpoint) is off.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig holds the defaults of every flag.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether an endpoint is configured.

func (Config) Validate

func (c Config) Validate() error

Validate refuses a configuration that would leak or cannot work. A disabled configuration with any other telemetry flag set is refused too: it would be silently ignored.

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

The instruments, one per fact. Names are turnd.*; units are UCUM ({thing} for a count, By for bytes, s for seconds). Every attribute has a small fixed set of values: nothing here is a person, a credential or an address.

turnd.relay.allocations            gauge    {allocation}  live TURN allocations
turnd.relay.permissions            gauge    {permission}  live permissions
turnd.relay.channels               gauge    {channel}     live channel bindings
turnd.relay.requests               counter  {request}     control requests by turnd.method, turnd.transport, turnd.result
turnd.relay.policy.refusals        counter  {refusal}     peer-address refusals by turnd.policy
turnd.relay.auth.failures          counter  {failure}     by turnd.surface (relay, api) and turnd.reason
turnd.relay.bytes                  counter  By            relayed payload by turnd.direction
turnd.relay.packets                counter  {packet}      relayed datagrams by turnd.direction
turnd.relay.packets.dropped        counter  {packet}      datagrams dropped (no permission, rate cap, bad frame)
turnd.rooms                        gauge    {room}        live rooms
turnd.guests                       gauge    {guest}       by turnd.state (pending, admitted)
turnd.rendezvous.operations        counter  {operation}   by turnd.action and turnd.outcome
turnd.login.outcomes               counter  {login}       by turnd.outcome
http.server.request.duration       histogram s            /login, /callback, /healthz (HTTP semantic conventions)

What other signals are derived from these: allocations created and refused are turnd.relay.requests{method=allocate} with result ok or the refusal; knocks, admits and denies are turnd.rendezvous.operations{action=knock, admit, deny}; credentials minted are the operations credentials_host and credentials_room with outcome ok; sessions issued and refused are turnd.login.outcomes. The gRPC instrumentation adds rpc.server.* on its own.

func (*Metrics) AuthObserve

func (m *Metrics) AuthObserve(ctx context.Context, reason string)

AuthObserve is session.Auth.Observe: why a token was refused. The reason is a fixed word, never the verifier's error text.

func (*Metrics) BindRelay

func (m *Metrics) BindRelay(stats func() server.Stats, usage func() server.Usage)

BindRelay tells the gauges where the relay's counters are. Call it once the relay exists.

func (*Metrics) BindRendezvous

func (m *Metrics) BindRendezvous(counts func() rendezvous.Counts)

BindRendezvous tells the gauges where the rooms are.

func (*Metrics) LoginObserve

func (m *Metrics) LoginObserve(ctx context.Context, outcome string)

LoginObserve is session.LoginConfig.Observe.

func (*Metrics) RendezvousObserver

func (m *Metrics) RendezvousObserver() rendezvous.Observer

RendezvousObserver is rendezvous.Config.Observer.

func (*Metrics) ServerObserver

func (m *Metrics) ServerObserver() server.Observer

ServerObserver is the relay's observer: server.Config.Observer.

type Telemetry

type Telemetry struct {
	// contains filtered or unexported fields
}

Telemetry is the running pipeline: a tracer, the instruments and the log handler. A disabled one (Setup with no endpoint) is a no-op everywhere.

func Setup

func Setup(ctx context.Context, cfg Config, warn func(string)) (*Telemetry, error)

Setup builds the pipeline for cfg. warn receives one line per ignored environment variable. With no endpoint it returns a disabled Telemetry.

func (*Telemetry) Enabled

func (t *Telemetry) Enabled() bool

Enabled reports whether telemetry is exporting.

func (*Telemetry) HTTP

func (t *Telemetry) HTTP(h http.Handler, skip ...string) http.Handler

HTTP wraps h in a server span and the request-duration histogram, following the HTTP semantic conventions: the span is named "{method} {http.route}", a 5xx sets the status to Error and a 4xx leaves it unset.

The URL's query is never recorded (the callback's holds the authorization code and the state) and neither is the client address, the user agent or any header. url.path is recorded only for a route that exists, so a scanner's path cannot become an attribute. Requests whose path is in skip (the gRPC WebSocket, whose RPCs the gRPC instrumentation traces) pass through.

A caller's traceparent is continued only with Config.TrustClientContext; otherwise the trace restarts here (W3C Trace Context 3.4, 7.2).

func (*Telemetry) Logger

func (t *Telemetry) Logger(w io.Writer, level slog.Level) *slog.Logger

Logger builds turnd's logger: JSON on w (journald-friendly), each record carrying trace_id and span_id when a span is active in its context, and, when telemetry is on, the same records exported over OTLP through the slog bridge after redaction.

func (*Telemetry) MeterProvider

func (t *Telemetry) MeterProvider() metric.MeterProvider

func (*Telemetry) Metrics

func (t *Telemetry) Metrics() *Metrics

Metrics returns the instruments (inert when disabled).

func (*Telemetry) Propagator

func (t *Telemetry) Propagator() propagation.TextMapPropagator

Propagator is the propagator the gRPC server instrumentation extracts a caller's context with: W3C Trace Context when the configuration trusts the caller, otherwise an empty one, so the RPC starts its own trace.

func (*Telemetry) Shutdown

func (t *Telemetry) Shutdown(ctx context.Context) error

Shutdown flushes and stops every signal.

func (*Telemetry) TracerProvider

func (t *Telemetry) TracerProvider() trace.TracerProvider

TracerProvider and MeterProvider are for the gRPC instrumentation.

Jump to

Keyboard shortcuts

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