otelhandler

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package otelhandler shows a slog.Handler wrapper that adds extra attributes to log statements.

Example
package main

import (
	"context"
	"log/slog"
	"os"

	"github.com/vikstrous/slogexamples/otelhandler"
)

func main() {
	ctx := context.Background()
	sl := slog.New(otelhandler.NewOtelHandler(slog.NewTextHandler(os.Stderr, nil)))
	sl.InfoContext(ctx, "example")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OtelHandler

type OtelHandler struct {
	slog.Handler
}

OtelHandler adds extra fields to the record being logged containing traceID and spanID so that logs can be correlated with traces

func NewOtelHandler

func NewOtelHandler(h slog.Handler) OtelHandler

func (OtelHandler) Handle

func (o OtelHandler) Handle(ctx context.Context, r slog.Record) error

func (OtelHandler) WithAttrs

func (o OtelHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (OtelHandler) WithGroup

func (o OtelHandler) WithGroup(group string) slog.Handler

Jump to

Keyboard shortcuts

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