Struggle to add label to logs on loki deployed with helm chart

You are the only person I found having the same issues I was going through, so I suppose others will benefit of the solution:

Thanks to this post on stackoverflow:

https://stackoverflow.com/questions/63414638/promtail-ignores-extrascrapeconfigs

I was able to implement the correct solution for the exact same issue you are having.

Apparently the fact that extraScrapeConfigs is appended to the end of the configuration affects promtail ability to add custom labels. So, instead of using extraScrapeConfigs, use the pipelineStages. On loki-stack 2.2.0, this the configuration that worked for me:

promtail:
  enabled: true
  pipelineStages:
    - cri: {}
    - regex:
        expression: '^.*[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3} (?P<level>[A-Z]+)  \[\[(?P<sourcefile>.*)\]\].*'

    - labels:
        level:
        sourcefile:

I hope it helps