-
Hello, we have enabled agent in our own cluster, and I have enabled the faro-web-sdk on the client side. It is sending the logs as JSON strings. I would like to use the River function Here's the River config for the agent:
Here's a sample of what a log message ends up looking like in Grafana/Loki: You can see the three Considering that the JSON content of the log {
"0": "testing faro",
"_meta": {
"runtime": "Browser",
"browser": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"name": "index.tsx",
"parentNames": [
"bridge"
],
"date": "2024-02-04T18:08:30.160Z",
"logLevelId": 3,
"logLevelName": "INFO",
"path": {
"fullFilePath": "https://localhost:4200/build/chunks/chunk-WBYRT6AL.js",
"fileName": "chunk-WBYRT6AL.js",
"fileNameWithLine": "chunk-WBYRT6AL.js:2994",
"fileColumn": "18",
"fileLine": "2994",
"filePath": "/build/chunks/chunk-WBYRT6AL.js",
"filePathWithLine": "/build/chunks/chunk-WBYRT6AL.js:2994"
}
}
} Would I need to do something like the following, if I wanted to add, let's say the
Also, I read the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Following river script should meet your need. Note that I use multiple pipelines to process the faro SDK log. logging {
level = "debug"
format = "logfmt"
}
faro.receiver "default" {
server {
listen_address = "0.0.0.0"
listen_port = "12347"
cors_allowed_origins = ["*"]
}
extra_log_labels = {
app_name = "frontend",
app_environment = "dev",
source = "faro-sdk",
}
output {
logs = [loki.process.logfmt.receiver]
}
}
loki.process "logfmt" {
forward_to = [loki.process.json.receiver]
stage.match {
selector = "{app_name=\"frontend\"}"
stage.logfmt {
mapping = { "kind" = ""}
}
stage.match {
selector = "{kind=\"log\"}"
stage.logfmt {
mapping = { "message" = "" }
}
stage.json {
source = "message"
expressions = {name = "_meta.name"}
}
stage.labels {
values = {
name = "",
}
}
}
stage.labels {
values = {
kind = "",
}
}
}
}
loki.process "json" {
forward_to = [loki.echo.echo.receiver, loki.write.local_loki.receiver]
stage.match {
selector = "{kind=\"log\"}"
stage.logfmt {
mapping = { "message" = "" }
}
stage.json {
source = "message"
expressions = {name = "_meta.name"}
}
stage.labels {
values = {
name = "",
}
}
}
}
loki.echo "echo" {
}
loki.write "local_loki" {
endpoint {
url = "http://gateway:3100/loki/api/v1/push"
}
} |
Beta Was this translation helpful? Give feedback.
-
Thanks @titaneric -- also dropping this Slack chan response in here as it may prove useful info for anyone else looking to do similar: |
Beta Was this translation helpful? Give feedback.
Following river script should meet your need.
Note that I use multiple pipelines to process the faro SDK log.
First, I add additional labels for faro SDK with
app_name
,app_environment
, andsource
.Then, I match
app_name="frontend"
and extractkind
into new labels.At last, I match
kind="log"
to extract your JSON message, and extract to new labels, too.