fluent-bit icon indicating copy to clipboard operation
fluent-bit copied to clipboard

opentelemetry output - logs_body_key_attributes does not append to existing log attributes

Open ryn9 opened this issue 6 months ago • 6 comments

Bug Report

Describe the bug When using opentelemetry output, the option logs_body_key_attributes does not append to existing log attributes

To Reproduce Try this config:

service:
  flush: 1
  daemon: off
  log_level: warn
  http_server: off

pipeline:
  inputs:
    - name: opentelemetry
      port: 4318
      logs_body_key: body
      processors:
        logs:
          - name: lua
            match: "*"
            time_as_table: true
            script: scripts/add_test_field.lua
            call: add_test_field
  outputs:
    - name: stdout
      match: "*"
      format: json_lines
    - name: opentelemetry
      match: "*"
      host: otel-collector
      port: 4318
      retry_limit: false
      log_response_payload: false
      tls: off
      tls.verify: off
      logs_body_key: body
      logs_body_key_attributes: true

add_test_field is defined as:

function add_test_field(tag, timestamp, record)
    record["new_field"] = "This is a new field from Lua"
    return 1, timestamp, record
end

The output to std-out shows the new_field being created. The output to the upstream otel collector is not getting new_field appended to the log attributes

Expected behavior The output to the upstream otel collector should get new_field appended to the log attributes

Your Environment

Version used: 4.0.4 / Branch: lua-add-group-metadata-support Configuration: See above Environment name and version (e.g. Kubernetes? What version?): N/A Server type and version: N/A Operating System and version: N/A Filters and plugins: Lua

Additional context

ryn9 avatar Jun 06 '25 17:06 ryn9

My hacky work around for now...

nest all the fields under 'body' and then under the OTEL collector sort it out.

As 'nest' is currently has issues with retaining the metadata, I will perform a nesting operation with lua using the 'lua-add-group-metadata-support' branch. I am not sure when the fix to lua (or other filters) will make it to release. reference: https://github.com/fluent/fluent-bit/issues/10442#issuecomment-2950161595

the lua function:

function nest_under_body(tag, timestamp, record)
    local new_record = {}
    new_record["body"] = record
    return 1, timestamp, new_record
end

on the OTEL collector side:

  transform/nested_body_and_attributes:
    error_mode: ignore
    log_statements:
      - context: log
        statements:
          - set(cache["body"], log.body["body"])
          - delete_key(log.body, "body")
          - merge_maps(attributes, log.body, "upsert")
          - set(log.body, cache["body"])
          - delete_key(cache, "body")

ryn9 avatar Jun 06 '25 18:06 ryn9

Lua fix was already merged, release will be mid next week

edsiper avatar Jun 06 '25 23:06 edsiper

Thank you so much for quickly looking at these issues! Please let me know if you need me to provide any additional clarity to to comments.

ryn9 avatar Jun 07 '25 00:06 ryn9

Eagerly waiting for this release with #10444 fix, as soon as it is out I will be using it in my environment :)

KoushikBSK avatar Jun 10 '25 01:06 KoushikBSK

For clarity - this reported issue does not actually have anything to do with the lua filter specifically.

What I am calling out is that the opentelemetry output logs_body_key_attributes does not append to existing log attributes.

That is - if there are already log attributes in the envelopte/metadata, the logs_body_key_attributes does not appear to do anything.

ryn9 avatar Jun 10 '25 13:06 ryn9

Yes I agree (have no interest on logs_body_key_attributes ) and I was mainly highlighting (@edsiper )Eduardo's comment about the release time being this week :) I am keenly waiting to get the new realease with the lua fix to test in my environment.

KoushikBSK avatar Jun 13 '25 00:06 KoushikBSK

Fix: https://github.com/fluent/fluent-bit/pull/10562

edsiper avatar Jul 09 '25 02:07 edsiper