Skip to content

Commit 350ef2e

Browse files
committed
feat: add sentry problem details reporter
1 parent dd31b6c commit 350ef2e

File tree

7 files changed

+531
-0
lines changed

7 files changed

+531
-0
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
3+
name: CI
4+
on:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: lint
15+
uses: reviewdog/action-golangci-lint@v2
16+
test:
17+
strategy:
18+
matrix:
19+
go_version:
20+
- 1.15.x
21+
- 1.16.x
22+
- 1.17.x
23+
os:
24+
- ubuntu-latest
25+
runs-on: ${{ matrix.os }}
26+
steps:
27+
- uses: actions/checkout@v2
28+
- uses: actions/setup-go@v2
29+
with:
30+
go-version: ${{ matrix.go_version }}
31+
- name: test
32+
run: go test -v -race -cover -covermode=atomic ./...

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 aereal
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[![status][ci-status-badge]][ci-status]
2+
[![PkgGoDev][pkg-go-dev-badge]][pkg-go-dev]
3+
4+
# go-problem-reporter
5+
6+
go-problem-reporter captures HTTP responses that conform to [RFC7807 Problem Details][rfc7807] from your web application and sends to error reporting services.
7+
8+
Currently supported services:
9+
10+
- [Sentry][]
11+
12+
## Synopsis
13+
14+
```go
15+
package main
16+
17+
import (
18+
"github.com/getsentry/sentry-go"
19+
"github.com/moogar0880/problems"
20+
sentryhttp "github.com/getsentry/sentry-go/http"
21+
sentryreporter "github.com/aereal/go-problem-reporter/sentry"
22+
)
23+
24+
func main() {
25+
h := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
26+
p := problems.NewDetailedProblem(http.StatusInternalServerError, "some details"),
27+
problems.StatusProblemHandler(p).ServeHTTP(rw, r)
28+
})
29+
mw := sentryreporter.New(sentryreporter.Options{WaitForDelivery: true})
30+
withSentryHub := sentryhttp.New(sentryhttp.Options{}).Handle
31+
&http.Server{
32+
Handler: withSentryHub(mw(h)),
33+
}
34+
}
35+
```
36+
37+
## Installation
38+
39+
```sh
40+
go get github.com/aereal/go-problem-reporter
41+
```
42+
43+
## License
44+
45+
See LICENSE file.
46+
47+
[pkg-go-dev]: https://pkg.go.dev/github.com/aereal/go-problem-reporter
48+
[pkg-go-dev-badge]: https://pkg.go.dev/badge/aereal/go-problem-reporter
49+
[ci-status-badge]: https://github.com/aereal/go-problem-reporter/workflows/CI/badge.svg?branch=main
50+
[ci-status]: https://github.com/aereal/go-problem-reporter/actions/workflows/CI
51+
[rfc7807]: https://datatracker.ietf.org/doc/html/rfc7807
52+
[Sentry]: https://sentry.io/welcome/

go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module github.com/aereal/go-problem-reporter
2+
3+
go 1.17
4+
5+
require (
6+
github.com/aereal/gomas v0.3.0
7+
github.com/getsentry/sentry-go v0.11.0
8+
github.com/google/go-cmp v0.5.6
9+
github.com/moogar0880/problems v0.1.1
10+
)
11+
12+
require golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect

0 commit comments

Comments
 (0)