thinkingdataanalytics / go-sdk Goto Github PK
View Code? Open in Web Editor NEWThinkingData SDK for Golang
License: Apache License 2.0
ThinkingData SDK for Golang
License: Apache License 2.0
这个是文档代码。
ta, err := thinkingdata.New(consumer)
这个是New 函数实现。
func New(c Consumer) TDAnalytics {
return TDAnalytics{consumer: c,
superProperties: make(map[string]interface{}),
mutex: new(sync.RWMutex)}
}
NewBatchConsumer参数问题
可以的话加一个所有参数手动指定的构造函数吧
现在这样没办法同时修改某些配置
在游戏停服时, 在main函数里 使用defer 调用 TDAnalytics::Close
函数,但是在log里发现有 panic 发生,最终定位到是这行
go-sdk/thinkingdata/consumer_log.go
Line 84 in 81f51ce
往一个close的channel里写数据导致的panic
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*LogConsumer).Add(0xc0000bb8c0, {{0xc0006220c8, 0x7}, {0x0, 0x0}, {0x2aa5e2f, 0x5}, {0xc0009e0048, 0x17}, {0x2aa64ce, ...}, ...})
......省略部分.........../github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/consumer_log.go:84 +0xb1
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*TDAnalytics).add(0x46ed720, {0xc0006220c8, 0x7}, {0x0, 0x0}, {0x2aa5e2f, 0x5}, {0x2aa64ce, 0x6}, {0x0, ...}, ...)
......省略部分.........../github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/thinkingdata.go:246 +0x33b
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*TDAnalytics).track(0xc001068000, {0xc0006220c8, 0x7}, {0x0, 0x0}, {0x2aa5e2f, 0x5}, {0x2aa64ce, 0xc00013f530}, {0x0, ...}, ...)
......省略部分.........../github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/thinkingdata.go:144 +0x21e
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*TDAnalytics).Track(0x263fde0, {0xc0006220c8, 0x2aa5c45}, {0x0, 0xc0012e77a0}, {0x2aa64ce, 0xc0012e77e0}, 0xc0012e7800)
......省略部分.........../github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/thinkingdata.go:103 +0x4b
所以这里是不是要加一个 判断,如果channel已经关闭了,后续在有数据进来 直接丢掉,或者加一些同步机制,保证不会出现提前close的情况
go module will help a lot to manage versions.
for {
flush := false
select {
case rec, ok := <-c.ch:
if !ok {
return
}
channel发现close之后直接return,buffer里面还有数据没法送,是不是就丢了
使用场景:一个客服端高频的向接收端发送数据。
通过 logbus
打日志时,如果日志类型为设置用户属性,则会报错。
原因:
#event_name
, 不管有没有值,导致logbus
检查日志格式时,报错 设置用户属性事件 不能带#event_name
解决方案:
EventName string `json:"#event_name, omitempty"`
WARNING: DATA RACE
Read at 0x00c000429660 by goroutine 73:
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*BatchConsumer).Add()
C:/Server/vendor/github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/consumer_batch.go:163 +0x43c
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*TDAnalytics).add()
C:/Server/vendor/github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/thinkingdata.go:202 +0x554
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*TDAnalytics).track()
C:/Server/vendor/github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/thinkingdata.go:108 +0x54f
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*TDAnalytics).Track()
C:/Server/vendor/github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/thinkingdata.go:82 +0x18e
Previous write at 0x00c000429660 by goroutine 18:
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.(*BatchConsumer).Flush()
C:/Server/vendor/github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/consumer_batch.go:197 +0xaa8
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.initBatchConsumer.func1()
C:/Server/vendor/github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/consumer_batch.go:151 +0x12f
Goroutine 18 (running) created at:
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.initBatchConsumer()
C:/Server/vendor/github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/consumer_batch.go:146 +0x8e5
github.com/ThinkingDataAnalytics/go-sdk/thinkingdata.NewBatchConsumerWithConfig()
C:/Server/vendor/github.com/ThinkingDataAnalytics/go-sdk/thinkingdata/consumer_batch.go:90 +0x109
Every time data is written to a file, parseTime() must be called, and the regexp in the method must be initialized.
The more data is written, the greater the cumulative consumption.
Suggest initializing regexp and processing it globally.
`
func parseTime(input []byte) string {
var re = regexp.MustCompile(`"((\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})(?:\.(\d{3}))\d*)(Z|[\+-]\d{2}:\d{2})"`)
var substitution = "\"$2 $3.$4\""
for re.Match(input) {
input = re.ReplaceAll(input, []byte(substitution))
}
return string(input)
}
`
sdk把数据写到本地文件之后, LogBus会把文件传输到服务器?LogBus是什么咋没介绍?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.