# Go > https://docs.errora.org/platforms/go ## نصب ```bash go get github.com/getsentry/sentry-go ``` ## مقداردهی اولیه ```go package main import ( "log" "time" "github.com/getsentry/sentry-go" ) func main() { err := sentry.Init(sentry.ClientOptions{ Dsn: "https://@/", Environment: "production", Release: "myapp@1.4.2", EnableTracing: true, TracesSampleRate: 0.2, ProfilesSampleRate: 1.0, AttachStacktrace: true, SendDefaultPII: false, }) if err != nil { log.Fatalf("sentry.Init: %s", err) } // پیش از پایان برنامه، رویدادهای بافرشده را تخلیه کنید. defer sentry.Flush(2 * time.Second) run() } ``` در Go فراخوانی `Flush` مهم است: انتقال داده ناهم‌زمان است، پس پروسه‌ای که بلافاصله پس از یک panic خارج می‌شود ممکن است رویداد را از دست بدهد. ## net/http ```go sentryHandler := sentryhttp.New(sentryhttp.Options{Repanic: true}) http.Handle("/", sentryHandler.Handle(mux)) ``` برای Gin از `sentrygin.New(...)`، برای Echo از `sentryecho.New(...)` و برای Fiber از `sentryfiber.New(...)` استفاده کنید. ## ثبت دستی ```go if err != nil { sentry.WithScope(func(scope *sentry.Scope) { scope.SetTag("area", "ledger") scope.SetContext("order", map[string]any{"id": order.ID}) sentry.CaptureException(err) }) } defer func() { if r := recover(); r != nil { sentry.CurrentHub().Recover(r) sentry.Flush(2 * time.Second) panic(r) } }() ``` ## اسپن‌های ردیابی ```go ctx := context.Background() span := sentry.StartSpan(ctx, "task", sentry.WithTransactionName("nightly-settlement")) defer span.Finish() child := sentry.StartSpan(span.Context(), "db.query") // … کار … child.Finish() ``` ## چک‌این کران ```go checkinID := sentry.CaptureCheckIn(&sentry.CheckIn{ MonitorSlug: "nightly-settlement", Status: sentry.CheckInStatusInProgress, }, &sentry.MonitorConfig{ Schedule: sentry.CrontabSchedule("0 3 * * *"), CheckInMargin: 5, MaxRuntime: 30, Timezone: "Asia/Tehran", }) // … اجرای جاب … sentry.CaptureCheckIn(&sentry.CheckIn{ ID: *checkinID, MonitorSlug: "nightly-settlement", Status: sentry.CheckInStatusOK, }, nil) ``` نگاه کنید به [مانیتورینگ کران](/products/crons). ## بررسی نهایی ```go sentry.CaptureException(errors.New("Errora smoke test")) sentry.Flush(2 * time.Second) ```