telemetry

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package telemetry wires a service's traces and metrics as one thing.

The signals are configured separately but must agree on three facts: the `service.name` both report under, whether the HTTP layer is instrumented at all (one otelhttp wrapper emits both), and shutdown. Init returns a value that owns all three, plus the Prometheus registry and scrape listener - no package globals, so two stacks can coexist.

pkg/otel and pkg/metrics keep their own entry points for projects that wire the signals by hand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ServiceName string        `yaml:"serviceName"`
	OTel        OTelConfig    `yaml:"otel"`
	Metrics     MetricsConfig `yaml:"metrics"`
}

Config is the telemetry block of a project's config.yaml. ServiceName sits above both signals and fills in for an empty per-signal name.

type MetricsConfig

type MetricsConfig = metrics.Config

OTelConfig / MetricsConfig re-export the per-signal config shapes so a project can name them without importing both packages.

type OTelConfig

type OTelConfig = craftotel.Config

OTelConfig / MetricsConfig re-export the per-signal config shapes so a project can name them without importing both packages.

type Telemetry

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

Telemetry is a live stack: providers, the registry the scrape gathers, and the listener serving it. A nil *Telemetry is usable - every method degrades to a no-op, so callers never branch on it.

func Init

func Init(ctx context.Context, c Config) (*Telemetry, error)

Init builds the stack described by c. Either signal, both, or neither may be enabled. The Prometheus scrape gets its own listener (`metrics.adminAddr`), not the public API port, so it can be firewalled separately.

func (*Telemetry) AdminErr

func (t *Telemetry) AdminErr() <-chan error

AdminErr surfaces a post-startup failure of the scrape listener, or nil when none runs. Callers must check for nil: receiving from a nil channel blocks forever.

func (*Telemetry) HTTPMiddleware

func (t *Telemetry) HTTPMiddleware() server.Middleware

HTTPMiddleware instruments every request against THIS stack's providers, not the global slots. With neither signal configured it returns a plain pass-through, so an unconfigured process pays nothing.

func (*Telemetry) MeterProvider

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

func (*Telemetry) Registerer

func (t *Telemetry) Registerer() prom.Registerer

Registerer exposes the registry backing the scrape, for attaching your own client_golang collectors. Nil when this stack has no scrape.

func (*Telemetry) ScrapeURL

func (t *Telemetry) ScrapeURL() string

ScrapeURL is the `host:port/path` the listener bound to, or "" when none started. The port is the resolved one, so a `:0` bind is loggable.

func (*Telemetry) Shutdown

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

Shutdown closes everything this stack owns, listener first, then the providers - whose Shutdown flushes any pending push batch. Errors are collected, not short-circuited, so one failure cannot skip the rest.

func (*Telemetry) TracerProvider

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

TracerProvider / MeterProvider expose the stack's providers for code that wants its own spans or instruments. Both return the OTel no-op when that signal is off, so call sites never nil-check.

Jump to

Keyboard shortcuts

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