otel

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: MIT Imports: 22 Imported by: 0

README

otel - open telemetry

This library is a basic wrapper for common usages of the OTel SDK. The code found herein is derived from https://opentelemetry.io/docs/languages/go/getting-started/.

NOTE: the documentation specifies that the SDK API isn't completely stable, so there may be times when any consumer of it must update their code. This library may fall behind and stop working until we notice and fix it.

direct usage

The otel/examples/ directory shows how to use the direct Setup* functions, along with the required cleanup function calls. If you want to make your functions available globally, refer to the link above for the functions to publish the

abstracted

We use the libraries by attaching them to the context, scoping them to the current process in a concurrent application. We have published these in named packages under the otel/context/ directory.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConfigurationRequired = errors.New("configuration not provided")

Functions

func SetupLogging

func SetupLogging(
	ctx context.Context,
	configuration *LoggerConfiguration,
	shutdownFunc *ShutdownFuncs,
	res *resource.Resource,
) (*log.LoggerProvider, error)

func SetupMetrics

func SetupMetrics(
	ctx context.Context,
	configuration *MeterConfiguration,
	shutdownFuncs *ShutdownFuncs,
	res *resource.Resource,
) (*metric.MeterProvider, error)

func SetupOTelSDK

func SetupOTelSDK(
	ctx context.Context,
	loggerOptions *LoggerConfiguration,
	meterOptions *MeterConfiguration,
	tracerOptions *TracerConfiguration,
	serviceName string,
) (context.Context, func(context.Context) error, error)

setupOTelSDK bootstraps the OpenTelemetry pipeline. If it does not return an error, make sure to call shutdown for proper cleanup.

func SetupTracing

func SetupTracing(
	ctx context.Context,
	configuration *TracerConfiguration,
	shutdownFuncs *ShutdownFuncs,
	res *resource.Resource,
) (*trace.TracerProvider, error)

Types

type LoggerConfiguration

type LoggerConfiguration struct {
	Method LoggingMethod
	Stdout []stdoutlog.Option
	Grpc   []otlploggrpc.Option
	Http   []otlploghttp.Option
}

type LoggingMethod

type LoggingMethod uint8
const (
	LoggingMethodStdout LoggingMethod = iota
	LoggingMethodGRPC
	LoggingMethodHTTP
)

type MeterConfiguration

type MeterConfiguration struct {
	Method     MetricMethod
	Stdout     []stdoutmetric.Option
	Grpc       []otlpmetricgrpc.Option
	Http       []otlpmetrichttp.Option
	BatchTimer time.Duration
}

type MetricMethod

type MetricMethod uint8
const (
	MetricMethodStdout MetricMethod = iota
	MetricMethodGRPC
	MetricMethodHTTP
)

type ShutdownFuncs

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

ShutdownFuncs consolidates closures from the reference code to enable refactoring the code for clarity.

func (*ShutdownFuncs) Shutdown

func (sdf *ShutdownFuncs) Shutdown(ctx context.Context) error

Shutdown calls cleanup functions registered via shutdownFuncs. The errors from the calls are joined. Each registered cleanup will be invoked once.

type TracerConfiguration

type TracerConfiguration struct {
	Method     TracingMethod
	Stdout     []stdouttrace.Option
	Grpc       []otlptracegrpc.Option
	Http       []otlptracehttp.Option
	BatchTimer time.Duration // the delay between batch posts. default is 5s
}

type TracingMethod

type TracingMethod uint8
const (
	TracingMethodStdout TracingMethod = iota
	TracingMethodGRPC
	TracingMethodHTTP
)

Directories

Path Synopsis
context
examples
log command
meter command
trace command

Jump to

Keyboard shortcuts

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