Loading...
Loading...
Full Sentry SDK setup for Go. Use when asked to "add Sentry to Go", "install sentry-go", "setup Sentry in Go", or configure error monitoring, tracing, logging, metrics, or crons for Go applications. Supports net/http, Gin, Echo, Fiber, FastHTTP, Iris, and Negroni.
npx skill4agent add getsentry/sentry-agent-skills sentry-go-sdksentry-gogithub.com/getsentry/sentry-goNote: SDK versions and APIs below reflect Sentry docs at time of writing (sentry-go v0.43.0). Always verify against docs.sentry.io/platforms/go/ before implementing.
# Check existing Sentry dependency
grep -i sentry go.mod 2>/dev/null
# Detect web framework
grep -E "gin-gonic/gin|labstack/echo|gofiber/fiber|valyala/fasthttp|kataras/iris|urfave/negroni" go.mod 2>/dev/null
# Detect logging libraries
grep -E "sirupsen/logrus|go.uber.org/zap|rs/zerolog|log/slog" go.mod go.sum 2>/dev/null
# Detect cron / scheduler patterns
grep -E "robfig/cron|go-co-op/gocron|jasonlvhit/gocron" go.mod 2>/dev/null
# Detect OpenTelemetry usage
grep "go.opentelemetry.io" go.mod 2>/dev/null
# Check for companion frontend
ls frontend/ web/ client/ ui/ 2>/dev/nullsentry-gogo.modreferences/profiling.md| Feature | Recommend when... |
|---|---|
| Error Monitoring | Always — non-negotiable baseline |
| Tracing | |
| Logging | logrus, zap, zerolog, or |
| Metrics | Business events, SLO tracking, or counters needed |
| Crons | |
| Profiling | ⚠️ Removed in v0.31.0 — do not recommend; see |
# Core SDK (always required)
go get github.com/getsentry/sentry-go
# Framework sub-package — install only what matches detected framework:
go get github.com/getsentry/sentry-go/http # net/http
go get github.com/getsentry/sentry-go/gin # Gin
go get github.com/getsentry/sentry-go/echo # Echo
go get github.com/getsentry/sentry-go/fiber # Fiber
go get github.com/getsentry/sentry-go/fasthttp # FastHTTP
# Logging sub-packages — install only what matches detected logging lib:
go get github.com/getsentry/sentry-go/logrus # Logrus
go get github.com/getsentry/sentry-go/slog # slog (stdlib, Go 1.21+)
go get github.com/getsentry/sentry-go/zap # Zap
go get github.com/getsentry/sentry-go/zerolog # Zerolog
# OpenTelemetry bridge (only if OTel is already in use):
go get github.com/getsentry/sentry-go/otelmain()import (
"log"
"os"
"time"
"github.com/getsentry/sentry-go"
)
err := sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("SENTRY_DSN"),
Environment: os.Getenv("SENTRY_ENVIRONMENT"), // "production", "staging", etc.
Release: release, // inject via -ldflags at build time
SendDefaultPII: true,
AttachStacktrace: true,
// Tracing (adjust sample rate for production)
EnableTracing: true,
TracesSampleRate: 1.0, // lower to 0.1–0.2 in high-traffic production
// Logs
EnableLogs: true,
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}
defer sentry.Flush(2 * time.Second)Releasevar release string // set by -ldflags
// go build -ldflags="-X main.release=my-app@$(git describe --tags)"sentry.Init| Framework | Import path | Middleware call | | |
|---|---|---|---|---|
| | | | |
| Gin | | | | |
| Echo | | | | |
| Fiber | | | | |
| FastHTTP | | | | |
| Iris | | | | |
| Negroni | | | | |
Note: Fiber and FastHTTP are built onwhich has no built-in recovery. Usevalyala/fasthttpfor those.Repanic: false, WaitForDelivery: true
// net/http, Negroni:
hub := sentry.GetHubFromContext(r.Context())
// Gin:
hub := sentrygin.GetHubFromContext(c)
// Echo:
hub := sentryecho.GetHubFromContext(c)
// Fiber:
hub := sentryfiber.GetHubFromContext(c)| Feature | Reference file | Load when... |
|---|---|---|
| Error Monitoring | | Always (baseline) |
| Tracing | | HTTP handlers / distributed tracing |
| Profiling | | Performance-sensitive production apps |
| Logging | | logrus / zap / zerolog / slog detected |
| Metrics | | Business KPIs / SLO tracking |
| Crons | | Scheduler / cron job patterns detected |
Read ${SKILL_ROOT}/references/<feature>.mdClientOptions| Option | Type | Default | Purpose |
|---|---|---|---|
| | | SDK disabled if empty; env: |
| | | e.g., |
| | | e.g., |
| | | Include IP, request headers |
| | | Stack traces on |
| | | Error event sample rate (0.0 treated as 1.0) |
| | | Enable performance tracing |
| | | Transaction sample rate |
| | | Custom per-transaction sampling (overrides rate) |
| | | Enable Sentry Logs feature |
| | | Max breadcrumbs per event |
| | | Max depth for unwrapping error chains |
| | | Verbose SDK debug output |
| | | Hook to mutate/drop error events |
| | | Hook to mutate/drop transaction events |
| | | Regex patterns for errors to drop |
| | | Regex patterns for transactions to drop |
| Variable | Maps to | Purpose |
|---|---|---|
| | Data Source Name |
| | App version (e.g., |
| | Deployment environment |
| | Outbound proxy |
ClientOptions// In a handler or test — triggers a real error event:
sentry.CaptureMessage("Sentry Go SDK test")
// Or trigger a captured panic (with recovery middleware in place):
panic("sentry test panic")Debug: trueClientOptionssentry.Flush(2 * time.Second)ls frontend/ web/ client/ ui/ 2>/dev/null
cat frontend/package.json web/package.json 2>/dev/null | grep -E '"react"|"svelte"|"vue"|"next"'| Frontend detected | Suggest skill |
|---|---|
| React / Next.js | |
| Svelte / SvelteKit | |
| Vue | Use |
| Other JS/TS | |
| Issue | Solution |
|---|---|
| Events not appearing | Set |
| Malformed DSN — check format: |
| Panics not captured | Ensure framework middleware is registered before handlers |
| |
| Missing stack traces | Set |
| Goroutine events missing context | Clone hub before spawning goroutine: |
| Too many transactions | Lower |
| Fiber/FastHTTP not recovering | Use |
| |