grafana / loki

Like Prometheus, but for logs.
https://grafana.com/loki
GNU Affero General Public License v3.0
23.02k stars 3.34k forks source link

Cannot index label otel object such as seviritytext #13456

Open omri-shilton opened 3 weeks ago

omri-shilton commented 3 weeks ago

Describe the bug When using otel http listener for ingesting otel logs, cannot index label objects that are not in the attribute, such as "SeverityText". Yet grafana does identify the log level correctly.

To Reproduce Steps to reproduce the behavior:

  1. Ingest logs via otel http
  2. log object does not have level attribute but has SeverityText
  3. configure
    otlp_config:
    resource_attributes:
    attributes_config:
      - action: index_label
        attributes:
          - level

    Which has no effect

Expected behavior An option to map otel objects as labels as well Environment:

Screenshots, Promtail config, or terminal output Example log object

2024-07-09T08:27:57.681Z    info    ResourceLog #0
Resource SchemaURL: 
Resource attributes:
     -> telemetry.sdk.language: Str(python)
     -> telemetry.sdk.name: Str(opentelemetry)
     -> telemetry.sdk.version: Str(1.24.0)
     -> service.name: Str(armoz-app)
     -> telemetry.auto.version: Str(0.45b0)
ScopeLogs #0
ScopeLogs SchemaURL: 
InstrumentationScope opentelemetry.sdk._logs._internal 
LogRecord #0
ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC
Timestamp: 2024-07-09 08:27:53.102534656 +0000 UTC
SeverityText: ERROR
SeverityNumber: Error(17)
Body: Str(Failed to export metrics to opentelemetry-collector.opentelemetry.svc.cluster.local:4317, error code: StatusCode.UNIMPLEMENTED)
Attributes:
     -> otelSpanID: Str(0)
     -> otelTraceID: Str(0)
     -> otelTraceSampled: Bool(false)
     -> otelServiceName: Str(armoz-app)
     -> code.filepath: Str(/home/appuser/.local/lib/python3.10/site-packages/opentelemetry/exporter/otlp/proto/grpc/exporter.py)
     -> code.function: Str(_export)
     -> code.lineno: Int(306)
Trace ID: 
Span ID: 
Flags: 0

And in Grafana

image
Jayclifford345 commented 3 weeks ago

I can confirm this as well if we take an example payload from otel:

{
  "resource": {
    "attributes": {
      "service.name": "example-service",
      "service.namespace": "example-namespace",
      "service.instance.id": "instance-12345",
      "service.version": "1.0.0",
      "host.name": "example-host",
      "host.id": "host-12345",
      "cloud.provider": "aws",
      "cloud.region": "us-west-2"
    }
  },
  "instrumentationLibrary": {
    "name": "example-logger",
    "version": "0.1.0"
  },
  "logRecords": [
    {
      "timeUnixNano": "1625241600000000000",
      "severityText": "INFO",
      "severityNumber": 9,
      "name": "example-log",
      "body": {
        "stringValue": "This is an example log message"
      },
      "attributes": {
        "http.method": "GET",
        "http.url": "https://example.com/api/resource",
        "http.status_code": 200,
        "db.system": "mysql",
        "db.statement": "SELECT * FROM users WHERE id = ?"
      },
      "traceId": "4bf92f3577b34da6a3ce929d0e0e4736",
      "spanId": "00f067aa0ba902b7",
      "flags": 1,
      "droppedAttributesCount": 0
    }
  ]
}

We only allow users to promote logRecords data to structured metadata:

    log_attributes:
        - action: structured_metadata
          attributes:
            - severityText

changing the above to

    log_attributes:
        - action: index_label
          attributes:
            - severityText

Causes Loki to fail:

level=info ts=2024-07-09T09:05:33.245743339Z caller=loki.go:506 msg="Loki stopped" running_time=21m38.185866051s
level=error ts=2024-07-09T09:05:33.509294922Z caller=main.go:70 msg="validating config" err="CONFIG ERROR: invalid limits_config config: index_label action is only supported for resource_attributes"

We should allow users to promote log attributes like severity to labels to provide better flexibility on what is indexed