日志优化

This commit is contained in:
hahwu 2026-01-21 17:56:16 +08:00
parent 892b6408d3
commit 94a056c18a

View File

@ -1,6 +1,7 @@
package thinkingdata
import (
"encoding/json"
"errors"
"sync"
"time"
@ -23,19 +24,20 @@ const (
)
type Data struct {
IsComplex bool `json:"-"` // properties are nested or not
AccountId string `json:"#account_id,omitempty"`
DistinctId string `json:"#distinct_id,omitempty"`
Type string `json:"#type"`
Time string `json:"#time"`
Timestamp int64 `json:"#timestamp,omitempty"`
EventName string `json:"#event_name,omitempty"`
EventId string `json:"#event_id,omitempty"`
FirstCheckId string `json:"#first_check_id,omitempty"`
Ip string `json:"#ip,omitempty"`
UUID string `json:"#uuid,omitempty"`
AppId string `json:"#app_id,omitempty"`
Properties map[string]interface{} `json:"properties"`
IsComplex bool `json:"-"` // properties are nested or not
AccountId string `json:"#account_id,omitempty"`
DistinctId string `json:"#distinct_id,omitempty"`
Type string `json:"#type"`
Time string `json:"#time"`
Timestamp int64 `json:"#timestamp,omitempty"`
EventName string `json:"#event_name,omitempty"`
EventId string `json:"#event_id,omitempty"`
FirstCheckId string `json:"#first_check_id,omitempty"`
Ip string `json:"#ip,omitempty"`
UUID string `json:"#uuid,omitempty"`
AppId string `json:"#app_id,omitempty"`
Properties map[string]interface{} `json:"properties"`
PropertiesSummary string `json:"properties_summary,omitempty"`
}
// TDConsumer define operation interface
@ -275,26 +277,30 @@ func (ta *TDAnalytics) add(accountId, distinctId, dataType, eventName, eventId s
if len(uuid) == 0 {
uuid = generateUUID()
}
properties_summary, err := json.Marshal(properties)
if err != nil {
properties_summary = []byte{}
}
data := Data{
AccountId: accountId,
DistinctId: distinctId,
Type: dataType,
Time: eventTime,
Timestamp: time.Now().Unix(),
EventName: eventName,
EventId: eventId,
FirstCheckId: firstCheckId,
Ip: ip,
UUID: uuid,
Properties: properties,
AccountId: accountId,
DistinctId: distinctId,
Type: dataType,
Time: eventTime,
Timestamp: time.Now().Unix(),
EventName: eventName,
EventId: eventId,
FirstCheckId: firstCheckId,
Ip: ip,
UUID: uuid,
Properties: properties,
PropertiesSummary: string(properties_summary),
}
if len(appId) > 0 {
data.AppId = appId
}
err := formatProperties(&data, ta)
err = formatProperties(&data, ta)
if err != nil {
return err
}