Documentation
¶
Overview ¶
Package otelx provides OpenTelemetry tracing and metrics setup and utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Enabled controls whether tracing is enabled.
Enabled bool `mapstructure:"enabled"`
// ServiceName is the name of the service for tracing.
ServiceName string `mapstructure:"service_name"`
// ServiceVersion is the version of the service.
ServiceVersion string `mapstructure:"service_version"`
// Environment is the deployment environment (development, staging, production).
Environment string `mapstructure:"environment"`
// Exporter specifies the exporter type: "otlp", "stdout", or "noop".
Exporter string `mapstructure:"exporter"`
// OTLP contains OTLP exporter configuration.
OTLP OTLPConfig `mapstructure:"otlp"`
// SampleRate is the sampling rate (0.0 to 1.0). 1.0 means sample all traces.
SampleRate float64 `mapstructure:"sample_rate"`
}
Config holds OpenTelemetry configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a default configuration for development.
type OTLPConfig ¶
type OTLPConfig struct {
// Endpoint is the OTLP collector endpoint (e.g., "localhost:4318").
Endpoint string `mapstructure:"endpoint"`
// Insecure disables TLS for the connection.
Insecure bool `mapstructure:"insecure"`
// Protocol is the transport protocol: "http" or "grpc".
Protocol string `mapstructure:"protocol"`
}
OTLPConfig holds OTLP exporter configuration.
type Provider ¶ added in v1.11.0
type Provider struct {
// contains filtered or unexported fields
}
Provider wraps the OpenTelemetry tracer, meter, and logger providers with shutdown capability.
func Setup ¶
Setup initializes OpenTelemetry tracing and metrics based on the provided configuration. Returns a Provider that should be shut down when the application exits.
func (*Provider) SlogHandler ¶ added in v1.12.0
SlogHandler returns an slog.Handler that sends logs via OTel. Use this to create a fan-out handler alongside the existing stdout handler.
Click to show internal directories.
Click to hide internal directories.