app

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: Apache-2.0 Imports: 38 Imported by: 15

Documentation

Overview

Package app implements OTEL, prometheus, graceful shutdown and other common application features for go-faster projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go added in v0.17.0

func Go(f func(ctx context.Context, t *Telemetry) error, op ...Option)

Go runs f until interrupt.

func Resource deprecated

func Resource(ctx context.Context) (*resource.Resource, error)

Resource returns new resource for application.

Combines following detectors: - ProcessRuntimeDescription - ProcessRuntimeVersion - ProcessRuntimeName And merges it with default resource.

Deprecated: use WithResourceOptions, WithServiceName, WithServiceNamespace.

func Run

func Run(f func(ctx context.Context, lg *zap.Logger, m *Telemetry) error, op ...Option)

Run f until interrupt.

If errors.Is(err, ctx.Err()) is valid for returned error, shutdown is considered graceful. Context is cancelled on SIGINT. After watchdogTimeout application is forcefully terminated with exitCodeWatchdog.

Types

type Metrics deprecated

type Metrics = Telemetry

Deprecated: use Telemetry.

type Option added in v0.8.2

type Option interface {
	// contains filtered or unexported methods
}

Option is a functional option for the application.

func WithContext added in v0.10.0

func WithContext(ctx context.Context) Option

WithContext sets the base context for the application. Background context is used by default.

func WithMeterOptions added in v0.8.2

func WithMeterOptions(opts ...autometer.Option) Option

WithMeterOptions sets the default autometer options for the application.

func WithResource added in v0.12.0

func WithResource(fn func(ctx context.Context) (*resource.Resource, error)) Option

WithResource sets the function that will be called to retrieve telemetry resource for application.

Defaults to function that enables most common resource detectors.

func WithResourceOptions added in v0.21.0

func WithResourceOptions(opts ...resource.Option) Option

WithResourceOptions sets the default resource options.

Use before WithResource or WithServiceName to override default resource options.

func WithServiceName added in v0.21.0

func WithServiceName(name string) Option

WithServiceName sets the default service name for the application.

func WithServiceNamespace added in v0.21.0

func WithServiceNamespace(namespace string) Option

WithServiceNamespace sets the default service namespace for the application.

func WithTracerOptions added in v0.8.2

func WithTracerOptions(opts ...autotracer.Option) Option

WithTracerOptions sets the default autotracer options for the application.

func WithZapConfig added in v0.8.2

func WithZapConfig(cfg zap.Config) Option

WithZapConfig sets the default zap config for the application.

func WithZapOpenTelemetry added in v0.26.0

func WithZapOpenTelemetry() Option

WithZapOpenTelemetry enabels OpenTelemetry mode for zap. See zctx.WithOpenTelemetryZap.

func WithZapOptions added in v0.11.0

func WithZapOptions(opts ...zap.Option) Option

WithZapOptions sets additional zap logger options for the application.

func WithZapTee added in v0.17.0

func WithZapTee(teeToStderr bool) Option

WithZapTee sets option to tee zap logs to stderr.

type Telemetry added in v0.17.0

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

Telemetry implement common basic metrics and infrastructure to it.

func (*Telemetry) BaseContext added in v0.25.0

func (m *Telemetry) BaseContext() context.Context

BaseContext is base context for the application.

func (*Telemetry) LoggerProvider added in v0.17.0

func (m *Telemetry) LoggerProvider() log.LoggerProvider

func (*Telemetry) MeterProvider added in v0.17.0

func (m *Telemetry) MeterProvider() metric.MeterProvider

func (*Telemetry) ShutdownContext added in v0.23.0

func (m *Telemetry) ShutdownContext() context.Context

ShutdownContext is context for triggering graceful shutdown. It is cancelled on SIGINT.

Base context Telemetry.BaseContext can be used during shutdown to finish pending operations, it will be cancelled later on timeout.

func (*Telemetry) String added in v0.17.0

func (m *Telemetry) String() string

func (*Telemetry) TextMapPropagator added in v0.17.0

func (m *Telemetry) TextMapPropagator() propagation.TextMapPropagator

func (*Telemetry) TracerProvider added in v0.17.0

func (m *Telemetry) TracerProvider() trace.TracerProvider

Jump to

Keyboard shortcuts

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