Documentation ¶
Overview ¶
Package slog provides functions to correlate logs and traces using log/slog package (https://pkg.go.dev/log/slog).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewJSONHandler ¶
NewJSONHandler is a convenience function that returns a *slog.JSONHandler logger enhanced with tracing information.
Example ¶
package main import ( "context" "log/slog" "os" slogtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/log/slog" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" ) func main() { // start the DataDog tracer tracer.Start() defer tracer.Stop() // create the application logger logger := slog.New(slogtrace.NewJSONHandler(os.Stdout, nil)) // start a new span span, ctx := tracer.StartSpanFromContext(context.Background(), "ExampleNewJSONHandler") defer span.Finish() // log a message using the context containing span information logger.Log(ctx, slog.LevelInfo, "this is a log with tracing information") }
Output:
func WrapHandler ¶
WrapHandler enhances the given logger handler attaching tracing information to logs.
Example ¶
package main import ( "context" "log/slog" "os" slogtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/log/slog" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" ) func main() { // start the DataDog tracer tracer.Start() defer tracer.Stop() // create the application logger myHandler := slog.NewJSONHandler(os.Stdout, nil) logger := slog.New(slogtrace.WrapHandler(myHandler)) // start a new span span, ctx := tracer.StartSpanFromContext(context.Background(), "ExampleWrapHandler") defer span.Finish() // log a message using the context containing span information logger.Log(ctx, slog.LevelInfo, "this is a log with tracing information") }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.