Skip to content

Commit c993c67

Browse files
authored
implement sentry error reporting (#151)
* implement sentry error reporting * add sentry to config files * implement sentry hook * remove unwanted log levels from sentry hook * remove event id pass to log entry in sentry hook * move sentry_hook.go to root folder * move environment to server config
1 parent 9b575dc commit c993c67

File tree

12 files changed

+238
-59
lines changed

12 files changed

+238
-59
lines changed

cmd/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88
_ "time/tzdata"
99

10+
"github.com/getsentry/sentry-go"
1011
"github.com/google/uuid"
1112
"go.mongodb.org/mongo-driver/bson/primitive"
1213

@@ -67,6 +68,21 @@ func main() {
6768
return err
6869
}
6970

71+
err = sentry.Init(sentry.ClientOptions{
72+
Debug: true,
73+
Dsn: cfg.Sentry.Dsn,
74+
Environment: cfg.Server.Environment,
75+
})
76+
if err != nil {
77+
return err
78+
}
79+
80+
defer sentry.Recover() // recover any panic and report to sentry
81+
defer sentry.Flush(2 * time.Second) // send any events in sentry before exiting
82+
83+
sentryHook := convoy.NewSentryHook(convoy.DefaultLevels)
84+
log.AddHook(sentryHook)
85+
7086
var queuer queue.Queuer
7187

7288
if cfg.Queue.Type == config.RedisQueueProvider {

config/config.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ type DatabaseConfiguration struct {
1919
Dsn string `json:"dsn"`
2020
}
2121

22+
type SentryConfiguration struct {
23+
Dsn string `json:"dsn"`
24+
}
25+
2226
type ServerConfiguration struct {
23-
HTTP struct {
27+
Environment string `json:"environment"`
28+
HTTP struct {
2429
Port uint32 `json:"port"`
2530
} `json:"http"`
2631
}
@@ -77,6 +82,7 @@ type Configuration struct {
7782
UIAuth UIAuthConfiguration `json:"ui,omitempty"`
7883
UIAuthorizedUsers map[string]string `json:"-"`
7984
Database DatabaseConfiguration `json:"database"`
85+
Sentry SentryConfiguration `json:"sentry"`
8086
Queue QueueConfiguration `json:"queue"`
8187
Server ServerConfiguration `json:"server"`
8288
Strategy StrategyConfiguration `json:"strategy"`
@@ -139,6 +145,19 @@ func LoadConfig(p string) error {
139145
}
140146
}
141147

148+
if serverEnv := os.Getenv("CONVOY_SERVER_ENV"); serverEnv != "" {
149+
c.Server.Environment = serverEnv
150+
}
151+
152+
// if it's still empty, set it to development
153+
if c.Server.Environment == "" {
154+
c.Server.Environment = "development"
155+
}
156+
157+
if sentryDsn := os.Getenv("CONVOY_SENTRY_DSN"); sentryDsn != "" {
158+
c.Sentry = SentryConfiguration{Dsn: sentryDsn}
159+
}
160+
142161
if signatureHeader := os.Getenv("CONVOY_SIGNATURE_HEADER"); signatureHeader != "" {
143162
c.Signature.Header = SignatureHeaderProvider(signatureHeader)
144163
}

convoy-docker.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
2-
"database": {
2+
"sentry": {
3+
"dsn": "<insert-sentry-dsn>"
4+
},
5+
"database": {
6+
"environment": "dev",
37
"dsn": "mongodb://root:rootpassword@mongodb:27017"
48
},
59
"queue": {

convoy.json

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,50 @@
11
{
2-
"database": {
3-
"dsn": "mongodb://root:rootpassword@localhost:27017"
4-
},
5-
"queue": {
6-
"type": "redis",
7-
"redis": {
8-
"dsn": "redis://localhost:8379"
9-
}
10-
},
11-
"server": {
12-
"http": {
13-
"port": 5005
14-
}
15-
},
16-
"auth": {
17-
"type": "none"
18-
},
19-
"strategy": {
20-
"type": "default",
21-
"default": {
22-
"intervalSeconds": 125,
23-
"retryLimit": 15
24-
}
25-
},
26-
"signature": {
27-
"header": "X-Company-Event-WebHook-Signature",
28-
"hash": "SHA256"
29-
},
30-
"ui": {
31-
"type": "basic",
32-
"basic": [
33-
{
34-
"username": "user1",
35-
"password": "password1"
36-
},
37-
{
38-
"username": "user2",
39-
"password": "password2"
40-
}
41-
],
42-
"jwtKey": "eyJhbGciOiJIUzI1NiJ9.eyJSb2xlIjoiQWRtaW4iLCJJc3N1ZXIiOiJDb252b3kgVGVzdCIsIlVzZXJuYW1lIjoiU21hcnQiLCJleHAiOjE2MzE2MjMzOTAsImlhdCI6MTYzMTYyMzM5MH0.u4kHClCgj9KjdyHfebQn8_AnU0DlXeJX8zvJvpMLCkQ",
43-
"jwtTokenExpirySeconds": 3600
44-
}
2+
"database": {
3+
"environment": "dev",
4+
"dsn": "mongodb://root:rootpassword@localhost:27017"
5+
},
6+
"sentry": {
7+
"dsn": "<insert-sentry-dsn>"
8+
},
9+
"queue": {
10+
"type": "redis",
11+
"redis": {
12+
"dsn": "redis://localhost:8379"
13+
}
14+
},
15+
"server": {
16+
"environment": "dev",
17+
"http": {
18+
"port": 5005
19+
}
20+
},
21+
"auth": {
22+
"type": "none"
23+
},
24+
"strategy": {
25+
"type": "default",
26+
"default": {
27+
"intervalSeconds": 125,
28+
"retryLimit": 15
29+
}
30+
},
31+
"signature": {
32+
"header": "X-Company-Event-WebHook-Signature",
33+
"hash": "SHA256"
34+
},
35+
"ui": {
36+
"type": "basic",
37+
"basic": [
38+
{
39+
"username": "user1",
40+
"password": "password1"
41+
},
42+
{
43+
"username": "user2",
44+
"password": "password2"
45+
}
46+
],
47+
"jwtKey": "eyJhbGciOiJIUzI1NiJ9.eyJSb2xlIjoiQWRtaW4iLCJJc3N1ZXIiOiJDb252b3kgVGVzdCIsIlVzZXJuYW1lIjoiU21hcnQiLCJleHAiOjE2MzE2MjMzOTAsImlhdCI6MTYzMTYyMzM5MH0.u4kHClCgj9KjdyHfebQn8_AnU0DlXeJX8zvJvpMLCkQ",
48+
"jwtTokenExpirySeconds": 3600
49+
}
4550
}

docs/docs.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
22
// This file was generated by swaggo/swag at
3-
// 2021-10-13 21:07:22.826963 +0100 WAT m=+23.737257334
3+
// 2021-10-15 12:55:36.391586 +0100 WAT m=+25.226284585
44
package docs
55

66
import (
@@ -1233,9 +1233,6 @@ var doc = `{
12331233
"models.Application": {
12341234
"type": "object",
12351235
"properties": {
1236-
"group_id": {
1237-
"type": "string"
1238-
},
12391236
"name": {
12401237
"type": "string"
12411238
},

docs/swagger.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,9 +1222,6 @@
12221222
"models.Application": {
12231223
"type": "object",
12241224
"properties": {
1225-
"group_id": {
1226-
"type": "string"
1227-
},
12281225
"name": {
12291226
"type": "string"
12301227
},

docs/swagger.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ basePath: /api/v1
22
definitions:
33
models.Application:
44
properties:
5-
group_id:
6-
type: string
75
name:
86
type: string
97
secret:

docs/v3/openapi3.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
"schemas": {
44
"models.Application": {
55
"properties": {
6-
"group_id": {
7-
"type": "string"
8-
},
96
"name": {
107
"type": "string"
118
},

docs/v3/openapi3.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ components:
22
schemas:
33
models.Application:
44
properties:
5-
group_id:
6-
type: string
75
name:
86
type: string
97
secret:

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/dgrijalva/jwt-go v3.2.0+incompatible
77
github.com/felixge/httpsnoop v1.0.2
88
github.com/getkin/kin-openapi v0.78.0
9+
github.com/getsentry/sentry-go v0.11.0 // indirect
910
github.com/ghodss/yaml v1.0.0
1011
github.com/go-chi/chi/v5 v5.0.3
1112
github.com/go-chi/render v1.0.1

0 commit comments

Comments
 (0)