mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 00:17:37 +08:00
refactor: relocate sentry sdk
This commit is contained in:
+10
-6
@@ -28,9 +28,18 @@ const (
|
|||||||
ga4MeasurementID = "G-9KHR3VC2LN"
|
ga4MeasurementID = "G-9KHR3VC2LN"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ga4Client *GA4Client
|
var (
|
||||||
|
ga4Client *GA4Client
|
||||||
|
userID string
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
var err error
|
||||||
|
userID, err = machineid.ProtectedID("hrp")
|
||||||
|
if err != nil {
|
||||||
|
userID = uuid.NewV1().String()
|
||||||
|
}
|
||||||
|
|
||||||
// init GA4 client
|
// init GA4 client
|
||||||
ga4Client = NewGA4Client(ga4MeasurementID, ga4APISecret)
|
ga4Client = NewGA4Client(ga4MeasurementID, ga4APISecret)
|
||||||
}
|
}
|
||||||
@@ -50,11 +59,6 @@ func NewGA4Client(measurementID, apiSecret string, debug ...bool) *GA4Client {
|
|||||||
dbg = debug[0]
|
dbg = debug[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
userID, err := machineid.ProtectedID("hrp")
|
|
||||||
if err != nil {
|
|
||||||
userID = uuid.NewV1().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
return &GA4Client{
|
return &GA4Client{
|
||||||
measurementID: measurementID,
|
measurementID: measurementID,
|
||||||
apiSecret: apiSecret,
|
apiSecret: apiSecret,
|
||||||
|
|||||||
@@ -1,51 +1,18 @@
|
|||||||
package sdk
|
package sdk
|
||||||
|
|
||||||
import (
|
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/env"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
trackingID = "UA-114587036-1" // Tracking ID for Google Analytics
|
trackingID = "UA-114587036-1" // Tracking ID for Google Analytics
|
||||||
sentryDSN = "https://cff5efc69b1a4325a4cf873f1e70c13a@o334324.ingest.sentry.io/6070292"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var gaClient *GAClient
|
var gaClient *GAClient
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// init GA client
|
// init GA client
|
||||||
clientID, err := machineid.ProtectedID("hrp")
|
gaClient = NewGAClient(trackingID, userID)
|
||||||
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,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendEvent(e IEvent) error {
|
func SendEvent(e IEvent) error {
|
||||||
|
|||||||
@@ -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