Skip to content

Commit

Permalink
feature: add sentry integration and update go version in go.mod (cshu…
Browse files Browse the repository at this point in the history
…m#510)

* feature: add sentry integration and update go version in go.mod

* change configuration for sentry

* add test case for sentry-dsn configuration

* change error message
  • Loading branch information
aslamhadi authored and aslam-kumparan committed Jan 20, 2025
1 parent fe41009 commit 822d475
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG GOLANG_VERSION=1.23.3
ARG GOLANG_VERSION=1.23.4
FROM golang:${GOLANG_VERSION}-bookworm as builder

ARG VIPS_VERSION=8.16.0
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,4 +816,7 @@ Usage of imagor:
VIPS avif speed, the lowest is at 0 and the fastest is at 9 (Default 5).
-vips-strip-metadata
VIPS strips all metadata from the resulting image

-sentry-dsn
include sentry dsn to integrate imagor with sentry
```
27 changes: 27 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"crypto/sha512"
"flag"
"fmt"
"github.com/TheZeroSlave/zapsentry"
"github.com/getsentry/sentry-go"
"go.uber.org/zap/zapcore"
"runtime"
"strings"
Expand Down Expand Up @@ -153,6 +155,8 @@ func CreateServer(args []string, funcs ...Option) (srv *server.Server) {
"Enable strip query string redirection")
serverAccessLog = fs.Bool("server-access-log", false,
"Enable server access log")
sentryDsn = fs.String("sentry-dsn", "",
"Sentry DSN config")

prometheusBind = fs.String("prometheus-bind", "", "Specify address and port to enable Prometheus metrics, e.g. :5000, prom:7000")
prometheusPath = fs.String("prometheus-path", "/", "Prometheus metrics path")
Expand Down Expand Up @@ -192,6 +196,28 @@ func CreateServer(args []string, funcs ...Option) (srv *server.Server) {
}
logger = zap.Must(config.Build())
}

if len(*sentryDsn) > 0 {
err = sentry.Init(sentry.ClientOptions{
Dsn: *sentryDsn,
})
if err != nil {
fmt.Printf("sentry.Init: %s", err)
}
defer sentry.Flush(2 * time.Second)

// Add Sentry integration to zap logger
core, err := zapsentry.NewCore(zapsentry.Configuration{
Level: zapcore.ErrorLevel, // only log errors or higher levels to Sentry
EnableBreadcrumbs: true, // enable sending breadcrumbs to Sentry
BreadcrumbLevel: zapcore.InfoLevel, // at what level should we sent breadcrumbs to sentry, this level can't be higher than `Level`
}, zapsentry.NewSentryClientFromClient(sentry.CurrentHub().Client()))
if err != nil {
fmt.Printf("zapsentry integration error: %s", err)
}
logger = zapsentry.AttachCoreToLogger(core, logger)
}

return logger, *debug
}, funcs...)

Expand Down Expand Up @@ -225,5 +251,6 @@ func CreateServer(args []string, funcs ...Option) (srv *server.Server) {
server.WithLogger(logger),
server.WithDebug(*debug),
server.WithMetrics(pm),
server.WithSentry(*sentryDsn),
)
}
7 changes: 7 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ func TestBind(t *testing.T) {
assert.Equal(t, ":4567", srv.Addr)
}

func TestSentry(t *testing.T) {
srv := CreateServer([]string{
"-sentry-dsn", "https://12345@sentry.com/123",
})
assert.Equal(t, "https://12345@sentry.com/123", srv.SentryDsn)
}

func TestSignerAlgorithm(t *testing.T) {
srv := CreateServer([]string{
"-imagor-signer-type", "sha256",
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/kumparan/imagor

go 1.22.7

toolchain go1.23.1
go 1.23.4

require (
cloud.google.com/go/storage v1.47.0
github.com/TheZeroSlave/zapsentry v1.23.0
github.com/aws/aws-sdk-go v1.55.5
github.com/fsouza/fake-gcs-server v1.50.2
github.com/getsentry/sentry-go v0.30.0
github.com/johannesboyne/gofakes3 v0.0.0-20241026070602-0da3aa9c32ca
github.com/peterbourgon/ff/v3 v3.4.0
github.com/prometheus/client_golang v1.20.5
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.49.0/go.mod h1:l2fIqmwB+FKSfvn3bAD/0i+AXAxhIZjTK2svT/mgUXs=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 h1:GYUJLfvd++4DMuMhCFLgLXvFwofIxh/qOwoGuS/LTew=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0/go.mod h1:wRbFgBQUVm1YXrvWKofAEmq9HNJTDphbAaJSSX01KUI=
github.com/TheZeroSlave/zapsentry v1.23.0 h1:TKyzfEL7LRlRr+7AvkukVLZ+jZPC++ebCUv7ZJHl1AU=
github.com/TheZeroSlave/zapsentry v1.23.0/go.mod h1:3DRFLu4gIpnCTD4V9HMCBSaqYP8gYU7mZickrs2/rIY=
github.com/aws/aws-sdk-go v1.44.256/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
Expand Down Expand Up @@ -67,6 +69,10 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fsouza/fake-gcs-server v1.50.2 h1:ulrS1pavCOCbMZfN5ZPgBRMFWclON9xDsuLBniXtQoE=
github.com/fsouza/fake-gcs-server v1.50.2/go.mod h1:VU6Zgei4647KuT4XER8WHv5Hcj2NIySndyG8gfvwckA=
github.com/getsentry/sentry-go v0.30.0 h1:lWUwDnY7sKHaVIoZ9wYqRHJ5iEmoc0pqcRqFkosKzBo=
github.com/getsentry/sentry-go v0.30.0/go.mod h1:WU9B9/1/sHDqeV8T+3VwwbjeR5MSXs/6aqG3mqZrezA=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -141,6 +147,9 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/peterbourgon/ff/v3 v3.4.0 h1:QBvM/rizZM1cB0p0lGMdmR7HxZeI/ZrBWB4DqLkMUBc=
github.com/peterbourgon/ff/v3 v3.4.0/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/xattr v0.4.10 h1:Qe0mtiNFHQZ296vRgUjRCoPHPqH7VdTOrZx3g0T+pGA=
github.com/pkg/xattr v0.4.10/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU=
Expand Down
7 changes: 7 additions & 0 deletions server/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func WithDebug(debug bool) Option {
}
}

// WithSentry with sentry option
func WithSentry(dsn string) Option {
return func(s *Server) {
s.SentryDsn = dsn
}
}

// WithStartupTimeout with server startup timeout option
func WithStartupTimeout(timeout time.Duration) Option {
return func(s *Server) {
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Server struct {
CertFile string
KeyFile string
PathPrefix string
SentryDsn string
StartupTimeout time.Duration
ShutdownTimeout time.Duration
Logger *zap.Logger
Expand Down

0 comments on commit 822d475

Please sign in to comment.