Unable to add extra structured metadata as label

I am using Loki v3.4.2 and Grafana 11.5.1 to receive logs from an Open Telemetry Collector.

I am sending logs as structured metadata and want to add some extra fields from my log messages to show as labels in Grafana.

I have tried a number of different ways including reviewing the documentation here: Ingesting logs to Loki using OpenTelemetry Collector | Grafana Loki documentation as well as several other posts and am unable to resolve this.

My loki config has consisted of various versions of the following:

limits_config:
  allow_structured_metadata: true
  otlp_config:
    resource_attributes:
      attributes_config:
        - action: index_label
          attributes:
            - service.group
    log_attributes:
      - action: structured_metadata
        attributes:
            - Alias

I’ve tried putting the attribute under resource_attributes, in the same group as service.group, as a separate group. I’ve also tried setting the default_resource_attributes_as_index_labels value as well.

distributor:
  otlp_config:
    default_resource_attributes_as_index_labels: ["Alias", "service.group"]

The log message I’m sending to Loki looks as follows:

2025-02-19T16:22:29 ScopeLogs SchemaURL: 
2025-02-19T16:22:29 InstrumentationScope  
2025-02-19T16:22:29 LogRecord #0
2025-02-19T16:22:29 ObservedTimestamp: 2025-02-19 06:22:26.3524881 +0000 UTC
2025-02-19T16:22:29 Timestamp: 2025-02-19 06:22:26.3524881 +0000 UTC
2025-02-19T16:22:29 SeverityText: Warning
2025-02-19T16:22:29 SeverityNumber: Warn(13)
2025-02-19T16:22:29 Body: Str(Test)
2025-02-19T16:22:29 Attributes:
2025-02-19T16:22:29      -> Alias: Str(MAIN)
2025-02-19T16:22:29 Trace ID: 
2025-02-19T16:22:29 Span ID: c8dbaca31e6a3b9b
2025-02-19T16:22:29 Flags: 0

So it appears like the attribute is there. In Grafana, I can see the Alias attribute as a line in the log record, but it doesn’t appear in the label drop down. I’m not sure where to go from here, the documentation on this is very unclear.

Documentation is clear. It is for RESOURCE atrribute and you are not sending RESOURCE attributes - there is only log line atrribute in your example. Fix that one and it will be working.

In that case why does setting log_attributes not work? In previous versions I was able to promote normal attributes to labels in the otel collector, is this no longer possible? The migration steps talk about a centrally managed list of attributes.

I don’t know.
No.

Does that mean we’ve lost a feature that used to be possible? Indexing attributes as labels seems like a common use case.

I worked it out. The answer is to use the Otel transform processor to set a resource attribute based on a log attribute:

  transform:
    error_mode: ignore
    log_statements:
        - set(resource.attributes["Alias"], log.attributes["Alias"])

Common use case and common problem for administrator. Typical user will index everything (hard cardinality data included), because everything is important - it will be admin/infra/cost problem to deal with it.

So it is win from admin perspective: user doesn’t have an option to make a mess and admin has obtained an option to enforce some (good) label hygiene.

That’s one option from many. You can generate resources atttribute at the log source properly, so then you don’t need any fidling with attributes on the collector side.