Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
ribice committed Jan 12, 2025
1 parent d8eb25f commit a94845b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions _examples/flush-with-context/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"context"
"fmt"
"time"

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

func main() {
_ = sentry.Init(sentry.ClientOptions{
Dsn: "https://[email protected]/1337",
Debug: true,
})

sentry.CaptureMessage("Event #1")
sentry.CaptureMessage("Event #2")
sentry.CaptureMessage("Event #3")

go func() {
sentry.CaptureMessage("Event #4")
sentry.CaptureMessage("Event #5")
}()

fmt.Println("=> Flushing transport buffer")

ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
defer cancel()

if sentry.FlushWithContext(ctx) {
fmt.Println("=> All queued events delivered!")
} else {
fmt.Println("=> Flush timeout reached")
}
}

0 comments on commit a94845b

Please sign in to comment.