Zero-dependency clients for errors.bitreport.pt following the same patterns as clients/node and clients/php: batch size 25, 5 s flush interval, 8 s HTTP timeout, fire-and-forget, env-var config. Each client ships with unit tests backed by an embedded HTTP server (no mocks), an example file, and a build manifest (pyproject.toml, go.mod, pom.xml). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
47 lines
996 B
Go
47 lines
996 B
Go
//go:build ignore
|
|
|
|
// Basic usage example for the BitReport Go error reporter.
|
|
//
|
|
// Run with:
|
|
//
|
|
// ERROR_REPORTING_TOKEN=your_token go run basic_usage.go
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
errorreporter "pt.bitreport/errors-go"
|
|
)
|
|
|
|
func main() {
|
|
errorreporter.Init(errorreporter.Config{
|
|
Token: os.Getenv("ERROR_REPORTING_TOKEN"),
|
|
ProjectName: "My Go App",
|
|
ProjectSlug: "my-go-app",
|
|
})
|
|
defer errorreporter.Flush()
|
|
|
|
// Report a plain message
|
|
errorreporter.ReportMessage("Application started", "info", nil)
|
|
|
|
// Report a warning with extra context
|
|
errorreporter.ReportMessage("Cache miss", "warning", map[string]interface{}{
|
|
"cache_key": "user:42",
|
|
})
|
|
|
|
// Report an error
|
|
if err := riskyOperation(); err != nil {
|
|
errorreporter.ReportError(err, map[string]interface{}{
|
|
"operation": "riskyOperation",
|
|
})
|
|
}
|
|
|
|
fmt.Println("Events sent. Check your errors.bitreport.pt dashboard.")
|
|
}
|
|
|
|
func riskyOperation() error {
|
|
return errors.New("something went wrong")
|
|
}
|