mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-12 09:05:02 +08:00
refactor: relocate sentry sdk
This commit is contained in:
@@ -28,9 +28,18 @@ const (
|
||||
ga4MeasurementID = "G-9KHR3VC2LN"
|
||||
)
|
||||
|
||||
var ga4Client *GA4Client
|
||||
var (
|
||||
ga4Client *GA4Client
|
||||
userID string
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
userID, err = machineid.ProtectedID("hrp")
|
||||
if err != nil {
|
||||
userID = uuid.NewV1().String()
|
||||
}
|
||||
|
||||
// init GA4 client
|
||||
ga4Client = NewGA4Client(ga4MeasurementID, ga4APISecret)
|
||||
}
|
||||
@@ -50,11 +59,6 @@ func NewGA4Client(measurementID, apiSecret string, debug ...bool) *GA4Client {
|
||||
dbg = debug[0]
|
||||
}
|
||||
|
||||
userID, err := machineid.ProtectedID("hrp")
|
||||
if err != nil {
|
||||
userID = uuid.NewV1().String()
|
||||
}
|
||||
|
||||
return &GA4Client{
|
||||
measurementID: measurementID,
|
||||
apiSecret: apiSecret,
|
||||
|
||||
@@ -1,51 +1,18 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/rs/zerolog/log"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
|
||||
const (
|
||||
trackingID = "UA-114587036-1" // Tracking ID for Google Analytics
|
||||
sentryDSN = "https://cff5efc69b1a4325a4cf873f1e70c13a@o334324.ingest.sentry.io/6070292"
|
||||
)
|
||||
|
||||
var gaClient *GAClient
|
||||
|
||||
func init() {
|
||||
// init GA client
|
||||
clientID, err := machineid.ProtectedID("hrp")
|
||||
if err != nil {
|
||||
clientID = uuid.NewV1().String()
|
||||
}
|
||||
gaClient = NewGAClient(trackingID, clientID)
|
||||
|
||||
// init sentry sdk
|
||||
if env.DISABLE_SENTRY == "true" {
|
||||
return
|
||||
}
|
||||
err = sentry.Init(sentry.ClientOptions{
|
||||
Dsn: sentryDSN,
|
||||
Release: fmt.Sprintf("httprunner@%s", version.VERSION),
|
||||
AttachStacktrace: true,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("init sentry sdk failed!")
|
||||
return
|
||||
}
|
||||
sentry.ConfigureScope(func(scope *sentry.Scope) {
|
||||
scope.SetLevel(sentry.LevelError)
|
||||
scope.SetUser(sentry.User{
|
||||
ID: clientID,
|
||||
})
|
||||
})
|
||||
gaClient = NewGAClient(trackingID, userID)
|
||||
}
|
||||
|
||||
func SendEvent(e IEvent) error {
|
||||
|
||||
37
hrp/internal/sdk/sentry.go
Normal file
37
hrp/internal/sdk/sentry.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
|
||||
const (
|
||||
sentryDSN = "https://cff5efc69b1a4325a4cf873f1e70c13a@o334324.ingest.sentry.io/6070292"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// init sentry sdk
|
||||
if env.DISABLE_SENTRY == "true" {
|
||||
return
|
||||
}
|
||||
err := sentry.Init(sentry.ClientOptions{
|
||||
Dsn: sentryDSN,
|
||||
Release: fmt.Sprintf("httprunner@%s", version.VERSION),
|
||||
AttachStacktrace: true,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("init sentry sdk failed!")
|
||||
return
|
||||
}
|
||||
sentry.ConfigureScope(func(scope *sentry.Scope) {
|
||||
scope.SetLevel(sentry.LevelError)
|
||||
scope.SetUser(sentry.User{
|
||||
ID: userID,
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user