Skip to content

Add structured metadata support for Loki output plugin" #1579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

error9098x
Copy link

@error9098x error9098x commented Apr 19, 2025

Signed-off-by: ProCodec 43810146+error9098x@users.noreply.github.com

What this PR does / why we need it:

Adds support for structured metadata in the Loki output plugin. This allows attaching high-cardinality data (like pod names, trace IDs, thread IDs) to log lines without using them as labels, following Loki's recommended best practices for Loki 3.0+.

The implementation adds:

  • structuredMetadata field to set key-value pairs as structured metadata
  • structuredMetadataKeys field to reference record keys for structured metadata
  • Processing logic in the Params() method to generate the proper Fluent Bit configuration
  • Test cases to verify the functionality

Which issue(s) this PR fixes:

Fixes #1551

Does this PR introduced a user-facing change?


Added support for structured metadata in Loki output plugin. Users can now configure high-cardinality data to be sent as structured metadata instead of labels.

Note: This feature requires Loki 3.0+ with schema v13 or higher, TSDB storage, and allow_structured_metadata: true in Loki configuration.

Additional documentation, usage docs, etc.:


Example usage:

apiVersion: fluentbit.fluent.io/v1alpha2
kind: ClusterOutput
metadata:
name: loki-output
spec:
match: kube.*
loki:
host: loki-gateway
port: 3100
labels:
- job=fluentbit
- environment=production
structuredMetadata:
pod: "${record['kubernetes']['pod_name']}"
      container: "${record['kubernetes']['container_name']}"
trace_id: "\${record['trace_id']}"
structuredMetadataKeys:
- level
- caller

For more info on structured metadata: https://grafana.com/docs/loki/latest/get-started/labels/structured-metadata/

Signed-off-by: ProCodec <43810146+error9098x@users.noreply.github.com>
@error9098x error9098x marked this pull request as ready for review April 19, 2025 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fluent-operator don't support set structured_metadata of loki
1 participant