providers

package
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package providers composes OpenTelemetry tracer and meter providers from a declarative Config, with OTLP HTTP and Prometheus exporters.

NewCompositeProvider builds the tracer/meter pair for a service in one call: OTLP tracing and/or metrics when an endpoint is configured, a Prometheus scrape endpoint when enabled, or no-ops when neither is. The strategy selector in providers_strategy.go decides which exporters to wire based on the Config, so callers get a single composite to hand to their instrumentation and a single Shutdown to call on exit.

This package is Alpha stability. The API may change significantly before reaching stable status in v1.0.0.

Package providers contains telemetry provider implementations and builder logic

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompositeProvider

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

CompositeProvider combines telemetry providers into a single interface. It manages tracer providers, meter providers, Prometheus handlers, and cleanup.

func NewCompositeProvider

func NewCompositeProvider(
	ctx context.Context,
	options ...ProviderOption,
) (*CompositeProvider, error)

NewCompositeProvider creates the appropriate providers based on provided options

func (*CompositeProvider) MeterProvider

func (p *CompositeProvider) MeterProvider() metric.MeterProvider

MeterProvider returns the primary meter provider

func (*CompositeProvider) PrometheusHandler

func (p *CompositeProvider) PrometheusHandler() http.Handler

PrometheusHandler returns the Prometheus metrics handler if configured

func (*CompositeProvider) Shutdown

func (p *CompositeProvider) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down all providers

func (*CompositeProvider) TracerProvider

func (p *CompositeProvider) TracerProvider() trace.TracerProvider

TracerProvider returns the tracer provider

type Config

type Config struct {
	// Service information
	ServiceName    string // ServiceName identifies the service for telemetry data
	ServiceVersion string // ServiceVersion identifies the service version for telemetry data

	// OTLP configuration
	OTLPEndpoint   string            // OTLPEndpoint is the OTLP collector endpoint (e.g., "localhost:4318")
	Headers        map[string]string // Headers are additional headers to send with OTLP requests
	Insecure       bool              // Insecure enables insecure transport (no TLS) for OTLP
	TracingEnabled bool              // TracingEnabled controls whether tracing is enabled for OTLP
	MetricsEnabled bool              // MetricsEnabled controls whether metrics are enabled for OTLP
	SamplingRate   float64           // SamplingRate controls trace sampling (0.0 to 1.0)

	// Prometheus configuration
	EnablePrometheusMetricsPath bool // EnablePrometheusMetricsPath enables Prometheus /metrics endpoint

	// TLS configuration
	CACertPath string // CACertPath is the file path to a custom CA certificate bundle for the OTLP endpoint

	// Custom attributes
	// CustomAttributes are additional resource attributes to include (as map for JSON serialization)
	CustomAttributes map[string]string

	// ExtraSpanProcessors contains additional OTEL span processors to register alongside the
	// default OTLP exporter (e.g. a Sentry bridge processor for dual export).
	ExtraSpanProcessors []sdktrace.SpanProcessor
}

Config holds the telemetry configuration for all providers. It contains service information, OTLP settings, and Prometheus configuration.

type MeterResult

type MeterResult struct {
	MeterProvider     metric.MeterProvider
	PrometheusHandler http.Handler
	ShutdownFunc      func(context.Context) error
}

MeterResult contains the result of creating a meter provider

type MeterStrategy

type MeterStrategy interface {
	CreateMeterProvider(ctx context.Context, config Config, res *resource.Resource) (*MeterResult, error)
}

MeterStrategy defines the interface for creating meter providers

type NoOpMeterStrategy

type NoOpMeterStrategy struct{}

NoOpMeterStrategy creates a no-op meter provider that discards all metric data. It's used when both OTLP and Prometheus metrics are disabled.

func (*NoOpMeterStrategy) CreateMeterProvider

func (*NoOpMeterStrategy) CreateMeterProvider(
	_ context.Context,
	_ Config,
	_ *resource.Resource,
) (*MeterResult, error)

CreateMeterProvider creates a no-op meter provider

type NoOpTracerStrategy

type NoOpTracerStrategy struct{}

NoOpTracerStrategy creates a no-op tracer provider that discards all trace data. It's used when tracing is disabled or no OTLP endpoint is configured.

func (*NoOpTracerStrategy) CreateTracerProvider

func (*NoOpTracerStrategy) CreateTracerProvider(
	_ context.Context,
	_ Config,
	_ *resource.Resource,
) (trace.TracerProvider, func(context.Context) error, error)

CreateTracerProvider creates a no-op tracer provider

type OTLPTracerStrategy

type OTLPTracerStrategy struct{}

OTLPTracerStrategy creates an OTLP tracer provider that sends traces to an OTLP collector. It supports sampling configuration, custom headers, and secure/insecure transport.

func (*OTLPTracerStrategy) CreateTracerProvider

func (*OTLPTracerStrategy) CreateTracerProvider(
	ctx context.Context,
	config Config,
	res *resource.Resource,
) (trace.TracerProvider, func(context.Context) error, error)

CreateTracerProvider creates an OTLP tracer provider with the configured endpoint and sampling rate

type ProviderOption

type ProviderOption func(*Config) error

ProviderOption is an option type used to configure the telemetry providers

func WithCACertPath

func WithCACertPath(path string) ProviderOption

WithCACertPath sets the CA certificate path for the OTLP endpoint

func WithCustomAttributes

func WithCustomAttributes(attributes map[string]string) ProviderOption

WithCustomAttributes sets the custom resource attributes

func WithEnablePrometheusMetricsPath

func WithEnablePrometheusMetricsPath(enablePrometheusMetricsPath bool) ProviderOption

WithEnablePrometheusMetricsPath sets the enable prometheus metrics path flag

func WithExtraSpanProcessors

func WithExtraSpanProcessors(processors ...sdktrace.SpanProcessor) ProviderOption

WithExtraSpanProcessors appends additional OTEL span processors (e.g. a Sentry bridge).

func WithHeaders

func WithHeaders(headers map[string]string) ProviderOption

WithHeaders sets the headers

func WithInsecure

func WithInsecure(insecure bool) ProviderOption

WithInsecure sets the insecure flag

func WithMetricsEnabled

func WithMetricsEnabled(metricsEnabled bool) ProviderOption

WithMetricsEnabled sets the metrics enabled flag

func WithOTLPEndpoint

func WithOTLPEndpoint(endpoint string) ProviderOption

WithOTLPEndpoint sets the OTLP endpoint

func WithSamplingRate

func WithSamplingRate(samplingRate float64) ProviderOption

WithSamplingRate sets the sampling rate

func WithServiceName

func WithServiceName(serviceName string) ProviderOption

WithServiceName sets the service name

func WithServiceVersion

func WithServiceVersion(serviceVersion string) ProviderOption

WithServiceVersion sets the service version

func WithTracingEnabled

func WithTracingEnabled(tracingEnabled bool) ProviderOption

WithTracingEnabled sets the tracing enabled flag

type StrategySelector

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

StrategySelector determines which strategies to use based on configuration. It analyzes the configuration to select appropriate tracer and meter strategies.

func NewStrategySelector

func NewStrategySelector(config Config) *StrategySelector

NewStrategySelector creates a new strategy selector with the given configuration. The selector will analyze the config to determine appropriate strategies.

func (*StrategySelector) IsFullyNoOp

func (s *StrategySelector) IsFullyNoOp() bool

IsFullyNoOp returns true if both tracer and meter would be no-op.

func (*StrategySelector) SelectMeterStrategy

func (s *StrategySelector) SelectMeterStrategy() MeterStrategy

SelectMeterStrategy determines the appropriate meter strategy based on configuration.

func (*StrategySelector) SelectTracerStrategy

func (s *StrategySelector) SelectTracerStrategy() TracerStrategy

SelectTracerStrategy determines the appropriate tracer strategy based on configuration.

type TracerStrategy

type TracerStrategy interface {
	// CreateTracerProvider creates a tracer provider with optional shutdown function
	CreateTracerProvider(ctx context.Context, config Config, res *resource.Resource) (
		trace.TracerProvider, func(context.Context) error, error)
}

TracerStrategy defines the interface for creating tracer providers. Implementations create trace providers based on configuration and resource information.

type UnifiedMeterStrategy

type UnifiedMeterStrategy struct {
	EnableOTLP       bool // EnableOTLP controls whether to add an OTLP metrics reader
	EnablePrometheus bool // EnablePrometheus controls whether to add a Prometheus reader
}

UnifiedMeterStrategy creates a meter provider with multiple readers (OTLP and/or Prometheus). It can combine OTLP metrics export and Prometheus scraping in a single provider.

func (*UnifiedMeterStrategy) CreateMeterProvider

func (s *UnifiedMeterStrategy) CreateMeterProvider(
	ctx context.Context,
	config Config,
	res *resource.Resource,
) (*MeterResult, error)

CreateMeterProvider creates a unified meter provider with OTLP and/or Prometheus readers

Directories

Path Synopsis
Package otlp provides OpenTelemetry Protocol (OTLP) provider implementations
Package otlp provides OpenTelemetry Protocol (OTLP) provider implementations
Package prometheus provides Prometheus metric exporter implementation
Package prometheus provides Prometheus metric exporter implementation

Jump to

Keyboard shortcuts

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