Skip to content

Conversation

bachp
Copy link

@bachp bachp commented Oct 1, 2025

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:

  • [N/A] Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • Backport to latest stable release.

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

  • New Features
    • Capture and include event names in OpenTelemetry logs; event names are added to OTLP log metadata when present.
    • New configurable keys to control event-name extraction:
      • logs_event_name_metadata_key (default: $EventName)
      • logs_event_name_message_key (default: $EventName)
  • Chores
    • Adjusted build/version guards for broader compatibility.
  • Tests
    • Added test validating event name propagation into OTLP metadata and log body.

Copy link

coderabbitai bot commented Oct 1, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary of changes
Protobuf schema (C) — LogRecord
lib/fluent-otel-proto/proto_c/opentelemetry/proto/logs/v1/logs.pb-c.c, lib/fluent-otel-proto/proto_c/opentelemetry/proto/logs/v1/logs.pb-c.h
Add event_name string field to LogRecord; expand field descriptors/indices/number ranges to 11; update descriptor and initializer; small protobuf-c version guard tweak.
OTel input plugin — logs packer
plugins/in_opentelemetry/opentelemetry_logs.c
Conditionally pack event_name into the OTLP log metadata map when LogRecord->event_name is non-null/non-empty.
OTel output plugin — configuration & accessors
plugins/out_opentelemetry/opentelemetry.c, plugins/out_opentelemetry/opentelemetry.h, plugins/out_opentelemetry/opentelemetry_conf.c
Add config keys logs_event_name_metadata_key and logs_event_name_message_key; add context fields and record-accessor pointers; create and destroy corresponding RAs (ra_event_name_metadata, ra_event_name_message, ra_log_meta_otlp_event_name).
OTel output plugin — logs processing
plugins/out_opentelemetry/opentelemetry_logs.c
Extract event name from precedence: OTLP meta, custom metadata, message body; set log_record->event_name when found; add allocation and free logic; add event_name_set guard.
Tests — OTLP logs
tests/internal/data/opentelemetry/test_cases.json
Add valid_log_with_event_name test case verifying eventName is captured into log_metadata.otlp.event_name and included in body output.

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
Loading
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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • koleini
  • fujimotos
  • patrick-stephens

Poem

A rabbit hops through logs anew,
I name each hop — event_name true.
From meta or body, I sniff and claim,
Tucked in records, shipped by name.
Thump-thump! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title clearly identifies the affected subsystem (“opentelemetry”) and concisely states the primary change of adding support for an event_name field in logs. It directly corresponds to the main objective of the changeset, which is to implement event_name handling throughout the logging pipeline. The phrasing is specific and avoids unnecessary detail, making the purpose immediately clear to reviewers.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0653e10 and 4bc1a8a.

📒 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)
🚧 Files skipped from review as they are similar to previous changes (3)
  • plugins/in_opentelemetry/opentelemetry_logs.c
  • plugins/out_opentelemetry/opentelemetry.h
  • lib/fluent-otel-proto/proto_c/opentelemetry/proto/logs/v1/logs.pb-c.h
🧰 Additional context used
🧬 Code graph analysis (2)
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)
🔇 Additional comments (13)
plugins/out_opentelemetry/opentelemetry.c (1)

1099-1108: LGTM! Configuration entries are well-structured.

The new event_name configuration entries follow the established pattern for metadata and message keys, with clear descriptions and appropriate defaults.

plugins/out_opentelemetry/opentelemetry_conf.c (3)

520-530: LGTM! Record accessor initialization follows established patterns.

The event_name record accessors are created consistently with existing metadata and message accessors, with appropriate error handling.


621-624: LGTM! OTLP event_name accessor properly initialized.

The record accessor for OTLP event_name metadata is correctly created with appropriate error handling.


815-826: LGTM! Proper cleanup of event_name record accessors.

All three event_name record accessors are correctly destroyed with appropriate NULL checks, preventing memory leaks.

tests/internal/data/opentelemetry/test_cases.json (1)

231-249: LGTM! Test case properly validates event_name propagation.

The new test case follows the established pattern and correctly validates that event_name from the log record is propagated to the OTLP metadata.

lib/fluent-otel-proto/proto_c/opentelemetry/proto/logs/v1/logs.pb-c.c (5)

356-356: LGTM! Field descriptor array size correctly updated.

Array size increased to accommodate the new event_name field.


478-489: LGTM! event_name field descriptor is correctly defined.

The field descriptor follows protobuf-c conventions with appropriate type, offset, and default value for a string field.


491-503: LGTM! Field indices updated correctly.

The field_indices_by_name array maintains proper alphabetical ordering with event_name correctly inserted.


504-509: LGTM! Protobuf number ranges correctly updated.

Range updated to reflect the new field count.


518-518: LGTM! Field count correctly updated to 11.

plugins/out_opentelemetry/opentelemetry_logs.c (3)

395-395: LGTM! Flag properly declared.

The event_name_set flag follows the established pattern for tracking field population.


652-696: LGTM! Event name extraction follows established pattern.

The three-tier extraction logic (OTLP metadata → metadata → message) mirrors the severity_text implementation and properly handles memory allocation, copying, and cleanup. The NULL assignment at the end prevents invalid free operations.


725-727: LGTM! Event name memory properly freed.

The cleanup logic correctly frees allocated event_name memory with appropriate checks against NULL and the protobuf empty string constant.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between fc59bd3 and 0653e10.

📒 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 new event_name field with protobuf_c_empty_string, consistent with other optional string fields.


13-13: Verify the protobuf-c compiler version downgrade.
The check in logs.pb-c.h changed from 1005000 to 1004001, 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, and ra_event_name_message fields are consistent with the existing dual-source pattern used for other log metadata fields like severity_text and span_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 type PROTOBUF_C_TYPE_STRING and default value protobuf_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 include event_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 and logs_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>
@bachp bachp force-pushed the support-logs-event-name branch from 0653e10 to 4bc1a8a Compare October 1, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant