|
7 | 7 | "io/ioutil"
|
8 | 8 | "os"
|
9 | 9 | "path/filepath"
|
| 10 | + "reflect" |
10 | 11 | "runtime"
|
11 | 12 | "strconv"
|
12 | 13 | "strings"
|
@@ -180,6 +181,8 @@ func init() {
|
180 | 181 | gob.Register(RemoteFileInfo{})
|
181 | 182 | gob.Register(Client{})
|
182 | 183 | gob.Register(sentry.TraceID{})
|
| 184 | + gob.Register(sentry.SpanID{}) |
| 185 | + gob.Register(QueuePosting{}) |
183 | 186 | }
|
184 | 187 |
|
185 | 188 | // AgentOption allows setting custom parameters during construction
|
@@ -948,6 +951,32 @@ func itemBuilder() interface{} {
|
948 | 951 | return &QueuePosting{}
|
949 | 952 | }
|
950 | 953 |
|
| 954 | +// Helper function to dynamically register a type with Gob |
| 955 | +func registerType(obj interface{}) { |
| 956 | + typ := reflect.TypeOf(obj) |
| 957 | + if typ.Kind() == reflect.Ptr { |
| 958 | + typ = typ.Elem() // Dereference pointer type |
| 959 | + } |
| 960 | + gob.Register(obj) |
| 961 | + fmt.Printf("Registered type: %s\n", typ.Name()) |
| 962 | +} |
| 963 | + |
| 964 | +func encodeData(data interface{}) ([]byte, error) { |
| 965 | + var buf bytes.Buffer |
| 966 | + enc := gob.NewEncoder(&buf) |
| 967 | + err := enc.Encode(data) |
| 968 | + if err != nil { |
| 969 | + return nil, err |
| 970 | + } |
| 971 | + return buf.Bytes(), nil |
| 972 | +} |
| 973 | + |
| 974 | +func decodeData(data []byte, obj interface{}) error { |
| 975 | + buf := bytes.NewBuffer(data) |
| 976 | + dec := gob.NewDecoder(buf) |
| 977 | + return dec.Decode(obj) |
| 978 | +} |
| 979 | + |
951 | 980 | func (a *Client) openQueue(ctx context.Context) (chan *QueuePosting, *dque.DQue, error) {
|
952 | 981 | q, err := dque.NewOrOpen("event-queue", a.basePath, 500, itemBuilder)
|
953 | 982 | queuePath := a.basePath + "/event-queue"
|
@@ -979,8 +1008,17 @@ func (a *Client) openQueue(ctx context.Context) (chan *QueuePosting, *dque.DQue,
|
979 | 1008 | if err = q.Enqueue(msg); err == nil {
|
980 | 1009 | AgentCollector.Enqueue(a)
|
981 | 1010 | } else {
|
982 |
| - a.logger.Error("enqueueItem", zap.Any("agentId", a.AgentID), zap.Any("item", msg), zap.Error(err)) |
983 |
| - AgentCollector.SetQueueSize(a, q.Size()) |
| 1011 | + if strings.Contains(err.Error(), "gob: type not registered") { |
| 1012 | + a.logger.Info("enqueueItem - late register type", zap.Any("agentId", a.AgentID), zap.Any("item", msg), zap.String("cause", err.Error())) |
| 1013 | + registerType(msg) |
| 1014 | + if err = q.Enqueue(msg); err == nil { |
| 1015 | + AgentCollector.Enqueue(a) |
| 1016 | + } |
| 1017 | + } |
| 1018 | + if err != nil { |
| 1019 | + a.logger.Error("enqueueItem", zap.Any("agentId", a.AgentID), zap.Any("item", msg), zap.Error(err)) |
| 1020 | + AgentCollector.SetQueueSize(a, q.Size()) |
| 1021 | + } |
984 | 1022 | }
|
985 | 1023 | }
|
986 | 1024 | if ctx.Err() != nil {
|
|
0 commit comments