Add support to set otel fields from the event body based on keys. Sig…#8644
Add support to set otel fields from the event body based on keys. Sig…#8644edsiper merged 2 commits intofluent:masterfrom
Conversation
4bfcc6b to
02b1a89
Compare
|
Thank you for working on this. I was able to compile this branch locally and test it. Here are my results. I started OpenTelemetry and Fluent Bit with the following respective configurations. otel-config.yaml---
receivers:
otlp:
protocols:
grpc:
http:
endpoint: "0.0.0.0:4318"
processors:
batch:
exporters:
file:
path: otel-output.json
service:
telemetry:
logs:
level: debug
pipelines:
logs:
receivers:
- otlp
processors:
- batch
exporters:
- filefluent-bit-config.yaml---
pipeline:
inputs:
- name: dummy
tag: dummy
metadata: |
{
"resource-attr": "resource-attr-val-1"
}
# This log record is taken directly from OpenTelemetry's Examples page.
# https://opentelemetry.io/docs/specs/otel/protocol/file-exporter/#examples
dummy: |
{
"severityNumber": 9,
"severityText": "Info",
"name": "logA",
"message": "This is a log message",
"app": "server",
"instance_num": 1,
"traceId": "08040201000000000000000000000000",
"spanId": "0102040800000000"
}
outputs:
- name: opentelemetry
match: "*"
host: localhost
port: 4318
logs_body_key: $message
logs_span_id_message_key: spanId
logs_trace_id_message_key: traceId
# For live debugging on the Fluent Bit side.
- name: stdout
match: "*"
format: jsonHere's what I received in OpenTelemetry. The span ID and trace ID are successfully populated. actual-logs.json{
"resourceLogs": [
{
"resource": {},
"scopeLogs": [
{
"scope": {},
"logRecords": [
{
"timeUnixNano": "1711562977179253000",
"body": {
"stringValue": "This is a log message"
},
"attributes": [
{
"key": "resource-attr",
"value": {
"stringValue": "resource-attr-val-1"
}
}
],
"traceId": "08040201000000000000000000000000",
"spanId": "0102040800000000"
}
]
}
]
}
]
}
|
Thank you @sudomateo for testing. Im glad its working for you as well. I also added support for extracting and setting severity_text and severity_number if you would like to send those also. I would like to be able to also set attributes based on a list of keys the user configures however that work will be done in a separate PR. For now if you would like to set attributes then you can by utilizing the "logs_body_key_attributes true" config that was done by @edsiper last month. The only downside to using the existing logs_body_key_attributes is that it copies over all keys into the attributes field so if you only want to send select fields/keys as attributes, thats currently not possible. Thats why I think it would be good to have a logs_severity_text_attributes_keys configuration at some point, but like i said that will be done in a separate PR. If you have time can you please run and attach a valgrind output showing no memory leaks. Im not able to do this on windows. |
|
I tested It appears the I didn't have time to use |
|
Thanks @sudomateo . I agree that it should be case insensitive. I will update. |
|
Hi, Thanks for putting in this OpentTelemetry change. I really need this as well. It looks like Valgrind is missing still. yeah, I don't know how to setup and use Valgrind for this project, but hope someone else knows. |
|
Here's a quick |
|
Thank you @sudomateo |
|
@edsiper @leonardo-albertovich @fujimotos @koleini Can some please review this? Let me know if there is anything else I need to do as far as checks. |
|
Can you link a docs PR for this? |
|
Documentation PR. I also added docs for @edsiper change as it looks like no doc update was done for his new field. |
|
Thanks, it looks like you have a few issues compiling for older targets as well. Loop definitions are the usual culprit but have a look. You can build locally using |
Signed-off-by: Boslet, Cory (cb645j) <cb645j@att.com>
02b1a89 to
240f096
Compare
Signed-off-by: Boslet, Cory (cb645j) <cb645j@att.com>
|
@patrick-stephens Thanks. I just moved it outside the loop. that should fix. |
|
@patrick-stephens can you please rerun the checks |
Done. Can you please rerun the checks |
|
thanks for this contribution and general testing for all. Running CI, let's try to get this in for v3.0.2 |
|
thanks |
no problem, thanks |
@cb645j Do you still plan on implementing this for attributes? |
Yes, I do. Its a little tricky but i will work on it. You can copy all fields to attributes by using @edsiper logs_body_key_attributes. The downside to it is that its either all or nothing. |
|
…ned-off-by: Cory Boslet cb645j@att.com
This is to support sending additional otlp properties derived from log events body/message properties based on keys.
This is related to #8359 and #8552
Testing
Before we can approve your change; please submit the following in a comment:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-testlabel to test for all targets (requires maintainer to do).Documentation
Backporting
Debug log ouput
stdout:
[0] kubernetes.local: [[1711471800.517000000, {}], {"timestamp"=>"2024-03-26 11:50:00.517", "loglevel"=>"INFO", "trace_id"=>"95e1d11ece6460e7d00c61d45cc195ff", "span_id"=>"11aafe22712ca02c", "message"=>"A log message"}]
outgoing opentelemetry message
see @sudomateo comment below
Example Configuration
Documentation
Otel Log Data Model fields now supported:
Valgrind
valgrind --leak-check=yes fluent-bit --config fluent-bit-config.yaml
==16653== Memcheck, a memory error detector
==16653== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16653== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==16653== Command: ./projects/scratch/fluent-bit/build/bin/fluent-bit --config fluent-bit-config.yaml
==16653==
[2024/03/28 17:39:51] [ info] [fluent bit] version=3.0.1, commit=02b1a89090, pid=16653
[2024/03/28 17:39:51] [ info] [storage] ver=1.5.1, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2024/03/28 17:39:51] [ info] [cmetrics] version=0.7.0
[2024/03/28 17:39:51] [ info] [output:stdout:stdout.0] worker #0 started
[2024/03/28 17:39:51] [ info] [ctraces ] version=0.4.0
[2024/03/28 17:39:51] [ info] [input:dummy:dummy.0] initializing
[2024/03/28 17:39:51] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2024/03/28 17:39:51] [ info] [sp] stream processor started
[{"date":1711647592.169228,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
[{"date":1711647593.161132,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
[{"date":1711647594.156564,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
[{"date":1711647595.153959,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
[{"date":1711647596.163722,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
[{"date":1711647597.154836,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
[{"date":1711647598.153678,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
[{"date":1711647599.152517,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
^C[2024/03/28 17:40:01] [engine] caught signal (SIGINT)
[2024/03/28 17:40:01] [ warn] [engine] service will shutdown in max 5 seconds
[{"date":1711647600.155777,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
[2024/03/28 17:40:01] [ info] [input] pausing dummy.0
[{"date":1711647601.156709,"severityNumber":9,"severityText":"Info","name":"logA","message":"This is a log message","app":"server","instance_num":1,"traceId":"08040201000000000000000000000000","spanId":"0102040800000000"}]
[2024/03/28 17:40:02] [ info] [engine] service has stopped (0 pending tasks)
[2024/03/28 17:40:02] [ info] [input] pausing dummy.0
[2024/03/28 17:40:02] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2024/03/28 17:40:02] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==16653==
==16653== HEAP SUMMARY:
==16653== in use at exit: 0 bytes in 0 blocks
==16653== total heap usage: 2,053 allocs, 2,053 frees, 5,611,479 bytes allocated
==16653==
==16653== All heap blocks were freed -- no leaks are possible
==16653==
==16653== For lists of detected and suppressed errors, rerun with: -s
==16653== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.