go-glitch
This commit is contained in:
commit
4526d05aef
|
@ -0,0 +1,53 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/getsentry/sentry-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Check for the right number of command line arguments
|
||||||
|
if len(os.Args) != 2 {
|
||||||
|
fmt.Println("Usage: ./go-glitch \"Your log message here\"")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
logMessage := os.Args[1]
|
||||||
|
|
||||||
|
dsn := os.Getenv("SENTRY_DSN")
|
||||||
|
if dsn == "" {
|
||||||
|
fmt.Println("Error: SENTRY_DSN environment variable is not set.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize Sentry with the DSN
|
||||||
|
err := sentry.Init(sentry.ClientOptions{
|
||||||
|
Dsn: dsn,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error initializing Sentry: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Defer a function to flush Sentry's buffer
|
||||||
|
defer func() {
|
||||||
|
success := sentry.Flush(5 * time.Second)
|
||||||
|
if !success {
|
||||||
|
fmt.Println("Failed to flush Sentry buffer within the expected time.")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Sentry buffer flushed successfully.")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Capture the message and output the event ID
|
||||||
|
eventID := sentry.CaptureMessage(logMessage)
|
||||||
|
if eventID != nil {
|
||||||
|
fmt.Printf("Sent message to Sentry with event ID: %s\n", *eventID)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Failed to send message to Sentry.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
module go-glitch
|
||||||
|
|
||||||
|
go 1.21.1
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/getsentry/sentry-go v0.27.0 // indirect
|
||||||
|
golang.org/x/sys v0.6.0 // indirect
|
||||||
|
golang.org/x/text v0.8.0 // indirect
|
||||||
|
)
|
|
@ -0,0 +1,6 @@
|
||||||
|
github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps=
|
||||||
|
github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
|
||||||
|
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
||||||
|
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
Loading…
Reference in New Issue