Documentation ¶
Overview ¶
Package observe implements a type that combines statter, logger and tracer.
Example usage:
func newObserver(c *cli.Context) (*observe.Observer, error) { log, err := cmd.NewLogger(c) if err != nil { return nil, err } stats, err := cmd.NewStatter(c, log) if err != nil { return nil, err } prof, err := cmd.NewProfiler(c, "my-service", log) if err != nil { return nil, err } profStop := func() {} if prof != nil { profStop = func() { _ = prof.Stop() } } tracer, err := cmd.NewTracer(c, log, semconv.ServiceNameKey.String("my-service"), semconv.ServiceVersionKey.String("1.0.0"), ) if err != nil { return nil, err } tracerCancel := func() { _ = tracer.Shutdown(context.Background()) } return observe.New(log, stats, tracer, tracerCancel, profStop), nil }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Observer ¶
type Observer struct { Log *logger.Logger Stats *statter.Statter TraceProv trace.TracerProvider // contains filtered or unexported fields }
Observer contains observability primitives.
func New ¶
func New(log *logger.Logger, stats *statter.Statter, traceProv trace.TracerProvider, closeFns ...func()) *Observer
New returns an observer with the given observability primitives.
Example ¶
var c *cli.Context // Get this from your action log, err := cmd.NewLogger(c) if err != nil { // Handle error. return } stats, err := cmd.NewStatter(c, log) if err != nil { // Handle error. return } prof, err := cmd.NewProfiler(c, "my-service", log) if err != nil { return } profStop := func() {} if prof != nil { profStop = func() { _ = prof.Stop() } } tracer, err := cmd.NewTracer(c, log, semconv.ServiceNameKey.String("my-service"), semconv.ServiceVersionKey.String("1.0.0"), ) if err != nil { // Handle error. return } tracerCancel := func() { _ = tracer.Shutdown(context.Background()) } obsrv := observe.New(log, stats, tracer, tracerCancel, profStop) _ = obsrv
Output:
func NewFake ¶
func NewFake() *Observer
NewFake returns a fake observer that reports nothing. This is useful for tests.
func NewFromCLI ¶ added in v2.10.0
NewFromCLI returns an observer with the given observability primitives.
Example ¶
var c *cli.Context // Get this from your action. obsrv, err := observe.NewFromCLI(c, "my-service", &observe.Options{ LogTimestamps: true, StatsRuntime: true, TracingAttrs: []attribute.KeyValue{ semconv.ServiceVersionKey.String("1.0.0"), }, }) if err != nil { // Handle error. return } _ = obsrv
Output:
Click to show internal directories.
Click to hide internal directories.