otelconfig

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: Apache-2.0 Imports: 17 Imported by: 23

Documentation

Index

Constants

View Source
const (
	// GRPC default port.
	GRPCDefaultPort = "4317"
	// HTTP default port.
	HTTPDefaultPort = "4318"
	// SSL/TLS default port.
	SSLDefaultPort = "443"
)

These are strings because they get appended to the host.

Variables

View Source
var (
	// SetVendorOptions provides a way for a vendor to add a set of Options that are automatically applied.
	SetVendorOptions func() []Option
	// ValidateConfig is a function that a vendor can implement to provide additional validation after
	// a configuration is built.
	ValidateConfig func(*Config) error
	// DefaultExporterEndpoint provides a way for vendors to update the default exporter endpoint address.
	// Defaults to 'localhost'.
	DefaultExporterEndpoint string = "localhost"
)

Functions

func ConfigureOpenTelemetry

func ConfigureOpenTelemetry(opts ...Option) (func(), error)

ConfigureOpenTelemetry is a function that be called with zero or more options. Options can be the basic ones above, or provided by individual vendors.

Types

type Config

type Config struct {
	ExporterEndpoint                string            `env:"OTEL_EXPORTER_OTLP_ENDPOINT,overwrite"`
	ExporterEndpointInsecure        bool              `env:"OTEL_EXPORTER_OTLP_INSECURE,default=false"`
	TracesExporterEndpoint          string            `env:"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,overwrite"`
	TracesExporterEndpointInsecure  bool              `env:"OTEL_EXPORTER_OTLP_TRACES_INSECURE"`
	TracesEnabled                   *bool             `env:"OTEL_TRACES_ENABLED,default=true"`
	ServiceName                     string            `env:"OTEL_SERVICE_NAME,overwrite"`
	ServiceVersion                  string            `env:"OTEL_SERVICE_VERSION,overwrite,default=unknown"`
	MetricsExporterEndpoint         string            `env:"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,overwrite"`
	MetricsExporterEndpointInsecure bool              `env:"OTEL_EXPORTER_OTLP_METRICS_INSECURE"`
	MetricsEnabled                  *bool             `env:"OTEL_METRICS_ENABLED,default=true"`
	MetricsReportingPeriod          string            `env:"OTEL_EXPORTER_OTLP_METRICS_PERIOD,overwrite,default=30s"`
	LogLevel                        string            `env:"OTEL_LOG_LEVEL,overwrite,default=info"`
	Propagators                     []string          `env:"OTEL_PROPAGATORS,overwrite,default=tracecontext,baggage"`
	ExporterProtocol                Protocol          `env:"OTEL_EXPORTER_OTLP_PROTOCOL,overwrite,default=grpc"`
	TracesExporterProtocol          Protocol          `env:"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL,overwrite"`
	MetricsExporterProtocol         Protocol          `env:"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL,overwrite"`
	Headers                         map[string]string `env:"OTEL_EXPORTER_OTLP_HEADERS,overwrite,separator=="`
	TracesHeaders                   map[string]string `env:"OTEL_EXPORTER_OTLP_TRACES_HEADERS,overwrite,separator=="`
	MetricsHeaders                  map[string]string `env:"OTEL_EXPORTER_OTLP_METRICS_HEADERS,overwrite,separator=="`
	ResourceAttributes              map[string]string `env:"OTEL_RESOURCE_ATTRIBUTES,overwrite,separator=="`
	SpanProcessors                  []trace.SpanProcessor
	Sampler                         trace.Sampler
	ResourceOptions                 []resource.Option
	Resource                        *resource.Resource
	Logger                          Logger                  `json:"-"`
	ShutdownFunctions               []func(c *Config) error `json:"-"`
	// contains filtered or unexported fields
}

Config is a configuration object; it is public so that it can be manipulated by vendors. Note that ExporterEndpoint specifies "DEFAULTPORT"; this is because the default port should vary depending on the protocol chosen. If not overridden by explicit configuration, it will be overridden with an appropriate default upon initialization.

type Logger

type Logger interface {
	Fatalf(format string, v ...interface{})
	Debugf(format string, v ...interface{})
}

Logger is an interface for a logger that can be passed to WithLogger.

type Option

type Option func(*Config)

Option is the type of an Option to the ConfigureOpenTelemetry function; it's a function that accepts a config and modifies it.

func WithErrorHandler

func WithErrorHandler(handler otel.ErrorHandler) Option

Configures a global error handler to be used throughout an OpenTelemetry instrumented project. See "go.opentelemetry.io/otel".

func WithExporterEndpoint

func WithExporterEndpoint(url string) Option

WithExporterEndpoint configures the generic endpoint used for sending all telemtry signals via OTLP.

func WithExporterInsecure

func WithExporterInsecure(insecure bool) Option

WithExporterInsecure permits connecting to the generic exporter endpoint without a certificate.

func WithExporterProtocol

func WithExporterProtocol(protocol Protocol) Option

WithExporterProtocol defines the default protocol.

func WithHeaders

func WithHeaders(headers map[string]string) Option

WithHeaders configures OTLP exporter headers.

func WithLogLevel

func WithLogLevel(loglevel string) Option

WithLogLevel configures the logging level for OpenTelemetry.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger sets up the logger to be used.

func WithMetricsEnabled

func WithMetricsEnabled(enabled bool) Option

WithMetricsEnabled configures whether metrics should be enabled.

func WithMetricsExporterEndpoint

func WithMetricsExporterEndpoint(url string) Option

WithMetricsExporterEndpoint configures the endpoint for sending metrics via OTLP.

func WithMetricsExporterInsecure

func WithMetricsExporterInsecure(insecure bool) Option

WithMetricsExporterInsecure permits connecting to the metric endpoint without a certificate.

func WithMetricsExporterProtocol

func WithMetricsExporterProtocol(protocol Protocol) Option

WithMetricsExporterProtocol defines the protocol for Metrics.

func WithMetricsHeaders

func WithMetricsHeaders(headers map[string]string) Option

WithMetricsHeaders configures OTLP metrics exporter headers.

func WithMetricsReportingPeriod

func WithMetricsReportingPeriod(p time.Duration) Option

WithMetricsReportingPeriod configures the metric reporting period, how often the controller collects and exports metric data.

func WithPropagators

func WithPropagators(propagators []string) Option

WithPropagators configures propagators.

func WithResourceAttributes

func WithResourceAttributes(attributes map[string]string) Option

WithResourceAttributes configures attributes on the resource; if the resource already exists, it sets additional attributes or overwrites those already there.

func WithResourceOption added in v1.11.0

func WithResourceOption(option resource.Option) Option

WithResourceOption configures options on the resource; These are appended after the default options and can override them.

func WithSampler

func WithSampler(sampler trace.Sampler) Option

WithSampler configures the Sampler to use when processing trace spans.

func WithServiceName

func WithServiceName(name string) Option

WithServiceName configures a "service.name" resource label.

func WithServiceVersion

func WithServiceVersion(version string) Option

WithServiceVersion configures a "service.version" resource label.

func WithShutdown

func WithShutdown(f func(c *Config) error) Option

WithShutdown adds functions that will be called first when the shutdown function is called. They are given a copy of the Config object (which has access to the Logger), and should return an error only in extreme circumstances, as an error return here is immediately fatal.

func WithSpanProcessor

func WithSpanProcessor(sp ...trace.SpanProcessor) Option

WithSpanProcessor adds one or more SpanProcessors.

func WithTracesEnabled

func WithTracesEnabled(enabled bool) Option

WithTracesEnabled configures whether traces should be enabled.

func WithTracesExporterEndpoint

func WithTracesExporterEndpoint(url string) Option

WithTracesExporterEndpoint configures the endpoint for sending traces via OTLP.

func WithTracesExporterInsecure

func WithTracesExporterInsecure(insecure bool) Option

WithTracesExporterInsecure permits connecting to the trace endpoint without a certificate.

func WithTracesExporterProtocol

func WithTracesExporterProtocol(protocol Protocol) Option

WithTracesExporterProtocol defines the protocol for Traces.

func WithTracesHeaders

func WithTracesHeaders(headers map[string]string) Option

WithTracesHeaders configures OTLP traces exporter headers.

type OtelConfig

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

OtelConfig is the object we're here for; it implements the initialization of Open Telemetry.

func (OtelConfig) Shutdown

func (ls OtelConfig) Shutdown()

Shutdown is the function called to shut down OpenTelemetry. It invokes any registered shutdown functions.

type Protocol

type Protocol pipelines.Protocol

Protocol defines the possible values of the protocol field.

Import the values for Protocol from pipelines but make them available without importing pipelines.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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