otelzap

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 15 Imported by: 0

README

otelzap GoDoc Build Status Coverage Status Go Report Card

OpenTelemetry integration with ZAP logger.

Released under the MIT License.

Quick start

This package can be used to add regular log messages as OpenTelemetry events.

func MyAction(ctx context.Context, foo int) {
    ctx, span := tracer.Start(ctx, "MyAction")
    defer span.End()

    LOG := otelzap.SpanLogger(span, logger)

    LOG.Debug("do my action", zap.Int("foo", foo))
    // will write to stdout as normal zap logger does
    // and also will add "do my action" event to the span
}

Documentation

Overview

Package otelzap writes zap logs as OTEL events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any(key string, value interface{}) attribute.KeyValue

Any converts unknown type to OpenTelemetry attribute, probably as JSON value.

func AppendZapFields added in v0.1.2

func AppendZapFields(attributes []attribute.KeyValue, fields ...zapcore.Field) []attribute.KeyValue

AppendZapFields converts and appends a few ZAP fields.

func HTTPHeader added in v0.1.1

func HTTPHeader(key string, header http.Header, exclude map[string]bool) attribute.KeyValue

HTTPHeader converts HTTP headers into OpenTelemetry attribute as multi-line string. The HTTP headers to exclude should be in canonical form (see textproto.CanonicalMIMEHeaderKey).

func SpanLogger

func SpanLogger(span trace.Span, logger *zap.Logger) *zap.Logger

SpanLogger creates ZAP logger which also writes to OpenTelemetry span. If span is `nil“ or `no-op` then the same logger returned.

func SpanLoggerFromContext

func SpanLoggerFromContext(ctx context.Context, logger *zap.Logger) *zap.Logger

SpanLoggerFromContext similar to SpanLogger but gets span from context.

Types

This section is empty.

Directories

Path Synopsis
internal
mocked
Package mocked is a generated GoMock package.
Package mocked is a generated GoMock package.

Jump to

Keyboard shortcuts

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