otelslog

package module
v0.0.0-...-2fc1f6b Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

otelslog

log/slog handler for OTel

Quick start

Configure open-telemetry provider first. See example here

Then configure slog logger with otelslog handler:

package main

import (
	"context"
	"github.com/landmaj/opentelemetry-go/otelslog"
	"log/slog"
)

func main() {
	// configure logger provider
	loggerProvider :=  ...

	otelLogger := slog.New(otelslog.NewOtelHandler(loggerProvider, &otelslog.HandlerOptions{}))

	//configure default logger
	slog.SetDefault(otelLogger)

	doSomething(ctx)
}

// call function with opentelemetry context provided
func doSomething(ctx context.Context) {
	slog.InfoContext(ctx, "hello", slog.String("myKey", "myValue"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Version

func Version() string

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

Types

type HandlerOptions

type HandlerOptions struct {
	Level slog.Leveler
}

HandlerOptions are options for a OtelHandler. A zero HandlerOptions consists entirely of default values.

type OtelHandler

type OtelHandler struct {
	// contains filtered or unexported fields
}

OtelHandler is a Handler that writes Records to OTLP

func NewOtelHandler

func NewOtelHandler(loggerProvider otel.LoggerProvider, opts *HandlerOptions) *OtelHandler

NewOtelHandler creates a OtelHandler that writes to otlp, using the given options. If opts is nil, the default options are used.

func (OtelHandler) Enabled

func (o OtelHandler) Enabled(ctx context.Context, level slog.Level) bool

func (OtelHandler) Handle

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

func (OtelHandler) WithAttrs

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

func (OtelHandler) WithGroup

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

Jump to

Keyboard shortcuts

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