Skip to content

Commit

Permalink
Merge pull request #24 from wcodesoft/feature/add-sentry
Browse files Browse the repository at this point in the history
Adding Sentry to mosha-author-service
  • Loading branch information
walterjgsp authored Sep 9, 2023
2 parents b50b3e2 + b5f02fe commit aae7e9d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ ENV HTTP_PORT 8180
ENV GRPC_PORT 8181
ENV MONGO_DB_HOST "mongodb://localhost:27017"
ENV QUOTE_SERVICE_ADDRESS "localhost:8281"
ENV SENTRY_DSN ""
ENV SENTRY_SAMPLE_RATE "1.0"
ENV RELEASE_VERSION "dev"

WORKDIR /bin
COPY --from=builder /app/mosha-author-service/app .
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ github.com/charmbracelet/log v0.2.3 h1:YVmBhJtpGL7nW/nlf5u+SEloU8XYljxozGzZpgwIv
github.com/charmbracelet/log v0.2.3/go.mod h1:ZApwwzDbbETVTIRTk7724yQRJAXIktt98yGVMMaa3y8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/getsentry/sentry-go v0.23.0 h1:dn+QRCeJv4pPt9OjVXiMcGIBIefaTJPw/h0bZWO05nE=
github.com/getsentry/sentry-go v0.23.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk=
github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
Expand Down Expand Up @@ -45,6 +48,7 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down
28 changes: 21 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import (
mdb "github.com/wcodesoft/mosha-service-common/database"
mgrpc "github.com/wcodesoft/mosha-service-common/grpc"
mhttp "github.com/wcodesoft/mosha-service-common/http"
"github.com/wcodesoft/mosha-service-common/tracing"
"os"
"strconv"
"sync"
)

const (
defaultHttpPort = "8180"
defaultGrpcPort = "8181"
AuthorServiceName = "AuthorService"
defaultMongoHost = "mongodb://localhost:27017"
defaultDatabase = "mosha"
quoteGrpcAddress = "localhost:8281"
defaultHttpPort = "8180"
defaultGrpcPort = "8181"
AuthorServiceName = "AuthorService"
defaultMongoHost = "mongodb://localhost:27017"
defaultDatabase = "mosha"
quoteGrpcAddress = "localhost:8281"
defaultReleaseVersion = "dev"
)

func getEnv(key, fallback string) string {
Expand All @@ -30,9 +33,20 @@ func getEnv(key, fallback string) string {
func main() {
log.Printf("Starting %s", AuthorServiceName)
httpPort := getEnv("COMPONENT_PORT", defaultHttpPort)
quoteServiceAddress := getEnv("QUOTE_SERVICE_ADDRESS", quoteGrpcAddress)
mongoHost := getEnv("MONGO_DB_HOST", defaultMongoHost)
grpcPort := getEnv("GRPC_PORT", defaultGrpcPort)
quoteServiceAddress := getEnv("QUOTE_SERVICE_ADDRESS", quoteGrpcAddress)
releaseVersion := getEnv("RELEASE_VERSION", defaultReleaseVersion)

sentryDsn := getEnv("SENTRY_DSN", "__DSN__")
sentrySampleRate, err := strconv.ParseFloat(getEnv("SENTRY_SAMPLE_RATE", "1.0"), 64)
if err != nil {
sentrySampleRate = 1.0
}

if err := tracing.SetupSentry(sentryDsn, releaseVersion, AuthorServiceName, sentrySampleRate); err != nil {
log.Error("unable to setup sentry: ", err)
}

quoteGrpcClientInfo := mgrpc.ClientInfo{
Name: "QuoteService",
Expand Down

0 comments on commit aae7e9d

Please sign in to comment.