Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
ribice committed Jul 31, 2024
1 parent 7da0be8 commit 8a95b37
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions _examples/slog/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"
"log"
"time"

"log/slog"

"github.com/getsentry/sentry-go"
sentryslog "github.com/getsentry/sentry-go/slog"
)

func main() {
err := sentry.Init(sentry.ClientOptions{
Dsn: "https://[email protected]/4506954545758208",
EnableTracing: false,
})
if err != nil {
log.Fatal(err)
}

defer sentry.Flush(2 * time.Second)

logger := slog.New(sentryslog.Option{Level: slog.LevelDebug}.NewSentryHandler())
logger = logger.With("release", "v1.0.0")

logger.
With(
slog.Group("user",
slog.String("id", "user-123"),
slog.Time("created_at", time.Now()),
),
).
With("environment", "dev").
With("error", fmt.Errorf("an error")).
Error("a message")
}

0 comments on commit 8a95b37

Please sign in to comment.