otelzap

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

README

otelzap

Zap logger with OpenTelemetry support. This logger will export LogRecord's in OTLP format.

Quick start

Configure open-telemetry provider. See example here

Then configure zap logger with otel core:

package main

import (
	"context"
	"github.com/agoda-com/opentelemetry-go/otelzap"
	"go.uber.org/zap"
)

func main() {

	// configure logger provider
	loggerProvider :=  ...

	// create new  logger with opentelemetry zap core and set it globally
	logger := zap.New(otelzap.NewOtelCore(loggerProvider))
	zap.ReplaceGlobals(logger)
}

// call function with opentelemetry context provided
func doSomething(ctx context.Context) {
	// send log with opentelemetry context
	otelzap.Ctx(ctx).Info("My message with trace context")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOtelCore

func NewOtelCore(loggerProvider otel.LoggerProvider, opts ...Option) zapcore.Core

NewOtelCore creates new OpenTelemetry Core to export logs in OTLP format

func Version

func Version() string

Version is the current release version of OpenTelemetry Zap in use.

Types

type Logger

type Logger struct {
	*zap.Logger
}

Logger is a thin wrapper for zap.Logger that adds Ctx method.

func Ctx

func Ctx(ctx context.Context) *Logger

Ctx is a shortcut for L().Ctx(ctx).

func L

func L() *Logger

L returns the global Logger

func (*Logger) Ctx

func (l *Logger) Ctx(ctx context.Context) *Logger

func (*Logger) Sugar

func (l *Logger) Sugar() *SugaredLogger

func (*Logger) With

func (l *Logger) With(fields ...zapcore.Field) *Logger

type Option added in v0.2.1

type Option func(c *otlpCore)

Option is a function that applies an option to an OpenTelemetry Core

func WithLevel added in v0.2.1

func WithLevel(level zapcore.Level) Option

WithLevel sets the minimum level for the OpenTelemetry Core log to be exported

type SugaredLogger

type SugaredLogger struct {
	*zap.SugaredLogger
}

func S

func S() *SugaredLogger

func (*SugaredLogger) Ctx

Jump to

Keyboard shortcuts

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