grafana / alloy

OpenTelemetry Collector distribution with programmable pipelines
https://grafana.com/oss/alloy
Apache License 2.0
1.42k stars 210 forks source link

Remapping otelcol.receiver.otlp logs labels to export to otelcol.exporter.otlphttp Loki #1879

Open avramenkovladyslav opened 1 month ago

avramenkovladyslav commented 1 month ago

What's wrong?

We're trying to remap the Loki labels with alloy, but it doesn't work

Steps to reproduce

Using configuration below and simple .NET application with opentelemetry logs output, the fields are not created with the action insert and from_attribute. In the meantime if we set static data like this:

    action {
        action = "insert"
        key = "application"
        value = "test value"
    }

it works

I used debug mode in alloy to see the actual fields before Loki transforming it, and there is a field service.name, so it's not a typo. Loki is transforming some fields with capital letter or ".", but it's not the cause in our case Is there any other way to map the fields for Loki labels?

Software version

Alloy v1.3.1 Helm chart version 0.7.0

Configuration

otelcol.receiver.otlp "grpc" {
  grpc {}

  output {
    logs  = [otelcol.processor.attributes.loki_labels.input]
  }
}

otelcol.processor.attributes "loki_labels" {
    action {
        action = "insert"
        key = "application"
        from_attribute = "service.name"
    }
    action {
        action = "insert"
        key = "level"
        from_attribute = "SeverityText"
    }
    output {
        logs  = [otelcol.exporter.otlphttp.loki.input]
    }
}

otelcol.exporter.otlphttp "loki" {
  client {
    endpoint = "http://loki-gateway.metrics.svc.cluster.local:80"
    tls {
      insecure_skip_verify = true
      insecure = true
    }
  }
  logs_endpoint = "http://loki-gateway.metrics.svc.cluster.local:80/otlp/v1/logs"
}

Logs

Output fields in Loki query:

detected_level  
error
exception_message   
exception_stacktrace    
exception_type  
FormatException
flags   
observed_timestamp  
scope_name  
service_instance_id 
service_name    
severity_number 
severity_text   
span_id 
telemetry_sdk_language  
telemetry_sdk_name  
opentelemetry
telemetry_sdk_version   
trace_id    
lieberlois commented 4 days ago

@avramenkovladyslav Did you manage to solve this?

avramenkovladyslav commented 3 days ago

@avramenkovladyslav Did you manage to solve this?

Nope. Tried different ways with otelcol and loki resources, but didn't find a good solution to remap fields