feat(integrations): marshal payload map

feat(db): cast payload to jsonb
This commit is contained in:
Taha Yassine Kraiem 2022-01-28 19:25:57 +01:00
parent 8b4f9c3080
commit 1224664fbb
2 changed files with 11 additions and 3 deletions

View file

@ -175,11 +175,14 @@ func (conn *Conn) InsertWebErrorEvent(sessionID uint64, projectID uint32, e *Err
errorID := hashid.WebErrorID(projectID, e)
log.Println(">>errorID")
log.Println(errorID)
log.Println(">>payload")
log.Println(e.Payload)
if err = tx.exec(`
INSERT INTO errors
(error_id, project_id, source, name, message, payload)
VALUES
($1, $2, $3, $4, $5, $6)
($1, $2, $3, $4, $5, $6::jsonb)
ON CONFLICT DO NOTHING`,
errorID, projectID, e.Source, e.Name, e.Message, e.Payload,
); err != nil {

View file

@ -130,7 +130,7 @@ func (es *elasticsearch) Request(c *client) error {
log.Println("No hits found")
break
}
log.Printf("received %d hits",len(hits))
log.Printf("received %d hits", len(hits))
for _, hit := range hits {
// Parse the attributes/fields of the document
@ -173,6 +173,11 @@ func (es *elasticsearch) Request(c *client) error {
log.Printf("Error converting token to uint46: %s\n", err)
sessionID = 0
}
payload, err := json.Marshal(source)
if err != nil {
log.Printf("Error converting source to json: %v\n", source)
continue
}
c.evChan <- &SessionErrorEvent{
//SessionID: sessionID,
SessionID: sessionID,
@ -181,7 +186,7 @@ func (es *elasticsearch) Request(c *client) error {
Source: "elasticsearch",
Timestamp: timestamp,
Name: fmt.Sprintf("%v", docID),
Payload: fmt.Sprintf("%v", source),
Payload: string(payload),
},
}
}