How to parse nested json in Promtail

I am having the following log which is in nested JSON

	
{"level":30,"time":1627625600625,"pid":15676,"hostname":"admin-hp-elitebook-840-g2","reqId":"req-2","req":{"method":"POST","url":"/v1/login","hostname":"127.0.0.1:3000","remoteAddress":"127.0.0.1","remotePort":55884},"msg":"incoming request"}

From that, i would like to create labels for method, URL, host i have tried the JSON expression like below in promtail

scrape_configs:
- job_name: plainlog
  pipeline_stages:
  - json:
      expressions:
        req: req
  - labels:
      req:
  - output:
      source: req
  static_configs:
  - targets:
      - localhost
    labels:
      job: plainlog
      __path__: /home/nidhin/Desktop/plainlog/*log

But it creates the label req and stores the JSON as value for the key req.Does anyone knows how to create labels from nested JSON

Hi @nidhinkumar06 did you find a solution ? same problem for me … no solution to parse a nested JSON. Some one from grafana could provide a POC please ?

I have not tried this but documentation shows an example here.

Be aware that Best practices advice against dynamic labels.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.