Documentation ¶
Overview ¶
Package otelslog provides a OpenTelemetry aware slog.Handler implementation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is an slog.Handler which helps standardize and correlate your logs by automatically adding the Trace ID and Span ID to your logs.
func (*Handler) WithAttrs ¶
WithAttrs implements the slog.Handler interface.
Example ¶
var buf bytes.Buffer var h slog.Handler = NewHandler(slog.NewJSONHandler(&buf, &slog.HandlerOptions{})) h = h.WithAttrs([]slog.Attr{slog.String("a", "b")}) logger := slog.New(h) logger.Info("hello world") var record struct { Message string `json:"msg"` A string `json:"a"` } err := json.Unmarshal(buf.Bytes(), &record) if err != nil { fmt.Println(err) return } fmt.Println(record.Message) fmt.Print(record.A)
Output: hello world b
func (*Handler) WithGroup ¶
WithGroup implements the slog.Handler interface.
Example ¶
var buf bytes.Buffer var h slog.Handler = NewHandler(slog.NewJSONHandler(&buf, &slog.HandlerOptions{})) h = h.WithGroup("n") logger := slog.New(h) logger.Info("hello world", slog.Int("one", 1)) var record struct { Message string `json:"msg"` N struct { One int `json:"one"` } `json:"n"` } err := json.Unmarshal(buf.Bytes(), &record) if err != nil { fmt.Println(err) return } fmt.Println(record.Message) fmt.Print(record.N.One)
Output: hello world 1
Click to show internal directories.
Click to hide internal directories.