opentelemetry output - logs_body_key_attributes does not append to existing log attributes
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
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")
Lua fix was already merged, release will be mid next week
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.
Eagerly waiting for this release with #10444 fix, as soon as it is out I will be using it in my environment :)
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.
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.
Fix: https://github.com/fluent/fluent-bit/pull/10562