providerconfig

package module
v0.0.0-...-17b3083 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 17 Imported by: 2

README

Features

  • add core,grpc and http modules so the user does not need to import everything

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShutDownPair

func ShutDownPair(name SignalHookName, fn ShutdownHook) func() (SignalHookName, ShutdownHook)

Types

type Execution

type Execution uint8
const (
	Sync Execution = iota + 1
	Async
)

func (Execution) IsValid

func (e Execution) IsValid() bool

func (Execution) String

func (e Execution) String() string

type Option

type Option func(*config)

func WithApplicationName

func WithApplicationName(applicationName string) Option
Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"
)

func main() {
	providerconfig.New(
		providerconfig.WithApplicationName("example-app"),
	)
}
Output:

func WithApplicationVersion

func WithApplicationVersion(applicationVersion string) Option
Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"
)

func main() {
	providerconfig.New(
		providerconfig.WithApplicationVersion("1.0.0"),
	)
}
Output:

func WithDisabledSignals

func WithDisabledSignals(disableTraces, disableMetrics, disableLogs bool) Option
Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"
)

func main() {
	providerconfig.New(
		providerconfig.WithDisabledSignals(
			false, // traces
			true,  // metrics
			true,  // logs
		),
	)
}
Output:

func WithExecutionType

func WithExecutionType(executionType Execution) Option
Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"
)

func main() {
	providerconfig.New(
		providerconfig.WithExecutionType(providerconfig.Async),
	)
}
Output:

func WithInitLogs

func WithInitLogs() Option

WithInitLogs sets the global log provider.

If this function is not used, the user has to set the global provider or use it directly. Can be globally set using the following code:

global.SetLoggerProvider(otelConfig.LogProvider())

func WithInitMetrics

func WithInitMetrics() Option

WithInitMetrics sets the global metric provider.

If this function is not used, the user has to set the global provider or use it directly. Can be globally set using the following code:

otel.SetMeterProvider(otelConfig.MetricProvider())

func WithInitSignals

func WithInitSignals() Option

WithInitSignals sets all three observability signals by calling their setter functions.

The setter functions would normally have to be set manually using the following lines of code:

 // traces
	otel.SetTracerProvider(otelConfig.TraceProvider())

	// metrics
	otel.SetMeterProvider(otelConfig.MetricProvider())

	// logs
	global.SetLoggerProvider(otelConfig.LogProvider())

With this Option these will be preformed for the user

func WithInitTraces

func WithInitTraces() Option

WithInitTraces sets the global trace provider.

If this function is not used, the user has to set the global provider or use it directly. Can be globally set using the following code:

otel.SetTracerProvider(otelConfig.TraceProvider())

func WithLogProviderOptions

func WithLogProviderOptions(options ...sdklog.LoggerProviderOption) Option
Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"

	sdklog "go.opentelemetry.io/otel/sdk/log"
)

func main() {
	providerconfig.New(
		providerconfig.WithLogProviderOptions(sdklog.WithAttributeCountLimit(15)),
	)
}
Output:

func WithMetricProviderOptions

func WithMetricProviderOptions(options ...sdkmetric.Option) Option
Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"

	sdkmetric "go.opentelemetry.io/otel/sdk/metric"
)

func main() {
	providerconfig.New(
		providerconfig.WithMetricProviderOptions(sdkmetric.WithReader(sdkmetric.NewManualReader())),
	)
}
Output:

func WithPrometheusBridge

func WithPrometheusBridge() Option

WithPrometheusBridge enables the Prometheus bridge in the configuration. The Prometheus bridge allows exporting metrics from the Prometheus instrumentation and forward them over OTLP to an endpoint. If the bridge is not enabled, prometheus metrics will not be exported over OTLP.

The Prometheus bridge is disabled by default.

func WithResourceOptions

func WithResourceOptions(resourceOptions ...resource.Option) Option
Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"
	"go.opentelemetry.io/otel/sdk/resource"
)

func main() {
	providerconfig.New(
		providerconfig.WithResourceOptions(resource.WithContainer(),
			resource.WithHost(),
		),
	)
}
Output:

func WithSignalProcessor

func WithSignalProcessor(signalProcessor SignalProcessor) Option

WithSignalProcessor expects an implementation of the SignalProcessor interface. There are two implementations provided by this library as separate modules to reduce the number of imported dependencies. This limits to what's actually used by the end user.

The implementations can be found in the packages:

  • github.com/vincentfree/opentelemetry/providerconfiggrpc
  • github.com/vincentfree/opentelemetry/providerconfighttp

Both packages contain a new function with their respective options.

Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"
	"github.com/vincentfree/opentelemetry/providerconfig/providerconfignoop"
)

func main() {
	providerconfig.New(
		// Example processor, in a real scenario, the http or grpc processors should be used.
		// Either is a separate import that needs to be added to the modules
		providerconfig.WithSignalProcessor(providerconfignoop.NewNoopProcessor()),
	)
}
Output:

func WithTracePropagator

func WithTracePropagator(propagator propagation.TextMapPropagator) Option

WithTracePropagator overwrites the default trace propagators set by the library. The trace propagator(s) are used to propagate trace context across distributed systems. The trace context object and other metadata can be injected and extracted based on this configuration.

If this function is not used, the defaults will be set. Default propagators are: propagation.TraceContext and propagation.Baggage

Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"
	"go.opentelemetry.io/otel/propagation"
)

func main() {
	providerconfig.New(
		providerconfig.WithTracePropagator(
			propagation.NewCompositeTextMapPropagator(
				propagation.TraceContext{},
				propagation.Baggage{},
			),
		),
	)
}
Output:

func WithTraceProviderOptions

func WithTraceProviderOptions(options ...sdktrace.TracerProviderOption) Option
Example
package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"

	sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

func main() {
	providerconfig.New(
		providerconfig.WithTraceProviderOptions(sdktrace.WithSampler(sdktrace.AlwaysSample())),
	)
}
Output:

type Options

type Options []Option

type Provider

type Provider interface {
	TraceProvider() trace.TracerProvider
	MetricProvider() metric.MeterProvider
	LogProvider() log.LoggerProvider
	ShutdownAll()
	ShutdownByType(signalHookName SignalHookName) bool
}

func New

func New(options ...Option) Provider

New initializes an OTLP exporter, and configures the corresponding trace, log and metric providers.

Although the function does not specify required Options, WithApplicationName and WithApplicationVersion are required.

Next to Application information, WithSignalProcessor is also required. There are two external modules that provide implementations, one fork gRPC and one for HTTP.

The implementations can be found in these packages:

  • github.com/vincentfree/opentelemetry/providerconfiggrpc
  • github.com/vincentfree/opentelemetry/providerconfighttp
Example

initializing through main and manually setting the providers.

providers can also be set directly through providerconfig.Option's like: providerconfig.WithInitTraces() providerconfig.WithInitMetrics() providerconfig.WithInitLogs()

package main

import (
	"github.com/vincentfree/opentelemetry/providerconfig"
	"github.com/vincentfree/opentelemetry/providerconfig/providerconfignoop"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/log/global"
)

func main() {
	provider := providerconfig.New(
		providerconfig.WithApplicationName("example-app"),
		providerconfig.WithApplicationVersion("0.1.0"),
		providerconfig.WithExecutionType(providerconfig.Async),
		providerconfig.WithSignalProcessor(providerconfignoop.NewNoopProcessor()),
	)

	// traces
	otel.SetTracerProvider(provider.TraceProvider())

	// metrics
	otel.SetMeterProvider(provider.MetricProvider())

	// logs
	global.SetLoggerProvider(provider.LogProvider())
}
Output:

type ShutdownHook

type ShutdownHook func()

type ShutdownHooks

type ShutdownHooks map[SignalHookName]ShutdownHook

func NewShutdownHooks

func NewShutdownHooks(fns ...func() (SignalHookName, ShutdownHook)) ShutdownHooks

func (ShutdownHooks) ShutdownAll

func (h ShutdownHooks) ShutdownAll()

func (ShutdownHooks) ShutdownByType

func (h ShutdownHooks) ShutdownByType(hookType SignalHookName) bool

type SignalHookName

type SignalHookName string
const (
	TraceHook  SignalHookName = "trace"
	MetricHook SignalHookName = "metric"
	LogHook    SignalHookName = "log"
)

type SignalProcessor

type SignalProcessor interface {
	AsyncTraceProcessor(...trace.BatchSpanProcessorOption) trace.SpanProcessor
	SyncTraceProcessor() trace.SpanProcessor
	AsyncLogProcessor(...log.BatchProcessorOption) log.Processor
	SyncLogProcessor(...log.SimpleProcessorOption) log.Processor
	MetricProcessor(...metric.PeriodicReaderOption) metric.Reader
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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