zap

command module
v0.0.0-...-316a413 Latest Latest
Warning

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

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

README

Zap OpenTelemetry instrumentation example

PkgGoDev

Install otelzap instrumentation:

go get github.com/uptrace/uptrace-go/extra/otelzap
go mod edit -replace go.uber.org/zap=github.com/uptrace/zap@master

Then wrap zap logger:

logger, err := zap.NewDevelopment()
if err != nil {
	panic(err)
}
defer logger.Sync()

logger = otelzap.Wrap(logger, otelzap.WithLevel(zap.NewAtomicLevelAt(zap.ErrorLevel)))

And use zap.Ctx to propagate the active span:

logger.Ctx(ctx).Error("hello from zap",
	zap.Error(errors.New("hello world")),
	zap.String("foo", "bar"))

Example

To run this example:

UPTRACE_DSN="https://<token>@api.uptrace.dev/<project_id>" go run main.go

Note that this example requires patching the zap package:

go mod edit -replace go.uber.org/zap=github.com/uptrace/zap@master

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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