Skip to content

opentelemetry: add OTLP JSON and OTLP Proto helpers#11624

Merged
edsiper merged 47 commits intomasterfrom
otlp_format_json_proto
Mar 30, 2026
Merged

opentelemetry: add OTLP JSON and OTLP Proto helpers#11624
edsiper merged 47 commits intomasterfrom
otlp_format_json_proto

Conversation

@edsiper
Copy link
Copy Markdown
Member

@edsiper edsiper commented Mar 27, 2026

It also extends stdout and kafka to format payloads in OTLP


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

    • Configurable yyjson backend (default ON).
    • New public JSON API: parse, serialize, pretty-print, and mutable JSON builder.
    • OTLP encoders (JSON & Protobuf) for traces/metrics/logs; Kafka and stdout can emit OTLP payloads.
  • Bug Fixes

    • Corrected timestamp nanoseconds computation.
    • Safer metrics chunk handling with mutex protection; metric unit preserved across encode/decode.
  • Tests

    • Added extensive OTLP roundtrip and conversion tests (JSON/proto, msgpack merges).
  • Chores

    • Project packaging version bumps and CI workflow action updates.

edsiper added 9 commits March 27, 2026 03:05
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Made yyjson optional via CMake; added a public flb_json API and implementation (immutable + mutable); added OTLP JSON/proto encoders and integrated them into outputs (Kafka, Stdout); gated yyjson-backed packer APIs; added metric unit roundtrip handling and tests; added metrics chunk synchronization.

Changes

Cohort / File(s) Summary
Build system & headers
CMakeLists.txt, cmake/headers.cmake, src/CMakeLists.txt
Add option(FLB_YYJSON ON); conditionally add yyjson subdir and FLB_HAVE_YYJSON; adjust include dirs and FLB_DEPS.
JSON public API & implementation
include/fluent-bit/flb_json.h, src/flb_json.c
Add public flb_json header and implementation: parse/serialize/prettify, immutable and mutable document/value APIs; optional yyjson-backed paths.
Packer/parser adjustments
include/fluent-bit/flb_pack.h, src/flb_pack.c, src/flb_pack_json.c, src/flb_parser_json.c, tests/internal/mp.c
Gate yyjson-specific packer functions behind FLB_HAVE_YYJSON; change default backend selection when yyjson absent; add OTLP JSON format constants; update callsites/tests to use flb_pack_json.
OpenTelemetry API & proto encoder
include/fluent-bit/flb_opentelemetry.h, src/opentelemetry/.../flb_opentelemetry_otlp_proto.c
Expose OTLP JSON/proto APIs and options; add OTLP proto implementation for metrics/traces/logs with msgpack decoding → protobuf construction → packed output.
Output plugins (Kafka, Stdout)
plugins/out_kafka/..., plugins/out_stdout/stdout.c
Add OTLP JSON/proto output formats; Kafka: new produce_raw_payload with queue-full retry logic and event_type adjustments; Stdout: OTLP JSON print path and pretty option.
CMetrics encode/decode & tests
lib/cmetrics/src/cmt_decode_msgpack.c, lib/cmetrics/src/cmt_encode_msgpack.c, lib/cmetrics/tests/*
Add opts.unit handling to encode/decode; adapt callbacks to use map context; add unit roundtrip and exp_histogram aggregation-preservation tests.
CTraces & metadata
lib/ctraces/..., lib/ctraces/.github/workflows/*
Bump patch version, update GH action artifact action versions, fix header guard macro and ensure SDS length set for hex ID output.
Core input/chunk synchronization
include/fluent-bit/flb_input.h, src/flb_input.c, src/flb_input_metric.c, src/flb_input_chunk.c
Add metrics_chunk_lock mutex to input instance, initialize/destroy it, protect ht_metric_chunks accesses; append metrics chunks with event count 1 and drop stale tag-bound entries.
Time utils
include/fluent-bit/flb_time.h
Fix nanoseconds calculation in flb_time_from_uint64 to use explicit multiplication for correct unit arithmetic.
OAuth2/JWT & tests
src/flb_oauth2_jwt.c, tests/internal/mp.c
Replace direct flb_pack_json_yyjson calls with flb_pack_json to follow default packer selection.
Tests & runtime filter updates
tests/internal/opentelemetry.c, tests/runtime/filter_log_to_metrics.c
Add extensive OTLP roundtrip tests and JSON normalization helpers; refactor runtime test buffering to bounded accumulation and include unit in expected metadata.
Outputs disallowing OTLP
plugins/out_null/null.c, plugins/out_tcp/tcp_conf.c, plugins/out_udp/udp_conf.c, plugins/out_websocket/websocket_conf.c
Explicitly mark OTLP JSON/OTLP_PRETTY formats as unsupported in several outputs and emit clear error messages.

Sequence Diagram(s)

sequenceDiagram
    participant Producer as Event Producer
    participant OutKafka as out_kafka
    participant OTLPConv as OTLP Converter
    participant Broker as Kafka Broker

    Producer->>OutKafka: push event_chunk (msgpack)
    activate OutKafka
    OutKafka->>OutKafka: inspect ctx->format
    alt OTLP JSON
        OutKafka->>OTLPConv: msgpack -> OTLP JSON
        activate OTLPConv
        OTLPConv->>OTLPConv: decode msgpack, build OTLP JSON
        OTLPConv-->>OutKafka: JSON bytes
        deactivate OTLPConv
    else OTLP Proto
        OutKafka->>OTLPConv: msgpack -> OTLP Proto
        activate OTLPConv
        OTLPConv->>OTLPConv: decode to cmt/ctr, build protobuf
        OTLPConv-->>OutKafka: binary proto bytes
        deactivate OTLPConv
    end
    OutKafka->>OutKafka: handle queue-full retries (local)
    OutKafka->>Broker: produce_raw_payload(bytes)
    OutKafka-->>Producer: return status
    deactivate OutKafka
Loading
sequenceDiagram
    participant App as Consumer/Library user
    participant flb_json as flb_json API
    participant flb_pack as flb_pack (msgpack)
    participant yyjson as yyjson (optional)

    App->>flb_json: flb_json_read(json, len)
    activate flb_json
    flb_json->>flb_pack: flb_pack_json(...)
    flb_pack-->>flb_json: msgpack buffer
    flb_json->>flb_json: wrap msgpack into flb_json_doc
    flb_json-->>App: flb_json_doc*
    deactivate flb_json

    App->>flb_json: flb_json_write_pretty(doc)
    activate flb_json
    alt FLB_HAVE_YYJSON
        flb_json->>yyjson: convert -> yyjson_mut, yyjson_write(pretty)
        yyjson-->>flb_json: pretty JSON
    else
        flb_json->>flb_json: render msgpack -> pretty JSON
    end
    flb_json-->>App: JSON string
    deactivate flb_json
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested reviewers

  • cosmo0920
  • niedbalski
  • patrick-stephens
  • celalettin1286

Poem

🐇 I nibble bytes and pack them tight,
yyjson optional, msgpack still right.
OTLP hops on Kafka's cart,
stdout prints each JSON heart.
Tests hop through roundtrips — code takes flight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'opentelemetry: add OTLP JSON and OTLP Proto helpers' accurately describes the main contribution: introducing OpenTelemetry OTLP JSON and Protocol Buffer conversion helpers as core infrastructure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch otlp_format_json_proto

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
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1ae9ea8fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

edsiper added 4 commits March 27, 2026 04:39
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
edsiper added 2 commits March 27, 2026 04:55
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
edsiper added 2 commits March 28, 2026 16:23
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Copy link
Copy Markdown

@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: 3

♻️ Duplicate comments (1)
src/opentelemetry/flb_opentelemetry_otlp_proto.c (1)

124-137: ⚠️ Potential issue | 🟠 Major

Still missing an INT64_MAX guard before narrowing positive msgpack integers.

Line 136 and Line 508 cast via.u64 straight into int64_t. Values above INT64_MAX wrap into negative resource_id / scope_id or AnyValue.int_value, which corrupts grouping and exported payload data.

Suggested range checks
     if (value->type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
+        if (value->via.u64 > INT64_MAX) {
+            return -1;
+        }
         *result = (int64_t) value->via.u64;
         return 0;
     }
             if (object->type == MSGPACK_OBJECT_POSITIVE_INTEGER) {
+                if (object->via.u64 > INT64_MAX) {
+                    otlp_any_value_destroy(value);
+                    return NULL;
+                }
                 value->int_value = (int64_t) object->via.u64;
             }

Also applies to: 503-509

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/opentelemetry/flb_opentelemetry_otlp_proto.c` around lines 124 - 137, The
positive-integer branch in msgpack_map_get_int64 (and the other site that casts
value->via.u64 into int64_t for resource_id/scope_id/AnyValue.int_value) lacks a
check for overflow: add a guard that compares value->via.u64 against INT64_MAX
before casting and treat values > INT64_MAX as an error (return non-zero) to
avoid wrapping into negative int64_t; apply the same check at the other cast
sites where via.u64 is narrowed to int64_t so large unsigned msgpack integers
are rejected rather than silently wrapped.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/flb_input_metric.c`:
- Around line 102-116: The eviction block that removes entries from
ht_metric_chunks is skipped when tag == NULL; to fix, ensure tag normalization
happens before that eviction logic in flb_input_metrics_append:
resolve/normalize the incoming tag (using the same tag normalization logic
currently at lines ~42–50) unconditionally so tag is non-NULL when you reach the
mutex/eviction code that references ins->ht_metric_chunks and
metrics_chunk_lock, or alternatively move the eviction code to the location
where flb_input_chunk_append_raw() finalizes the tag; update
flb_input_metrics_append() (and any helper that performs tag normalization) so
the eviction always runs against the resolved tag reference.

In `@src/opentelemetry/flb_opentelemetry_otlp_proto.c`:
- Around line 1621-1649: The code allocates a LogRecord into
current_scope->scope_log->log_records[...] before calling log_record_to_proto
but only increments n_log_records on success, so if log_record_to_proto fails
the allocated/partially-populated record is leaked; fix by freeing/destroying
that staged LogRecord (reverse of
opentelemetry__proto__logs__v1__log_record__init — i.e., free any nested fields
and the LogRecord struct) immediately before each early return in the error
paths that follow log_record_to_proto, so that flb_log_event_decoder_destroy,
destroy_export_logs, destroy_logs_resource_states and set_error can run without
leaking memory; ensure you update the same error branches that currently return
NULL after log_record_to_proto fails.
- Around line 911-915: The cleanup paths free protobuf-c string fields
unconditionally (e.g., resource_log->schema_url and the scope-related schema_url
fields) which can free static storage set by protobuf_c__*_init; update each
early-error cleanup to check against protobuf_c_empty_string before calling
flb_free (use the same guard pattern as destroy_export_logs()), specifically
guard resource_log->schema_url and the scope schema_url fields in the error
branches around the realloc/alloc failures so you only flb_free() if the pointer
!= protobuf_c_empty_string.

---

Duplicate comments:
In `@src/opentelemetry/flb_opentelemetry_otlp_proto.c`:
- Around line 124-137: The positive-integer branch in msgpack_map_get_int64 (and
the other site that casts value->via.u64 into int64_t for
resource_id/scope_id/AnyValue.int_value) lacks a check for overflow: add a guard
that compares value->via.u64 against INT64_MAX before casting and treat values >
INT64_MAX as an error (return non-zero) to avoid wrapping into negative int64_t;
apply the same check at the other cast sites where via.u64 is narrowed to
int64_t so large unsigned msgpack integers are rejected rather than silently
wrapped.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0b03b000-c255-41bd-a23f-f04c5fa02a5c

📥 Commits

Reviewing files that changed from the base of the PR and between 00ffa56 and 63c7752.

📒 Files selected for processing (6)
  • plugins/out_kafka/kafka.c
  • src/flb_input.c
  • src/flb_input_metric.c
  • src/flb_json.c
  • src/opentelemetry/flb_opentelemetry_otlp_proto.c
  • tests/internal/opentelemetry.c
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/flb_input.c
  • tests/internal/opentelemetry.c
  • plugins/out_kafka/kafka.c
  • src/flb_json.c

edsiper added 6 commits March 30, 2026 09:53
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Copy link
Copy Markdown

@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.

♻️ Duplicate comments (1)
src/opentelemetry/flb_opentelemetry_otlp_proto.c (1)

978-985: ⚠️ Potential issue | 🔴 Critical

Missing protobuf_c_empty_string guards when freeing scope->name and scope->version.

After opentelemetry__proto__common__v1__instrumentation_scope__init(scope), the name and version fields may be set to protobuf_c_empty_string (static storage). If add_msgpack_scope_fields partially succeeds or the corresponding msgpack fields don't exist, these fields remain at their init values. Calling flb_free() on static memory is undefined behavior.

The same issue exists at lines 993-994 and 1011-1012. The destroy_export_logs function correctly guards these fields at lines 1296-1302.

Proposed fix for all three cleanup paths
     if (add_msgpack_scope_fields(scope, scope_object) != 0) {
-        flb_free(scope->name);
-        flb_free(scope->version);
+        if (scope->name != NULL && scope->name != protobuf_c_empty_string) {
+            flb_free(scope->name);
+        }
+        if (scope->version != NULL && scope->version != protobuf_c_empty_string) {
+            flb_free(scope->version);
+        }
         otlp_kvarray_destroy(scope->attributes, scope->n_attributes);
         flb_free(scope);
         flb_free(scope_log);

Apply the same guard pattern at lines 993-994 and 1011-1012.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/opentelemetry/flb_opentelemetry_otlp_proto.c` around lines 978 - 985, The
cleanup code frees scope->name and scope->version unconditionally which can be
the static protobuf_c_empty_string; change each flb_free(scope->name) and
flb_free(scope->version) call (the ones in the failure path after
add_msgpack_scope_fields and the two other scope-cleanup paths) to only call
flb_free if the pointer is not equal to protobuf_c_empty_string (e.g., if
(scope->name && scope->name != protobuf_c_empty_string) flb_free(scope->name);
same for scope->version); apply the same guard pattern to all three cleanup
locations that free scope and scope_log to avoid freeing static storage.
🧹 Nitpick comments (1)
src/opentelemetry/flb_opentelemetry_otlp_proto.c (1)

1403-1413: Dead code: decoded_count == 0 check is unreachable.

The validation at lines 1394-1401 requires decoded_count > 0 for the CMT_DECODE_MSGPACK_INSUFFICIENT_DATA case (the only reachable branch after the while loop). If we reach line 1403, decoded_count is guaranteed to be > 0, making this check always false.

This is defensive code that does no harm, but could be removed for clarity.

Suggested simplification
     if (!((ret == CMT_DECODE_MSGPACK_INSUFFICIENT_DATA &&
            offset == size &&
            decoded_count > 0) ||
           (ret == CMT_DECODE_MSGPACK_SUCCESS && offset == size))) {
         cmt_destroy(merged_context);
         set_error(result, FLB_OPENTELEMETRY_OTLP_PROTO_INVALID_ARGUMENT, EINVAL);
         return NULL;
     }
 
-    if (decoded_count == 0) {
-        cmt_destroy(merged_context);
-        output = cfl_sds_create_size(0);
-        if (output == NULL) {
-            set_error(result, FLB_OPENTELEMETRY_OTLP_PROTO_NOT_SUPPORTED, ENOMEM);
-            return NULL;
-        }
-
-        set_result(result, FLB_OPENTELEMETRY_OTLP_PROTO_SUCCESS);
-        return (flb_sds_t) output;
-    }
-
     encoded = cmt_encode_opentelemetry_create(merged_context);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/opentelemetry/flb_opentelemetry_otlp_proto.c` around lines 1403 - 1413,
The if-block that checks decoded_count == 0 (which destroys merged_context,
creates output, sets set_error or set_result and returns) is unreachable given
the prior validation that requires decoded_count > 0; remove this entire
conditional branch to simplify control flow and avoid dead code, leaving the
normal path that continues processing merged_context and uses
set_result/set_error later (references: decoded_count, merged_context, output,
set_result, set_error).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/opentelemetry/flb_opentelemetry_otlp_proto.c`:
- Around line 978-985: The cleanup code frees scope->name and scope->version
unconditionally which can be the static protobuf_c_empty_string; change each
flb_free(scope->name) and flb_free(scope->version) call (the ones in the failure
path after add_msgpack_scope_fields and the two other scope-cleanup paths) to
only call flb_free if the pointer is not equal to protobuf_c_empty_string (e.g.,
if (scope->name && scope->name != protobuf_c_empty_string)
flb_free(scope->name); same for scope->version); apply the same guard pattern to
all three cleanup locations that free scope and scope_log to avoid freeing
static storage.

---

Nitpick comments:
In `@src/opentelemetry/flb_opentelemetry_otlp_proto.c`:
- Around line 1403-1413: The if-block that checks decoded_count == 0 (which
destroys merged_context, creates output, sets set_error or set_result and
returns) is unreachable given the prior validation that requires decoded_count >
0; remove this entire conditional branch to simplify control flow and avoid dead
code, leaving the normal path that continues processing merged_context and uses
set_result/set_error later (references: decoded_count, merged_context, output,
set_result, set_error).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c432c824-a832-4f1f-9002-aea251db9907

📥 Commits

Reviewing files that changed from the base of the PR and between 63c7752 and d6d1ac2.

📒 Files selected for processing (6)
  • plugins/out_null/null.c
  • plugins/out_tcp/tcp_conf.c
  • plugins/out_udp/udp_conf.c
  • plugins/out_websocket/websocket_conf.c
  • src/flb_input_metric.c
  • src/opentelemetry/flb_opentelemetry_otlp_proto.c

edsiper added 2 commits March 30, 2026 10:34
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Copy link
Copy Markdown

@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: 3

🧹 Nitpick comments (1)
include/fluent-bit/flb_opentelemetry.h (1)

114-120: Rename the shared OTLP log options type before this API freezes.

flb_opentelemetry_logs_to_otlp_proto() taking struct flb_opentelemetry_otlp_json_options * bakes a JSON-specific type name into the new proto API. Since this is newly public surface, a neutral name like flb_opentelemetry_otlp_logs_options will age better if the JSON and proto settings ever diverge.

Also applies to: 249-252

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/fluent-bit/flb_opentelemetry.h` around lines 114 - 120, Rename the
JSON-specific struct flb_opentelemetry_otlp_json_options to a neutral name
flb_opentelemetry_otlp_logs_options and update all references to it (notably the
parameter type in flb_opentelemetry_logs_to_otlp_proto and the other occurrences
mentioned) so the public API no longer embeds “json”; keep the same fields and
semantics but change the type name everywhere it is declared and used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@include/fluent-bit/flb_opentelemetry.h`:
- Around line 239-252: The current *_to_otlp_proto functions
(flb_opentelemetry_traces_to_otlp_proto,
flb_opentelemetry_metrics_to_otlp_proto,
flb_opentelemetry_metrics_msgpack_to_otlp_proto,
flb_opentelemetry_logs_to_otlp_proto) return flb_sds_t but do not document a
safe destroy contract, causing callers to use the wrong free routine; add
explicit destroy helpers or an opaque proto object to normalize ownership:
either (A) introduce and export per-type destroy functions such as
flb_opentelemetry_traces_proto_destroy, flb_opentelemetry_metrics_proto_destroy,
flb_opentelemetry_logs_proto_destroy and update callers to use them, or (B)
change the API to return a single opaque handle type (e.g., struct
flb_otlp_proto *) and provide one flb_otlp_proto_destroy(handle) plus accessor
to get flb_sds_t if needed; update the header declarations accordingly and
ensure plugins/out_kafka and other callers use the new destroy API instead of
flb_sds_destroy/cmt/ctr specific destructors.

In `@plugins/out_stdout/stdout.c`:
- Around line 346-353: The code currently checks ctx->out_format against
FLB_PACK_JSON_FORMAT_OTLP/OTLP_PRETTY after an unconditional return for
FLB_EVENT_TYPE_PROFILES (and thus print_profiles_text() runs even when OTLP JSON
is requested); update the logic to either (A) detect the invalid combination
early and return an error when event_type == FLB_EVENT_TYPE_PROFILES and
ctx->out_format is FLB_PACK_JSON_FORMAT_OTLP or
FLB_PACK_JSON_FORMAT_OTLP_PRETTY, or (B) move handling of
FLB_EVENT_TYPE_PROFILES into the same format dispatch so print_otlp_json(ctx,
event_chunk) is invoked for profiles once a profile OTLP encoder exists;
reference ctx->out_format, FLB_PACK_JSON_FORMAT_OTLP,
FLB_PACK_JSON_FORMAT_OTLP_PRETTY, FLB_EVENT_TYPE_PROFILES,
print_profiles_text(), and print_otlp_json() when making the change.
- Around line 220-222: The fallback else branch currently returns -1 without
logging, so add a flb_plg_error() call before returning to record the
unsupported event chunk type (use event_chunk->type) and a short message like
"unsupported OTLP event chunk type" to stdout plugin's error stream; update the
else branch in stdout.c (the block that now just returns -1) to call
flb_plg_error(ctx->ins, "unsupported OTLP event chunk type: %d",
event_chunk->type) (or the existing logger/context variable used in this file)
and then return -1.

---

Nitpick comments:
In `@include/fluent-bit/flb_opentelemetry.h`:
- Around line 114-120: Rename the JSON-specific struct
flb_opentelemetry_otlp_json_options to a neutral name
flb_opentelemetry_otlp_logs_options and update all references to it (notably the
parameter type in flb_opentelemetry_logs_to_otlp_proto and the other occurrences
mentioned) so the public API no longer embeds “json”; keep the same fields and
semantics but change the type name everywhere it is declared and used.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5cf9052a-4327-43a1-8a32-41da28fd169b

📥 Commits

Reviewing files that changed from the base of the PR and between d6d1ac2 and 16329ae.

📒 Files selected for processing (3)
  • include/fluent-bit/flb_opentelemetry.h
  • plugins/out_stdout/stdout.c
  • src/opentelemetry/flb_opentelemetry_otlp_json.c

edsiper added 4 commits March 30, 2026 13:45
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
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