Skip to content

Commit

Permalink
Merge pull request #10 from Gustavobelfort/feat/logstash-sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Belfort authored May 11, 2020
2 parents 165d451 + df90c47 commit 4a7a7fe
Show file tree
Hide file tree
Showing 17 changed files with 732 additions and 34 deletions.
14 changes: 10 additions & 4 deletions cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/getsentry/sentry-go"
"github.com/gustavobelfort/42-jitsi/internal/config"
"github.com/gustavobelfort/42-jitsi/internal/consumers"
"github.com/gustavobelfort/42-jitsi/internal/consumers/router"
Expand All @@ -19,14 +21,18 @@ import (
func init() {
config.AddRequired("intra.app_id", "intra.app_secret", "intra.webhooks")
if err := config.Initiate(); err != nil {
logrus.Fatalf("could not load configuration: %v", err)
logrus.WithError(err).Fatalf("could not load configuration: %v", err)
}
logging.Initiate()
if err := db.Init(); err != nil {
logrus.Fatalf("could not connect to the db: %v", err)
logrus.WithError(err).Fatalf("could not connect to the db: %v", err)
}
}

func main() {
if hub := sentry.CurrentHub(); hub.Client() != nil {
defer hub.Flush(time.Second * 5)
}
server := &http.Server{
Addr: config.Conf.HTTPAddr,
ReadTimeout: config.Conf.Timeout * 2,
Expand All @@ -36,7 +42,7 @@ func main() {

client, err := intra.NewClient(config.Conf.Intra.AppID, config.Conf.Intra.AppSecret, http.DefaultClient)
if err != nil {
logrus.Fatalf("could not initiate intra api client: %v", err)
logrus.WithError(err).Fatalf("could not initiate intra api client: %v", err)
}

hdl := handler.NewScaleTeamHandler(client, db.GlobalDB)
Expand All @@ -58,7 +64,7 @@ func waitForShutdown(consumer consumers.Consumer) {
logrus.Info(err)
return
}
logrus.Error(err)
logrus.WithError(err).Error(err)
}
}()
<-interruptChan
Expand Down
6 changes: 6 additions & 0 deletions cmd/rabbit/rabbit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/getsentry/sentry-go"
"github.com/gustavobelfort/42-jitsi/internal/config"
"github.com/gustavobelfort/42-jitsi/internal/consumers"
amqp2 "github.com/gustavobelfort/42-jitsi/internal/consumers/amqp"
Expand All @@ -21,12 +23,16 @@ func init() {
if err := config.Initiate(); err != nil {
logrus.Fatalf("could not load configuration: %v", err)
}
logging.Initiate()
if err := db.Init(); err != nil {
logrus.Fatalf("could not connect to the db: %v", err)
}
}

func main() {
if hub := sentry.CurrentHub(); hub.Client() != nil {
defer hub.Flush(time.Second * 5)
}
client, err := intra.NewClient(config.Conf.Intra.AppID, config.Conf.Intra.AppSecret, http.DefaultClient)
if err != nil {
logrus.Fatalf("could not initiate intra api client: %v", err)
Expand Down
30 changes: 30 additions & 0 deletions configs/configs.sample.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
##
# General configuration (mostly used by logs)
##
environment: development
service: 42-jitsi

##
# Log configuration
##
log_level: debug
# -- sentry configuration
sentry:
dsn: https://identifier@sentry.com/projectid
levels:
- error
- fatal
- panic
enabled: no
# -- logstash configuration
logstash:
host: localhost
port: 5000
protocol: tcp
levels:
- info
- warning
- error
- fatal
- panic

##
# SlackThat configuration
##
Expand Down
18 changes: 18 additions & 0 deletions configs/example.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
##
# General configuration (mostly used by logs)
##
ENVIRONMENT=development
SERVICE=42-jitsi

##
# Log configuration
##
LOG_LEVEL=debug
# -- sentry configuration
SENTRY_DSN=https://identifier@sentry.com/projectid
SENTRY_LEVELS=error,fatal,panic
SENTRY_ENABLED=false
# -- logstash configuration
LOGSTASH_HOST=localhost
LOGSTASH_PORT=5000
LOGSTASH_PROTOCOL=tcp
LOGSTASH_LEVELS=info,warning,error,fatal,panic
# Docker Configuration
##
JITSI42_CONSUMER_TYPE=api
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ go 1.13

require (
github.com/DATA-DOG/go-sqlmock v1.4.1
github.com/bshuster-repo/logrus-logstash-hook v0.0.0-20190911164539-b3d898b5138a
github.com/getsentry/sentry-go v0.6.0
github.com/gin-gonic/gin v1.6.2
github.com/golang/protobuf v1.4.0 // indirect
github.com/jinzhu/gorm v1.9.12
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/lib/pq v1.3.0 // indirect
github.com/magiconair/properties v1.8.1
github.com/mitchellh/mapstructure v1.1.2
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/sirupsen/logrus v1.5.0
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/spf13/viper v1.6.2
github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
golang.org/x/sys v0.0.0-20200428200454-593003d681fa // indirect
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 // indirect
)
Loading

0 comments on commit 4a7a7fe

Please sign in to comment.