Harnessing the Power of Loki’s JSON Log Parsing in Grafana

To effectively use Loki’s JSON log parsing in Grafana, you need to set up your log collection agent (Promtail or Grafana Alloy). This setup will involve sending structured JSON logs to Loki. Next, you can query and extract the required fields using LogQL in Grafana.

Initially, these logs were simple plain text, often cumbersome and difficult to decode. However, as applications have grown in complexity, a more efficient way to interpret these logs has become necessary.

This is where structured logs come into play. Unlike chaotic plain text logs, structured logs organize information systematically, often using JSON format.

Now, let’s  understand logs better, especially how to decode JSON logs. We’ll utilize a tool called the JSON Loki pipeline stage to simplify the process.

{
"@timestamp": "2024-02-27T14:13:13.714+00:00",
"@version": "1",
"message": "{\"access-time\":\"2024-02-25T14:13:13.697+0000\",\"account-code\":\"viewsynergy.abc.com\",\"remote-address\":\"49.207.192.81\",\"host\":\"gt-cougar-547c68c464-vz2qp\",\"guid\":\"f53a7273-3e58-4d38-bc7a-0d95edbbfbce\",\"thread\":\"http-nio-8080-exec-12\",\"user\":-2,\"is-static-resource\":false,\"url\":\"/v2/payroll-config/income-tax-agent/calculate/7/100\",\"session-id\":\"cce324dfae80d3cfdcb63766b004dba4\"}",
"logger_name": "com.abc",
"thread_name": "pool-1-thread-1",
"level": "INFO",
"level_value": 20000,
"consumer-id": "0"
}

Continue reading “Harnessing the Power of Loki’s JSON Log Parsing in Grafana”