Skip to content

Commit

Permalink
Merge pull request #22 from axiomhq/islam/axm-1768-feat-parse-log-lin…
Browse files Browse the repository at this point in the history
…es-before-sending-to-axiom-on-lambda

feat: Parse log lines before sending to Axiom
  • Loading branch information
dasfmi authored Oct 17, 2023
2 parents 1ff8f14 + a3bdce4 commit 11817ea
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"
"net/http"
"regexp"
"strings"

"os"
"strconv"
Expand Down Expand Up @@ -36,6 +38,8 @@ var (
axiomMetaInfo = map[string]string{}
)

var logLineRgx, _ = regexp.Compile(`^([0-9.:TZ-]{20,})\s+([0-9a-f-]{36})\s+(ERROR|INFO|WARN|DEBUG)\s+(.*)`)

func init() {
logger, _ = zap.NewProduction()

Expand Down Expand Up @@ -86,6 +90,16 @@ 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" {
// parse the record
matches := logLineRgx.FindStringSubmatch(e["record"].(string))
if len(matches) == 5 {
e["message"] = matches[4]
e["record"] = map[string]any{"requestId": matches[2], "message": e["record"], "timestamp": matches[1]}
e["level"] = strings.ToLower(matches[3])
}
}

// decide if the handler should notify the extension that the runtime is done
if e["type"] == "platform.runtimeDone" && !firstInvocationDone {
notifyRuntimeDone = true
Expand Down

0 comments on commit 11817ea

Please sign in to comment.