serilog-sinks-grafana-loki icon indicating copy to clipboard operation
serilog-sinks-grafana-loki copied to clipboard

Add support for actual structured metadata

Open oliver-unifii opened this issue 11 months ago • 1 comments

It appears this library doesn't actually support structured logging, instead it formats log lines into nested JSON message and then relies on json parser within loki to allow filtering.

As per Loki HTTP documentation to add structured logs one can append them as last item to log line array: https://grafana.com/docs/loki/latest/reference/api/#push-log-entries-to-loki

That will produce structured metadata as per https://grafana.com/docs/loki/latest/get-started/labels/structured-metadata/

Looking through the sourcecode it seems this library only serialises timestamp and message: https://github.com/serilog-contrib/serilog-sinks-grafana-loki/blob/7ce732477a0a8f7dd713fff44b561f15dad4a9a0/src/Serilog.Sinks.Grafana.Loki/Models/LokiStream.cs#L31

oliver-unifii avatar Mar 06 '24 03:03 oliver-unifii

Hi,

You define what properties of log entry should be added as labels with propertiesAsLabels setting. Other data as you mentioned is serialized as a JSON and relies on JSON parser for querying. That was the concept over time to avoid the high cardinality problems, but give the possibility to query the data.

The concept of structured metadata was added later and it's a good extension point IMO.

For now I see the conceptual point to be solved:

  • [ ] Should it be added to V8
  • [ ] Design the architectural part & API (give the user possibility to define the metadata fields etc)
  • [ ] Ensure it will be a valid payload for older Loki version (or get the default optional configuration)

mishamyte avatar Mar 06 '24 08:03 mishamyte