otellogrus

package module
v0.0.0-...-030a0e5 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: BSD-2-Clause Imports: 9 Imported by: 0

README

build workflow PkgGoDev

OpenTelemetry instrumentation for logrus logging

This instrumentation records logrus log messages as events on the existing span that is passed via a context.Context. It does not record anything if a context does not contain a span.

Installation

go get github.com/uptrace/opentelemetry-go/otellogrus

Usage

import (
    "github.com/uptrace/opentelemetry-go/otellogrus"
    "github.com/sirupsen/logrus"
)

// Instrument logrus.
logrus.AddHook(otellogrus.NewHook(otellogrus.WithLevels(
	logrus.PanicLevel,
	logrus.FatalLevel,
	logrus.ErrorLevel,
	logrus.WarnLevel,
)))

// Use ctx to pass the active span.
logrus.WithContext(ctx).
	WithError(errors.New("hello world")).
	WithField("foo", "bar").
	Error("something failed")

See example for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

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

Hook is a logrus hook that adds logs to the active span as events.

func NewHook

func NewHook(opts ...Option) *Hook

NewHook returns a logrus hook.

func (*Hook) Fire

func (hook *Hook) Fire(entry *logrus.Entry) error

Fire is a logrus hook that is fired on a new log entry.

func (*Hook) Levels

func (hook *Hook) Levels() []logrus.Level

Levels returns logrus levels on which this hook is fired.

type Option

type Option func(h *Hook)

Option applies a configuration to the given config.

func WithErrorStatusLevel

func WithErrorStatusLevel(level logrus.Level) Option

WithErrorStatusLevel sets the maximum logrus logging level on which the span status is set to codes.Error.

The default is <= logrus.ErrorLevel.

func WithLevels

func WithLevels(levels ...logrus.Level) Option

WithLevels sets the logrus logging levels on which the hook is fired.

The default is all levels between logrus.PanicLevel and logrus.WarnLevel inclusive.

Jump to

Keyboard shortcuts

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