opentelemetry

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 28 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 opentelemetry sets up the OpenTelemetry metrics and tracing of the relay proxy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enabled added in v0.2.0

func Enabled(cfg *Settings) bool

Enabled reports whether tracing is on: an endpoint of the bootstrap file or of the standard variables (the general one or the one of the traces), or an exporter chosen with OTEL_TRACES_EXPORTER, and neither OTEL_SDK_DISABLED=true nor OTEL_TRACES_EXPORTER=none. With none of these OpenTelemetry stays off: the relay does not export to localhost by default.

func ExportEnvironment

func ExportEnvironment(cfg *Settings)

ExportEnvironment gives the OTLP endpoint and the sampler of the bootstrap file to the OpenTelemetry SDK, which reads them from OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_TRACES_SAMPLER. The bootstrap file wins: a value it sets replaces the variable (and the endpoints of one signal, which would take precedence over the general one); a value it leaves out is not touched, and the SDK reads the variable. It changes the environment of the process, so it belongs to the startup wiring (main): call it once, before Init.

func LogAttrs added in v1.3.0

func LogAttrs(info *model.OpenTelemetryInfo) []slog.Attr

LogAttrs are the attributes of the line that says at the start whether OpenTelemetry is on, and how.

Types

type Option added in v0.2.0

type Option func(*OtelService)

Option customizes an OtelService.

func WithMetricReader added in v0.2.0

func WithMetricReader(reader sdkmetric.Reader) Option

WithMetricReader makes the metrics go to the reader instead of the exporter that the OTEL_* environment variables select. It is for the tests, which read the metrics themselves.

func WithSpanExporter added in v1.0.0

func WithSpanExporter(exporter sdktrace.SpanExporter) Option

WithSpanExporter makes the spans go to the exporter instead of the one that the OTEL_* environment variables select. It is for the tests, which read the spans themselves.

type OtelService

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

OtelService owns the OpenTelemetry providers of the relay proxy: the tracer provider and, with the same configuration, the meter provider (Go runtime metrics, and the HTTP server metrics of the requests).

func NewOtelService

func NewOtelService(opts ...Option) OtelService

NewOtelService returns an OtelService, with no provider: Init creates them.

func (*OtelService) Describe added in v1.3.0

func (s *OtelService) Describe(cfg *Settings) model.OpenTelemetryInfo

Describe says what the service does: whether OpenTelemetry is on, and per signal the exporter, the protocol and the host of the endpoint. It reads the same variables as the SDK, to say what the SDK read; it holds no path, query, header or credential. Call it after Init and InitMetrics.

func (*OtelService) Init

func (s *OtelService) Init(ctx context.Context, cfg *Settings) error

Init creates the OpenTelemetry tracer provider of the service. It does not change any process-wide state: Install does, and is called by the startup wiring only.

func (*OtelService) InitMetrics added in v0.2.0

func (s *OtelService) InitMetrics(ctx context.Context, cfg *Settings) error

InitMetrics creates the OpenTelemetry meter provider of the service and starts the Go runtime metrics on it, when OpenTelemetry is configured (same condition as the tracer provider). The metrics are exported like the traces: the protocol, the endpoint and the headers follow the OTEL_EXPORTER_OTLP_* variables, and OTEL_METRICS_EXPORTER selects the exporter (none disables the export). The export interval is the one of the SDK. It changes no process-wide state: the meter provider is given where it is used (MeterProvider).

func (*OtelService) Install

func (s *OtelService) Install(ctx context.Context, logger *slog.Logger)

Install makes the tracer provider of the service (or a no-op one when Init found OpenTelemetry disabled) the global OpenTelemetry provider, with the error handler and the propagator of the relay proxy. The OpenTelemetry API only offers process-wide registration, so it is the startup wiring (main) that asks for it.

func (*OtelService) MeterProvider added in v0.2.0

func (s *OtelService) MeterProvider() *sdkmetric.MeterProvider

MeterProvider returns the meter provider of the service, nil when OpenTelemetry is not configured or InitMetrics was not called.

func (*OtelService) Providers added in v1.3.0

func (s *OtelService) Providers() tracing.Providers

Providers returns the tracer provider, the meter provider and the propagator of the service as the values that the clients of the relay are built with. The tracer provider is the one that decides: with tracing off the result is the zero value, and no client is instrumented.

func (*OtelService) Stop

func (s *OtelService) Stop(ctx context.Context) error

Stop the OpenTelemetry service. The exporter, the tracer provider and the meter provider are all shut down, whatever the failure of one of them (the metrics are flushed within the deadline of ctx even when the traces fail to stop); the errors are joined.

func (*OtelService) TracerProvider added in v1.3.0

func (s *OtelService) TracerProvider() *sdktrace.TracerProvider

TracerProvider returns the tracer provider of the service, nil when tracing is off.

type Settings added in v0.2.0

type Settings struct {
	// ResourceAttributes are the attributes of the OpenTelemetry resource; they win over OTEL_RESOURCE_ATTRIBUTES key by
	// key, and the keys only the variable has are kept.
	ResourceAttributes map[string]string
	// Version is the version of the relay proxy, reported as the service version.
	Version string
	// OTLPEndpoint is the endpoint set by observability.tracing.otlpEndpoint; empty when the bootstrap file sets none
	// and OTEL_EXPORTER_OTLP_ENDPOINT applies. A value of the bootstrap file wins over the variable.
	OTLPEndpoint string
	// ExporterOTLPEndpoint is the endpoint set by otel.exporter.otlp.endpoint.
	ExporterOTLPEndpoint string
	// ServiceName is the name of the service, empty when the bootstrap file sets none: then OTEL_SERVICE_NAME applies,
	// then service.name of OTEL_RESOURCE_ATTRIBUTES, then semaphore.
	ServiceName string
	// Sampler is the trace sampler of the bootstrap file, empty when it sets none: then OTEL_TRACES_SAMPLER applies, then
	// the SDK default parentbased_always_on.
	Sampler string
	// JaegerSamplerManagerHostPort is the sampling server of the jaeger_remote sampler, empty for the default.
	JaegerSamplerManagerHostPort string
	// JaegerSamplerRefreshInterval is the refresh interval of the jaeger_remote sampler as a duration string.
	JaegerSamplerRefreshInterval string
	// JaegerSamplerMaxOperations is the maximum of operations of the jaeger_remote sampler, 0 for the default.
	JaegerSamplerMaxOperations int
	// SDKDisabled disables OpenTelemetry whatever the endpoint.
	SDKDisabled bool
}

Settings is what the OpenTelemetry service reads of the configuration of the relay proxy. It is built once at startup and not changed afterwards.

Jump to

Keyboard shortcuts

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