Promtail configuration

Hi Grafana Community,

I am configuring Loki and I got stuck in the Promtail yaml configuration file. I have a label that can get a wide range of values, but I still have to keep it in the log line for the analysis on Grafana. Hence, my idea is to drop that label from the labelk defined in the static config and integrate it into the log line so that Loki can get it as “Detected filed”.

The config-promtail.yml looks like this:

  - job_name: promtail
    - json:
          level: level
          timestamp: '"@timestamp"'
    - labels:
    - labeldrop:
      - hostname
    - template:
        source: message
        template: '{{ omit (mustFromJson .Entry) "a_filed" "@timestamp" "@another_filed" | mustToJson }}' 
    - output:
        source: message
    - targets:
      - localhost
        hostname: host

The stage “pack” does not suit my problem, but I was thinking of another template stage where I redefine hostname and then I add it into .Entry

Any advice? Thank you very much, I’d appreciate your help a lot!

I am using grafana 9.2.0, loki 3.0.1 and promtail 2.5.0