mirror of
https://github.com/elyby/accounts-profiles-endpoint.git
synced 2024-12-22 04:59:58 +05:30
Enable Sentry profiling (without it doesn't send traces)
This commit is contained in:
parent
2eda0caf55
commit
ca840c1cc5
@ -6,15 +6,17 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/etherlabsio/healthcheck/v2"
|
"github.com/etherlabsio/healthcheck/v2"
|
||||||
|
"github.com/getsentry/sentry-go"
|
||||||
sentrygin "github.com/getsentry/sentry-go/gin"
|
sentrygin "github.com/getsentry/sentry-go/gin"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"go.uber.org/multierr"
|
"go.uber.org/multierr"
|
||||||
|
|
||||||
db "ely.by/accounts-profiles-endpoint/internal/db/mysql"
|
db "ely.by/accounts-profiles-endpoint/internal/db/mysql"
|
||||||
"ely.by/accounts-profiles-endpoint/internal/http"
|
"ely.by/accounts-profiles-endpoint/internal/http"
|
||||||
"ely.by/accounts-profiles-endpoint/internal/logging/sentry"
|
sentryLogging "ely.by/accounts-profiles-endpoint/internal/logging/sentry"
|
||||||
"ely.by/accounts-profiles-endpoint/internal/services/chrly"
|
"ely.by/accounts-profiles-endpoint/internal/services/chrly"
|
||||||
"ely.by/accounts-profiles-endpoint/internal/services/signer"
|
"ely.by/accounts-profiles-endpoint/internal/services/signer"
|
||||||
)
|
)
|
||||||
@ -26,7 +28,7 @@ func Serve() error {
|
|||||||
ctx, _ = signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM, os.Kill)
|
ctx, _ = signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM, os.Kill)
|
||||||
|
|
||||||
var errors, err error
|
var errors, err error
|
||||||
err = sentry.InitWithConfig(config)
|
err = sentryLogging.InitWithConfig(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to initialize Sentry: %w", err)
|
return fmt.Errorf("unable to initialize Sentry: %w", err)
|
||||||
}
|
}
|
||||||
@ -52,7 +54,7 @@ func Serve() error {
|
|||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.Use(sentrygin.New(sentrygin.Options{Repanic: true}))
|
r.Use(sentrygin.New(sentrygin.Options{Repanic: true}))
|
||||||
r.Use(sentry.ErrorMiddleware())
|
r.Use(sentryLogging.ErrorMiddleware())
|
||||||
r.Use(http.ErrorMiddleware())
|
r.Use(http.ErrorMiddleware())
|
||||||
|
|
||||||
r.GET("/healthcheck", gin.WrapH(healthcheck.Handler(
|
r.GET("/healthcheck", gin.WrapH(healthcheck.Handler(
|
||||||
@ -72,5 +74,7 @@ func Serve() error {
|
|||||||
return fmt.Errorf("unable to start a server: %w", err)
|
return fmt.Errorf("unable to start a server: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sentry.Flush(2 * time.Second)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package sentry
|
package sentry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
sentryGin "github.com/getsentry/sentry-go/gin"
|
sentryGin "github.com/getsentry/sentry-go/gin"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -12,6 +14,7 @@ import (
|
|||||||
func InitWithConfig(config *viper.Viper) error {
|
func InitWithConfig(config *viper.Viper) error {
|
||||||
config.SetDefault("sentry.enable_tracing", false)
|
config.SetDefault("sentry.enable_tracing", false)
|
||||||
config.SetDefault("sentry.traces_sample_rate", 1.0)
|
config.SetDefault("sentry.traces_sample_rate", 1.0)
|
||||||
|
config.SetDefault("sentry.profiles_sample_rate", 1.0)
|
||||||
|
|
||||||
sampleRate := config.GetFloat64("sentry.traces_sample_rate")
|
sampleRate := config.GetFloat64("sentry.traces_sample_rate")
|
||||||
|
|
||||||
@ -19,14 +22,15 @@ func InitWithConfig(config *viper.Viper) error {
|
|||||||
Dsn: viper.GetString("sentry.dsn"),
|
Dsn: viper.GetString("sentry.dsn"),
|
||||||
EnableTracing: viper.GetBool("sentry.enable_tracing"),
|
EnableTracing: viper.GetBool("sentry.enable_tracing"),
|
||||||
TracesSampler: func(ctx sentry.SamplingContext) float64 {
|
TracesSampler: func(ctx sentry.SamplingContext) float64 {
|
||||||
if ctx.Span.Name == "GET /healthcheck" {
|
if !strings.Contains(ctx.Span.Name, "/api") {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return sampleRate
|
return sampleRate
|
||||||
},
|
},
|
||||||
Release: version.Version(),
|
ProfilesSampleRate: config.GetFloat64("sentry.profiles_sample_rate"),
|
||||||
Environment: config.GetString("sentry.environment"),
|
Release: version.Version(),
|
||||||
|
Environment: config.GetString("sentry.environment"),
|
||||||
Integrations: func(integrations []sentry.Integration) []sentry.Integration {
|
Integrations: func(integrations []sentry.Integration) []sentry.Integration {
|
||||||
nDeleted := 0
|
nDeleted := 0
|
||||||
for i, integration := range integrations {
|
for i, integration := range integrations {
|
||||||
|
Loading…
Reference in New Issue
Block a user