-
Notifications
You must be signed in to change notification settings - Fork 1.8k
opentelemetry: support event_name in logs #10959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughAdds an event_name string field to the OTLP LogRecord protobuf-c structs/descriptors, propagates event name extraction from metadata/message through out_opentelemetry record accessors, packs it in incoming OTLP logs, updates initialization/cleanup, and adds a test case for eventName propagation. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Src as Log Source
participant Out as out_opentelemetry
participant RA as Record Accessors
participant LR as LogRecord (protobuf-c)
participant In as in_opentelemetry (packer)
participant OTLP as OTLP Export
Src->>Out: Emit log (metadata + body)
Out->>RA: Eval ra_log_meta_otlp_event_name
alt found
RA-->>Out: event_name (OTLP meta)
else not found
Out->>RA: Eval ra_event_name_metadata
alt found
RA-->>Out: event_name (custom meta)
else not found
Out->>RA: Eval ra_event_name_message
RA-->>Out: event_name or empty
end
end
Out->>LR: Set LogRecord fields (incl. event_name if present)
Out-->>In: Prepared LogRecord
In->>In: If event_name set -> append "event_name" map entry
In->>OTLP: Pack and send log record
note over In,OTLP: event_name included only when non-null/non-empty
sequenceDiagram
autonumber
participant Cfg as Configuration
participant Out as out_opentelemetry
participant RA as RA Factory
Cfg-->>Out: Load keys (logs_event_name_metadata_key, logs_event_name_message_key)
Out->>RA: Create RA: ra_log_meta_otlp_event_name
Out->>RA: Create RA: ra_event_name_metadata
Out->>RA: Create RA: ra_event_name_message
RA-->>Out: Return RA handles
note right of Out: On teardown, free the three RA resources
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (3)
🧰 Additional context used🧬 Code graph analysis (2)plugins/out_opentelemetry/opentelemetry_logs.c (3)
plugins/out_opentelemetry/opentelemetry_conf.c (1)
🔇 Additional comments (13)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
plugins/in_opentelemetry/opentelemetry_logs.c (1)
284-290
: LGTM! Event name packing follows established pattern.The event_name packing logic correctly checks for null and empty strings, then packs the field into the metadata map using the same pattern as
severity_text
. The implementation is consistent with existing code.For a minor optimization (though not critical since it matches existing style), you could cache
strlen(log_record->event_name)
to avoid calling it twice:if (log_record->event_name != NULL && strlen(log_record->event_name) > 0) { + size_t event_name_len = strlen(log_record->event_name); flb_mp_map_header_append(&mh); msgpack_pack_str(mp_pck, 10); msgpack_pack_str_body(mp_pck, "event_name", 10); - msgpack_pack_str(mp_pck, strlen(log_record->event_name)); - msgpack_pack_str_body(mp_pck, log_record->event_name, strlen(log_record->event_name)); + msgpack_pack_str(mp_pck, event_name_len); + msgpack_pack_str_body(mp_pck, log_record->event_name, event_name_len); }However, this same pattern exists throughout the file, so consistency may be preferred over this micro-optimization.
tests/internal/data/opentelemetry/test_cases.json (1)
231-249
: New test valid_log_with_event_name — correct expectation and schema.Matches OTLP field name (eventName) and maps to log_metadata.otlp.event_name as expected. Consider adding:
- eventName with empty string and ensure packing behavior.
- eventName wrong type (e.g., number/object) to confirm it’s ignored safely.
plugins/out_opentelemetry/opentelemetry_logs.c (1)
652-697
: Extract/pack event_name with proper precedence and safety — LGTM.Order: $otlp metadata -> custom metadata RA -> body RA. Uses calloc+strncpy with zeroed buffer; sets NULL when absent to avoid invalid free. Matches severity_text handling.
To reduce duplication with severity_text, consider a tiny helper: copy_string_field_from_ra(ra, src_map, &dst_ptr, &set_flag).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
lib/fluent-otel-proto/proto_c/opentelemetry/proto/logs/v1/logs.pb-c.c
(4 hunks)lib/fluent-otel-proto/proto_c/opentelemetry/proto/logs/v1/logs.pb-c.h
(4 hunks)plugins/in_opentelemetry/opentelemetry_logs.c
(1 hunks)plugins/out_opentelemetry/opentelemetry.c
(1 hunks)plugins/out_opentelemetry/opentelemetry.h
(2 hunks)plugins/out_opentelemetry/opentelemetry_conf.c
(3 hunks)plugins/out_opentelemetry/opentelemetry_logs.c
(3 hunks)tests/internal/data/opentelemetry/test_cases.json
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
plugins/out_opentelemetry/opentelemetry_logs.c (3)
src/flb_record_accessor.c (1)
flb_ra_get_value_object
(803-814)include/fluent-bit/flb_mem.h (2)
flb_calloc
(84-96)flb_free
(126-128)src/flb_ra_key.c (1)
flb_ra_key_value_destroy
(842-851)
plugins/out_opentelemetry/opentelemetry_conf.c (1)
src/flb_record_accessor.c (2)
flb_ra_create
(271-358)flb_ra_destroy
(232-248)
plugins/in_opentelemetry/opentelemetry_logs.c (1)
src/flb_mp.c (1)
flb_mp_map_header_append
(345-349)
🔇 Additional comments (16)
lib/fluent-otel-proto/proto_c/opentelemetry/proto/logs/v1/logs.pb-c.h (3)
261-270
: LGTM! Event name field properly documented and positioned.The new
event_name
field is well-documented, follows the OpenTelemetry log data model, and is correctly positioned at the end of the struct to maintain binary compatibility with existing code.
272-274
: LGTM! Initializer macro correctly updated.The
OPENTELEMETRY__PROTO__LOGS__V1__LOG_RECORD__INIT
macro is properly updated to initialize the newevent_name
field withprotobuf_c_empty_string
, consistent with other optional string fields.
13-13
: Verify the protobuf-c compiler version downgrade.
The check inlogs.pb-c.h
changed from1005000
to1004001
, implying the proto was regenerated with an older protoc-c. Ensure this is intentional, won’t break compatibility, and update any build docs or CI configurations accordingly.plugins/out_opentelemetry/opentelemetry.h (2)
139-143
: LGTM! Event name fields follow established patterns.The new
logs_event_name_metadata_key
,ra_event_name_metadata
,logs_event_name_message_key
, andra_event_name_message
fields are consistent with the existing dual-source pattern used for other log metadata fields likeseverity_text
andspan_id
.
208-208
: LGTM! OTLP event name accessor properly positioned.The
ra_log_meta_otlp_event_name
accessor is correctly placed among other OTLP metadata accessors and follows the established naming convention.lib/fluent-otel-proto/proto_c/opentelemetry/proto/logs/v1/logs.pb-c.c (4)
356-356
: LGTM! Field descriptor array correctly expanded.The field descriptor array size is properly increased from 10 to 11 fields to accommodate the new
event_name
field. As this is generated code, it correctly reflects the updated protobuf definition.
478-489
: LGTM! Event name field descriptor properly structured.The
event_name
field descriptor is correctly configured as a protobuf field number 12, with typePROTOBUF_C_TYPE_STRING
and default valueprotobuf_c_empty_string
, following the established pattern for optional string fields.
491-503
: LGTM! Field indices correctly updated.The
field_indices_by_name
array is properly updated to includeevent_name
at index 10, maintaining alphabetical ordering of field names.
504-524
: LGTM! Message descriptor counts correctly updated.The number range and field count in the message descriptor are properly updated from 10 to 11, reflecting the addition of the
event_name
field.plugins/out_opentelemetry/opentelemetry.c (1)
1099-1108
: LGTM! Event name configuration entries properly defined.The new config map entries for
logs_event_name_metadata_key
andlogs_event_name_message_key
are well-structured, use appropriate defaults ($EventName
), and follow the established pattern for other log metadata/message keys. The descriptions clearly distinguish between metadata and message body usage.plugins/out_opentelemetry/opentelemetry_conf.c (4)
520-525
: Add RA for event_name (metadata) — looks good; confirm config maps exist.Creation mirrors severity_* RAs and logs on failure. Please confirm logs_event_name_metadata_key is present in config_map with sane default, and that null/empty values are handled as “not set”.
526-531
: Add RA for event_name (message/body) — consistent with pattern.Matches severity_*_message handling; good to enable body fallback.
621-625
: OTLP accessor $otlp['event_name'] — LGTM.Keeps parity with severity_text/number accessors.
815-826
: Destructor updated for new RAs — complete.All three event_name accessors are freed; ordering is fine.
plugins/out_opentelemetry/opentelemetry_logs.c (2)
395-395
: event_name_set flag added — consistent with existing pattern.Mirrors severity_* flags; keeps free path safe.
725-727
: Free event_name alongside severity_text — correct guard.Guard against protobuf_c_empty_string and NULL before free; matches allocator.
Signed-off-by: Pascal Bach <pascal.bach@siemens.com>
0653e10
to
4bc1a8a
Compare
event_name
was stabilitzed in opentelemetry-proto 1.6.0. This change allows to handle the field and pass it along to other opentelemetry consumers.It is implemented analogous to the severity_text.
This includes an updated version of fluent-otel-proto as proposed in fluent/fluent-otel-proto#5
Fixes the remaining problems mentioned in #10143
Enter
[N/A]
in the box, if an item is not applicable to your change.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-test
label to test for all targets (requires maintainer to do).Documentation
Backporting
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.
Summary by CodeRabbit