otel

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package otel wires OpenTelemetry for an Ohm application.

Setup configures a tracer provider with an OTLP exporter, installs the global tracer provider and text-map propagators, and returns a shutdown function for graceful flushing during server shutdown. Ohm's core and application code use the OpenTelemetry API directly; until Setup runs, that API returns a no-op tracer, so instrumentation can be written unconditionally with no overhead.

Exporter selection follows the standard OpenTelemetry environment variables (for example OTEL_TRACES_EXPORTER, OTEL_EXPORTER_OTLP_ENDPOINT, and OTEL_EXPORTER_OTLP_PROTOCOL), so deployments configure their backend without code changes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*config)

Option configures Setup.

func WithEnvironment

func WithEnvironment(name string) Option

WithEnvironment sets the deployment.environment.name resource attribute.

func WithPropagator

func WithPropagator(propagator propagation.TextMapPropagator) Option

WithPropagator overrides the global text-map propagator. The default propagates W3C trace context and baggage.

func WithResourceAttributes

func WithResourceAttributes(attrs ...attribute.KeyValue) Option

WithResourceAttributes appends additional resource attributes.

func WithSampler

func WithSampler(sampler sdktrace.Sampler) Option

WithSampler overrides the tracer provider sampler.

func WithServiceName

func WithServiceName(name string) Option

WithServiceName sets the service.name resource attribute.

func WithServiceVersion

func WithServiceVersion(version string) Option

WithServiceVersion sets the service.version resource attribute.

type Shutdown

type Shutdown func(context.Context) error

Shutdown flushes and releases telemetry resources. It should be called during graceful server shutdown so buffered spans are exported before exit.

func Setup

func Setup(ctx context.Context, opts ...Option) (Shutdown, error)

Setup installs OpenTelemetry for the process and returns a shutdown function.

Setup is opt-in: applications that never call it keep the no-op tracer and pay no telemetry cost. The returned Shutdown is safe to call once; calling it more than once returns the result of the first call's underlying providers.

Jump to

Keyboard shortcuts

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