Documentation
¶
Overview ¶
Package opentelemetry sets up the OpenTelemetry metrics and tracing of the relay proxy.
Index ¶
- func Enabled(cfg *Settings) bool
- func ExportEnvironment(cfg *Settings)
- type Option
- type OtelService
- func (s *OtelService) Init(ctx context.Context, cfg *Settings) error
- func (s *OtelService) InitMetrics(ctx context.Context, cfg *Settings) error
- func (s *OtelService) Install(ctx context.Context, logger *slog.Logger)
- func (s *OtelService) MeterProvider() *sdkmetric.MeterProvider
- func (s *OtelService) Stop(ctx context.Context) error
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Enabled ¶ added in v0.2.0
Enabled reports whether the configuration enables OpenTelemetry tracing: without an OTLP endpoint there is no exporter, and nothing is traced.
func ExportEnvironment ¶
func ExportEnvironment(cfg *Settings)
ExportEnvironment gives the OTLP endpoint and the sampler of the configuration to the OpenTelemetry SDK, which reads them from OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_TRACES_SAMPLER (a variable that is set wins). It changes the environment of the process, so it belongs to the startup wiring (main): call it once, before Init.
Types ¶
type Option ¶ added in v0.2.0
type Option func(*OtelService)
Option customizes an OtelService.
func WithMetricReader ¶ added in v0.2.0
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.
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) 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) 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.
type Settings ¶ added in v0.2.0
type Settings struct {
// ResourceAttributes are the attributes of the OpenTelemetry resource.
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 the openTelemetryOtlpEndpoint configuration element.
OTLPEndpoint string
// ExporterOTLPEndpoint is the endpoint set by otel.exporter.otlp.endpoint.
ExporterOTLPEndpoint string
// ServiceName is the name of the service, empty for the default.
ServiceName string
// Sampler is the trace sampler (OTEL_TRACES_SAMPLER), empty for always sample.
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.