Documentation
¶
Index ¶
- func ShutDownPair(name SignalHookName, fn ShutdownHook) func() (SignalHookName, ShutdownHook)
- type Execution
- type Option
- func WithApplicationName(applicationName string) Option
- func WithApplicationVersion(applicationVersion string) Option
- func WithDisabledSignals(disableTraces, disableMetrics, disableLogs bool) Option
- func WithExecutionType(executionType Execution) Option
- func WithInitLogs() Option
- func WithInitMetrics() Option
- func WithInitSignals() Option
- func WithInitTraces() Option
- func WithLogProviderOptions(options ...sdklog.LoggerProviderOption) Option
- func WithPeriodicReaderOptions(options ...sdkmetric.PeriodicReaderOption) Option
- func WithPrometheusBridge(options ...prometheus.Option) Option
- func WithResourceOptions(resourceOptions ...resource.Option) Option
- func WithSignalProcessor(signalProcessor SignalProcessor) Option
- func WithTracePropagator(propagator propagation.TextMapPropagator) Option
- func WithTraceProviderOptions(options ...sdktrace.TracerProviderOption) Option
- type Options
- type Provider
- type ShutdownHook
- type ShutdownHooks
- type SignalHookName
- type SignalProcessor
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 Option ¶
type Option func(*config)
func WithApplicationName ¶
Example ¶
package main
import (
"github.com/vincentfree/opentelemetry/providerconfig"
)
func main() {
providerconfig.New(
providerconfig.WithApplicationName("example-app"),
)
}
func WithApplicationVersion ¶
Example ¶
package main
import (
"github.com/vincentfree/opentelemetry/providerconfig"
)
func main() {
providerconfig.New(
providerconfig.WithApplicationVersion("1.0.0"),
)
}
func WithDisabledSignals ¶
Example ¶
package main
import (
"github.com/vincentfree/opentelemetry/providerconfig"
)
func main() {
providerconfig.New(
providerconfig.WithDisabledSignals(
false, // traces
true, // metrics
true, // logs
),
)
}
func WithExecutionType ¶
Example ¶
package main
import (
"github.com/vincentfree/opentelemetry/providerconfig"
)
func main() {
providerconfig.New(
providerconfig.WithExecutionType(providerconfig.Async),
)
}
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
WithLogProviderOptions accepts LoggerProviderOptions
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)),
)
}
func WithPeriodicReaderOptions ¶ added in v0.1.1
func WithPeriodicReaderOptions(options ...sdkmetric.PeriodicReaderOption) Option
WithPeriodicReaderOptions accepts PeriodicReaderOptions
func WithPrometheusBridge ¶
func WithPrometheusBridge(options ...prometheus.Option) 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.
Accepts prometheus.Option's ¶
The Prometheus bridge is disabled by default.
Example ¶
package main
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/vincentfree/opentelemetry/providerconfig"
"github.com/vincentfree/opentelemetry/providerconfig/providerconfignoop"
prombridge "go.opentelemetry.io/contrib/bridges/prometheus"
)
func main() {
providerconfig.New(
providerconfig.WithApplicationName("example-app"),
providerconfig.WithApplicationVersion("0.1.0"),
providerconfig.WithExecutionType(providerconfig.Async),
providerconfig.WithSignalProcessor(providerconfignoop.NewNoopProcessor()),
// options come from the opentelemetry bridge(renamed to prombridge) library
// (naming conflicts with the prometheus library)
providerconfig.WithPrometheusBridge(prombridge.WithGatherer(prometheus.NewRegistry())),
)
}
func WithResourceOptions ¶
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(),
),
)
}
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()),
)
}
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{},
),
),
)
}
func WithTraceProviderOptions ¶
func WithTraceProviderOptions(options ...sdktrace.TracerProviderOption) Option
WithTraceProviderOptions accepts TracerProviderOptions
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())),
)
}
type Provider ¶
type Provider interface {
TraceProvider() trace.TracerProvider
MetricProvider() metric.MeterProvider
LogProvider() log.LoggerProvider
ShutdownAll()
ShutdownByType(signalHookName SignalHookName) bool
}
func New ¶
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())
}
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
}