feat: dataReport 增加 disabled 开关,默认关闭埋点与上报
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,15 @@ func GenerateGlobalEventID() string {
|
||||
return strings.ReplaceAll(uuid.New().String(), "-", "")
|
||||
}
|
||||
|
||||
// Enabled 当前是否允许上报:Disabled=true 或 ApiUrl 为空都视为关闭。
|
||||
func Enabled() bool {
|
||||
return !config.Disabled && strings.TrimSpace(config.ApiUrl) != ""
|
||||
}
|
||||
|
||||
func AsyncReport(eventData interface{}, retryCount int) {
|
||||
if !Enabled() {
|
||||
return
|
||||
}
|
||||
// TODO 后续可改成kafka异步处理
|
||||
godef.Go(func() {
|
||||
// 自动重试
|
||||
@@ -227,6 +235,9 @@ func JsonRawMessage(v interface{}) json.RawMessage {
|
||||
|
||||
// 批量上报事件
|
||||
func BatchReport(ctx context.Context, data interface{}) error {
|
||||
if !Enabled() {
|
||||
return nil
|
||||
}
|
||||
apiUrl := config.ApiUrl + "/api/eventTracking/batchReport.json"
|
||||
reqBody, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
||||
@@ -39,6 +39,10 @@ type sdkConfigResponse struct {
|
||||
|
||||
// StartSDKConfigCron 定时拉取 SDK 域名配置串,服务端只缓存并原样透传。
|
||||
func StartSDKConfigCron() {
|
||||
if !Enabled() {
|
||||
log.Info("dataReport disabled, skip SDK config cron")
|
||||
return
|
||||
}
|
||||
sdkConfigOnce.Do(func() {
|
||||
if err := RefreshSDKDomainConfig(); err != nil {
|
||||
log.Error("RefreshSDKDomainConfig first run fail", log.E(err))
|
||||
|
||||
@@ -12,8 +12,9 @@ type Response struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ApiUrl string `json:"apiUrl"`
|
||||
RunMod string `json:"runMod"` // 运行模式: dev/test/prod/release
|
||||
ApiUrl string `json:"apiUrl"`
|
||||
RunMod string `json:"runMod"` // 运行模式: dev/test/prod/release
|
||||
Disabled bool `json:"disabled"` // true 时跳过全部埋点上报与 SDK 配置拉取
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user