Search code examples
grafanagrafana-loki

No detected fields in grafana


I have a project with the opentelemetry packages that sends the logs to a opentelemetry collector which stores them in Loki. Everything seems to work fine except that there's no detected fields.

Is there any setting I could have missed?

logs


Solution

  • By default, neither Grafana, nor Loki parse your JSON into labels*.

    But you can do it easily yourself within the query:

    {app="foo"} | json
    

    This will parse JSON object stored in the log message into labels.

    Not that names of fields will be sanitized and nested objects will be extracted:

    For instance, the pipeline | json will produce the following mapping:

    { "a.b": {c: "d"}, e: "f" }
    

    ->

    {a_b_c="d", e="f"}
    

    See additional considerations regarding nested objects and label names here.

    Additionally, there are some additional considerations on support for arrays and simultaneous parsing and renaming of fields described here.


    * : This kind of parsing can also happen on the exporter's side, but it is advised not to. Such approach, especially with JSON, will lead to extreme growth of cardinality and sequential loses in performance of Loki.