TLDR
- I want to extract a field from the JSON log
- then extract value from this field via regex
- finally, add extracted value with a different key back to JSON log
Problem
I am receiving events from Grafana Faro SDK into Alloy and forwarding them to Loki in JSON format. When the event goes into loki.process
it looks like this:
{
"app_name": "main-app",
"event_name": "faro.performance.resource",
"kind": "event",
"event_data_name": "https://cdn.company.com/specific-service-name/app_v2.23131284a8251.js",
... // 20+ other fields (can be dynamic)
}
From event_data_name
I would like to extract the first path segment - specific-service-name
and append it back to JSON with the name url_group
. This must happen without modifying any other fields.
{
"app_name": "main-app",
"event_name": "faro.performance.resource",
"kind": "event",
"event_data_name": "https://cdn.company.com/specific-service-name/app_v2.23131284a8251.js",
"url_group": "specific-service-name",
... // 20+ other fields (can be dynamic)
}
For some reason, in every described solution, the extracted field is added to labels, but I want to have it message payload. Is there any way to accomplish this?