Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 1.57 KB

README.md

File metadata and controls

50 lines (37 loc) · 1.57 KB

PkgGoDev

OpenTelemetry Go 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-extra/otellogrus

Usage

You need to install an otellogrus.Hook and use logrus.WithContext to propagate the active span.

import (
    "github.com/uptrace/opentelemetry-go-extra/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.

Options

otellogrus.NewHook accepts the following options:

  • otellogrus.WithLevels(logrus.PanicLevel, logrus.FatalLevel, logrus.ErrorLevel, logrus.WarnLevel) sets the logrus logging levels on which the hook is fired.
  • WithErrorStatusLevel(logrus.ErrorLevel) sets the minimal logrus logging level on which the span status is set to codes.Error.