{"id":23085378,"url":"https://github.com/asjdf/flamego-sentry","last_synced_at":"2026-05-04T05:44:24.702Z","repository":{"id":50389020,"uuid":"518924533","full_name":"asjdf/flamego-sentry","owner":"asjdf","description":"Package flamego-sentry is a middleware that capture and handle the error with Sentry  for Flamego","archived":false,"fork":false,"pushed_at":"2022-12-03T17:04:46.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-09T04:16:25.229Z","etag":null,"topics":["flamego","go","lsif-enabled","sentry"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asjdf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-28T16:47:23.000Z","updated_at":"2022-07-28T19:02:25.000Z","dependencies_parsed_at":"2023-01-22T16:55:19.242Z","dependency_job_id":null,"html_url":"https://github.com/asjdf/flamego-sentry","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asjdf%2Fflamego-sentry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asjdf%2Fflamego-sentry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asjdf%2Fflamego-sentry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asjdf%2Fflamego-sentry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asjdf","download_url":"https://codeload.github.com/asjdf/flamego-sentry/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247025730,"owners_count":20871244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flamego","go","lsif-enabled","sentry"],"created_at":"2024-12-16T17:54:15.177Z","updated_at":"2026-05-04T05:44:19.680Z","avatar_url":"https://github.com/asjdf.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://sentry.io/?utm_source=github\u0026utm_medium=logo\" target=\"_blank\"\u003e\n    \u003cpicture\u003e\n      \u003csource srcset=\"https://sentry-brand.storage.googleapis.com/sentry-logo-white.png\" media=\"(prefers-color-scheme: dark)\" /\u003e\n      \u003csource srcset=\"https://sentry-brand.storage.googleapis.com/sentry-logo-black.png\" media=\"(prefers-color-scheme: light), (prefers-color-scheme: no-preference)\" /\u003e\n      \u003cimg src=\"https://sentry-brand.storage.googleapis.com/sentry-logo-black.png\" alt=\"Sentry\" width=\"280\"\u003e\n    \u003c/picture\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# flamego-sentry\n\n[![GoDoc](https://img.shields.io/badge/GoDoc-Reference-blue?style=for-the-badge\u0026logo=go)](https://pkg.go.dev/github.com/asjdf/flamego-sentry)\n[![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?style=for-the-badge\u0026logo=sourcegraph)](https://sourcegraph.com/github.com/asjdf/flamego-sentry)\n\nPackage flamego-sentry is a middleware that capture and handle the error with Sentry  for Flamego\n\n## Install\n\n```bash\ngo get github.com/asjdf/flamego-sentry\n```\n\n```go\nimport (\n    \"fmt\"\n    \"github.com/getsentry/sentry-go\"\n    sentryflame \"github.com/asjdf/flamego-sentry\"\n    \"github.com/flamego/flamego\"\n)\n\n// To initialize Sentry's handler, you need to initialize Sentry itself beforehand\nif err := sentry.Init(sentry.ClientOptions{\n    Dsn: \"your-public-dsn\",\n}); err != nil {\n    fmt.Printf(\"Sentry initialization failed: %v\\n\", err)\n}\n\n// Then create your app\nf := flamego.Classic()\n\n// Once it's done, you can attach the handler as one of your middleware\nf.Use(sentryflame.New(sentryflame.Options{}))\n\n// Set up routes\nf.Get(\"/\", func() string {\n    return \"Hello world!\"\n})\n\n// And run it\nf.Run()\n```\n\n## Configuration\n`sentryflame` accepts a struct of `Options` that allows you to configure how the handler will behave.\n\nCurrently it respects 3 options:\n\n```go\n// Whether Sentry should repanic after recovery, in most cases it should be set to true,\n// as flamego.Classic includes its own Recovery middleware that handles http responses.\nRepanic         bool\n// Whether you want to block the request before moving forward with the response.\n// Because Flamego's default `Recovery` handler doesn't restart the application,\n// it's safe to either skip this option or set it to `false`.\nWaitForDelivery bool\n// Timeout for the event delivery requests.\nTimeout         time.Duration\n```\n\n## Usage\n\n`sentryflame` invoke an instance of `*sentry.Hub` (https://godoc.org/github.com/getsentry/sentry-go#Hub) to the `flamego.Context`, which makes it available throughout the rest of the request's lifetime.\nYou can access it by using the `sentrygin.GetHubFromContext()` method on the context itself in any of your proceeding middleware and routes.\nAnd it should be used instead of the global `sentry.CaptureMessage`, `sentry.CaptureException`, or any other calls, as it keeps the separation of data between the requests.\n\n**Keep in mind that `*sentry.Hub` won't be available in middleware attached before to `sentryflame`!**\n\n```go\nf := flamego.Classic()\n\nf.Use(sentryflame.New(sentrygin.Options{\n    Repanic: true,\n}))\n\nf.Use(func(ctx flamego.Context) {\n    if hub := sentryflame.GetHubFromContext(ctx); hub != nil {\n        hub.Scope().SetTag(\"someRandomTag\", \"maybeYouNeedIt\")\n    }\n    ctx.Next()\n})\n\nf.Get(\"/1\", func(ctx flamego.Context) {\n    if hub := GetHubFromContext(ctx); hub != nil {\n        hub.WithScope(func(scope *sentry.Scope) {\n            scope.SetExtra(\"unwantedQuery\", \"someQueryDataMaybe\")\n            hub.CaptureMessage(\"User provided unwanted query string, but we recovered just fine\")\n        })\n    }\n    ctx.ResponseWriter().WriteHeader(http.StatusOK)\n})\n\nf.Get(\"/2\", func(ctx flamego.Context, hub *sentry.Hub) {\n    hub.WithScope(func(scope *sentry.Scope) {\n        scope.SetExtra(\"unwantedQuery\", \"someQueryDataMaybe\")\n        hub.CaptureMessage(\"User provided unwanted query string, but we recovered just fine\")\n    })\n    ctx.ResponseWriter().WriteHeader(http.StatusOK)\n})\n\nf.Get(\"/foo\", func() {\n    // sentrygin handler will catch it just fine. Also, because we attached \"someRandomTag\"\n    // in the middleware before, it will be sent through as well\n    panic(\"y tho\")\n})\n\napp.Run()\n```\n\n### Accessing Request in `BeforeSend` callback\n\n```go\nsentry.Init(sentry.ClientOptions{\n    Dsn: \"your-public-dsn\",\n    BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {\n        if hint.Context != nil {\n            if req, ok := hint.Context.Value(sentry.RequestContextKey).(*http.Request); ok {\n                // You have access to the original Request here\n            }\n        }\n\n        return event\n    },\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasjdf%2Fflamego-sentry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasjdf%2Fflamego-sentry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasjdf%2Fflamego-sentry/lists"}