Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -814,4 +814,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
```
28 changes: 28 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"crypto/sha512"
"flag"
"fmt"
"github.com/TheZeroSlave/zapsentry"
"github.com/getsentry/sentry-go"
"go.uber.org/zap/zapcore"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -150,6 +153,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 All @@ -170,6 +175,28 @@ func CreateServer(args []string, funcs ...Option) (srv *server.Server) {
} else {
logger = zap.Must(zap.NewProduction())
}

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 @@ -203,5 +230,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 @@ -102,6 +102,13 @@ func TestBind(t *testing.T) {
assert.Equal(t, ":4567", srv.Addr)
}

func TestSentry(t *testing.T) {
srv := CreateServer([]string{
"-sentry-dsn", "https://[email protected]/123",
})
assert.Equal(t, "https://[email protected]/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/cshum/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
Loading