otelx

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 20 Imported by: 10

Documentation

Overview

Package otelx provides configuration helpers for configuring otel tracing

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownExporter is returned when the exporter passed in via the config
	// is not a known TraceExporter type.
	ErrUnknownExporter = errors.New("unknown tracing exporter")
)

Functions

func InitTracer

func InitTracer(tc Config, appName string, _ *zap.SugaredLogger) error

InitTracer will configure the exporter setup in the provided config and create an otel TracerProvider. The new TracerProvider will be set as the global trace provider.

func MustViperFlags

func MustViperFlags(v *viper.Viper, flags *pflag.FlagSet)

MustViperFlags returns the cobra flags and viper config to prevent code duplication and help provide consistent flags across the applications

Types

type Config

type Config struct {
	Enabled     bool          `mapstructure:"enabled"`
	Provider    TraceExporter `mapstructure:"provider"`
	Environment string        `mapstructure:"environment"`
	Random      string        `mapstructure:"random"`
	Stdout      struct {
		PrettyPrint       bool `mapstructure:"pretty_print"`
		DisableTimestamps bool `mapstructure:"disable_timestamps"`
	}
	Jaeger struct {
		AgentHost string `mapstructure:"agent_host"`
		AgentPort string `mapstructure:"agent_port"`
		Endpoint  string `mapstructure:"endpoint"`
		User      string `mapstructure:"user"`
		Password  string `mapstructure:"password"`
	}
	OTLP struct {
		Endpoint    string        `mapstructure:"endpoint"`
		Insecure    bool          `mapstructure:"insecure"`
		Certificate string        `mapstructure:"certificate"`
		Headers     []string      `mapstructure:"headers"`
		Compression string        `mapstructure:"compression"`
		Timeout     time.Duration `mapstructure:"timeout"`
	}
}

Config provides a struct for reading in all the config values available from viper. If you are not using viper it is still able to be configured manually and passed in.

type ConfigError

type ConfigError struct {
	Message string
	Err     error
}

ConfigError is returned when there is a problem with the provided TracingConfig during configuration.

func (*ConfigError) Error

func (c *ConfigError) Error() string

type TraceExporter

type TraceExporter string

TraceExporter provides a string representation of the tracing exporters that are supported. For example to print to stdout you would use ExporterStdout which is the same as using "stdout" as a CLI flag.

const (
	// ExporterStdout is for a stdout exporter.
	//  Settings for stdout:
	//      tracing.stdout.pretty_print          TRACING_STDOUT_PRETTY_PRINT            enable pretty printing the trace output
	//      tracing.stdout.disable_timestamps    TRACING_STDOUT_DISABLE_TIMESTAMPS      disable timestamps in the trace output
	ExporterStdout TraceExporter = "stdout"

	// ExporterJaeger is for a jaeger exporter capable of connecting to a trace api
	// endpoint as well as using the jaeger agent. You MUST specific either an
	// endpoint or an agent host and port. When connecting with an endpoint you
	// may optionally provide a user and password.
	//
	//  Settings for agent connections:
	//      tracing.jaeger.agent_host    TRACING_JAEGER_AGENT_HOST        host for jaeger agent connection
	//      tracing.jaeger.agent_port    TRACING_JAEGER_AGENT_PORT        port for jaeger agent connection
	//  Settings for endpoint connections:
	//      tracing.jaeger.endpoint      TRACING_JAEGER_AGENT_ENDPOINT    url for jaeger endpoint
	//      tracing.jaeger.user          TRACING_JAEGER_AGENT_USER        user for jaeger endpoint
	//      tracing.jaeger.password      TRACING_JAEGER_AGENT_PASSWORD    password for jaeger endpoint
	ExporterJaeger TraceExporter = "jaeger"

	// ExporterOTLPHTTP is for a OTLP exporter capable of connecting over secure or
	// insecure HTTP.
	//
	//      tracing.otlp.endpoint        TRACING_OTLP_ENDPOINT        url for otlp http endpoint
	//      tracing.otlp.insecure        TRACING_OTLP_INSECURE        use an insecure connection to the endpoint
	//      tracing.otlp.timeout         TRACING_OTLP_TIMEOUT         timeout for sending to the endpoint (defaults to 10s)
	ExporterOTLPHTTP TraceExporter = "otlphttp"

	// ExporterOTLPGRPC is for a OTLP exporter capable of connecting over secure or
	// insecure GRPC.
	//
	//      tracing.otlp.endpoint        TRACING_OTLP_ENDPOINT        url for otlp http endpoint
	//      tracing.otlp.insecure        TRACING_OTLP_INSECURE        use an insecure connection to the endpoint
	//      tracing.otlp.timeout         TRACING_OTLP_TIMEOUT         timeout for sending to the endpoint (defaults to 10s)
	ExporterOTLPGRPC TraceExporter = "otlpgrpc"

	// ExporterPassthrough is to configure tracing as a passthrough service. This
	// will setup a tracer and read incoming parent trace info from request and
	// pass parent trace info to downstream services, but will not export any spans
	// or other trace data from the application directly.
	ExporterPassthrough TraceExporter = "passthrough"
)

Jump to

Keyboard shortcuts

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