Skip to content

Commit

Permalink
simplify capturing requestId and message from record
Browse files Browse the repository at this point in the history
  • Loading branch information
dasfmi committed Aug 6, 2024
1 parent f266652 commit 7298da5
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,19 @@ func httpHandler(ax *flusher.Axiom, runtimeDone chan struct{}) http.HandlerFunc
requestId := ""

for _, e := range events {
// capture requestId on each start event
if rec, ok := e["record"]; ok && e["type"] == "platform.start" {
record := rec.(map[string]any)
requestId = record["requestId"].(string)
e["message"] = ""
// if reocrd key exists, extract the requestId and message from it
if rec, ok := e["record"]; ok {
if record, ok := rec.(map[string]any); ok {
// capture requestId and set it if it exists
if requestID, ok := record["requestId"]; ok {
requestId = requestID.(string)
}
if e["type"] == "function" {
// set message
e["message"] = record["message"].(string)
}
}
}

// attach the lambda information to the event
Expand All @@ -93,15 +102,12 @@ func httpHandler(ax *flusher.Axiom, runtimeDone chan struct{}) http.HandlerFunc
// replace the time field with axiom's _time
e["_time"], e["time"] = e["time"], nil

if e["type"] == "function" {
// extract the message from the record field
if rec, ok := e["record"].(map[string]any); ok {
e["message"] = rec["message"]
} else {
e["message"] = e["record"]
e["record"] = map[string]string{
"requestId": requestId,
}
// If we didn't find a message in record field, move the record to message
// and assign requestId
if e["type"] == "function" && e["message"] == "" {
e["message"] = e["record"]
e["record"] = map[string]string{
"requestId": requestId,
}
}

Expand Down

0 comments on commit 7298da5

Please sign in to comment.