telemetry

package
v1.9.6 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(ctx context.Context, options ...Options) (shutdown func(context.Context) error, err error)

Init initialises the global OTEL trace and metric providers and returns a shutdown function that flushes and closes them. Call the shutdown function before your process exits to ensure all pending telemetry is exported.

When Enabled is false (the default unless OTEL_ENABLED=true), a no-op shutdown function is returned immediately.

Usage — rely entirely on environment variables:

shutdown, err := telemetry.Init(ctx)

Usage — override specific fields in code:

shutdown, err := telemetry.Init(ctx, telemetry.Options{ServiceName: "my-service"})

func TraceFields added in v1.9.2

func TraceFields(ctx context.Context, fields map[string]any) map[string]any

TraceFields merges the active trace_id and span_id from ctx into a copy of fields so that structured log entries can be correlated with APM traces. Returns fields unchanged when ctx holds no valid span (e.g. telemetry disabled).

Usage:

log.InfoFields("webhook delivered", telemetry.TraceFields(ctx, map[string]any{
    "url":    job.URL,
    "tenant": job.Tenant,
}))

Types

type Options

type Options struct {
	// Enabled controls whether telemetry is initialised. Maps to OTEL_ENABLED.
	Enabled bool
	// Host is the OTEL collector hostname. Maps to OTEL_HOST.
	Host string
	// Port is the OTEL collector port. Maps to OTEL_PORT.
	Port string
	// ServiceName is reported as the service.name resource attribute. Maps to OTEL_SERVICE_NAME.
	ServiceName string
	// Environment is reported as the deployment.environment attribute. Maps to ENVIRONMENT.
	Environment string
	// Protocol selects the export transport: "grpc" (port 4317) or "http" (port 4318).
	// Maps to OTEL_PROTOCOL.
	Protocol string
	// Insecure disables TLS on the collector connection. Maps to OTEL_INSECURE.
	Insecure bool
	// MetricInterval controls how often metrics are pushed to the collector.
	// Defaults to 30 seconds.
	MetricInterval time.Duration
}

Options configures the OTEL telemetry providers. All fields are optional — zero values are filled from environment variables (see getOptions).

Jump to

Keyboard shortcuts

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