-
What Grafana version and what operating system are you using?
11.0
-
What are you trying to achieve?
I would like to display data from Loki that has some “optional” fields in a table.
-
How are you trying to achieve it?
I use an “extract fields” transformation to convert JSON lines into fields. This works mostly fine, but …
-
What happened?
… I have an field called “error” that might be empty. If there is no value (not at all or a ‘null’) it is displayed as “Not found” in the table column. Using the debugger I could confirm that this happens in this transform. The error field is converted into a string column and the values are “Not found”.
-
What did you expect to happen?
I expect to have an option to define another default value, i.e. just use an empty string to display an empty cell. I was not able to find such an option. I found some recommendations to solve the problem in the query to the data source, but as far as I know it’s not possible for Loki. In Grafana itself I could also not find an option to specify a default value.
Could you share sample JSON and transformation that you apply?
There is not much detail I can add. The JSON formatted input log lines look like this:
{"pito_error": null, ...}
or
{"pito_error": "a stack trace", ...}
There are more top level keys with a pito_
prefix, but they don’t matter here. In the edit view of my table I select “Transform data”. The first transformation is “Extract fields” with “Source”=“Line” and “Format”=“JSON”. One of the fields has the path “pito_error” with the alias “Error”. There are similar mappings for other top level keys. They work fine because they always have a value.
For this first transformation I can select “Debug transformation”. On the left I have “Input data” where I can find the raw input lines and they look as expected, i.e. have "pito_error": null
. On the right I have “Output data” where I can find the extracted “Error” column. It contains strings with the value “Not Found”.
So the transformation into “Not Found” obviously happens in this step. Instead of “Not Found” I would like to have an empty string.
Found out that it happens only when Alias is used:
In this case Not Found could be replaced by configuring Value mappings to an invisible character (i.e. from here):