Skip to content

opentelemetry: general fixes for log handling #10693

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

Merged
merged 9 commits into from
Aug 7, 2025
Merged

Conversation

edsiper
Copy link
Member

@edsiper edsiper commented Aug 5, 2025

This PR fixes #10672 and #10673

Couple of fixes were needed for cases with messages with long nested array/maps, as well some fixes for packaging for not set values while processing AnyValues.

Added some test cases and fixed the JSON packer that shown some issues packaging messages with many nested levels (recursion)


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.

edsiper added 3 commits August 5, 2025 12:33
- Add NULL check in otlp_pack_any_value function to handle NULL body parameter
- Add NULL check for body access in conditional check to prevent segfault
- Handle OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE__NOT_SET case by packing nil value

Signed-off-by: Eduardo Silva <[email protected]>
- Add proper NULL handling for empty map values (unset values)
- Fix missing value handling to pack as empty string
- Complete logic flow to handle all OpenTelemetry value states

Signed-off-by: Eduardo Silva <[email protected]>
Copy link

coderabbitai bot commented Aug 5, 2025

Walkthrough

This change updates msgpack CMake configuration to set a stack size macro, improves handling of unset and empty values in OpenTelemetry log processing (including packing nil for unset values), enhances JSON tokenization and msgpack conversion logic, broadens accepted types in OpenTelemetry utilities, and adds new tests for edge cases involving empty arrays and maps.

Changes

Cohort / File(s) Change Summary
CMake Configuration Update
cmake/msgpack.cmake
Adds MSGPACK_EMBED_STACK_SIZE=64 as a compile definition for msgpack during build configuration.
OpenTelemetry Log Value Handling
plugins/in_opentelemetry/opentelemetry_logs.c
Adds explicit handling for VALUE__NOT_SET by packing nil in msgpack; previously this case was not handled.
JSON Tokenization and Msgpack Conversion
src/flb_pack.c
Resets JSON parser state after token buffer resize and simplifies token boundary checks to more robustly detect invalid tokens.
OpenTelemetry Utility Enhancements
src/opentelemetry/flb_opentelemetry_utils.c
Accepts both array and map types for "arrayValue", refines logic for appending key-value lists to handle empty maps as null, missing values as empty strings, and improves internal flag usage for clarity.
OpenTelemetry Test Case Additions
tests/internal/data/opentelemetry/test_cases.json
Adds new test cases for handling empty maps, missing values, nested arrays/maps, and unwrapped maps in OpenTelemetry log bodies.
JSON Packing Test
tests/internal/pack.c
Adds a test for packing deeply nested JSON objects with empty arrays, validating correct msgpack conversion and output.

Sequence Diagram(s)

sequenceDiagram
    participant OpenTelemetryLog as OpenTelemetry Log Processor
    participant MsgpackPacker as Msgpack Packer

    OpenTelemetryLog->>MsgpackPacker: Process AnyValue
    alt VALUE__NOT_SET
        MsgpackPacker->>MsgpackPacker: Pack nil value
    else Other value types
        MsgpackPacker->>MsgpackPacker: Pack according to value type
    end
Loading
sequenceDiagram
    participant JSONParser as JSON Tokenizer
    participant MsgpackConverter as Msgpack Converter

    JSONParser->>JSONParser: Parse JSON tokens
    alt Token buffer too small
        JSONParser->>JSONParser: Resize token buffer
        JSONParser->>JSONParser: Reset parser state
        JSONParser->>JSONParser: Re-parse from start
    end
    JSONParser->>MsgpackConverter: Provide tokens
    MsgpackConverter->>MsgpackConverter: Validate token boundaries
    MsgpackConverter->>MsgpackConverter: Convert valid tokens to msgpack
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Suggested reviewers

  • leonardo-albertovich
  • koleini

Poem

In the warren of code, a stack size defined,
Empty maps and arrays, no value left behind.
Tokens reset, nils now packed with care,
Test cases sprout up, handled with flair.
With each little hop, our logs grow more bright—
🐇✨ Code rabbits make OpenTelemetry right!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch otel-logs-fixes

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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 (1)
cmake/msgpack.cmake (1)

10-11: Fix the inconsistency between comment and implementation.

The comment states "define preprocessor MSGPACK_EMBED_STACK_SIZE to 1024" but the actual implementation sets it to 64. Update the comment to match the implementation.

-# define preprocessor MSGPACK_EMBED_STACK_SIZE to 1024
+# define preprocessor MSGPACK_EMBED_STACK_SIZE to 64
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b04d501 and ac0dfc8.

📒 Files selected for processing (6)
  • cmake/msgpack.cmake (1 hunks)
  • plugins/in_opentelemetry/opentelemetry_logs.c (1 hunks)
  • src/flb_pack.c (2 hunks)
  • src/opentelemetry/flb_opentelemetry_utils.c (5 hunks)
  • tests/internal/data/opentelemetry/test_cases.json (1 hunks)
  • tests/internal/pack.c (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 32bit, x86, x86-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit, x64, x64-windows-static, 3.31.6)
  • GitHub Check: pr-windows-build / call-build-windows-package (Windows 64bit (Arm64), amd64_arm64, -DCMAKE_SYSTEM_NAME=Windows -DCMA...
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_THREAD=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SIMD=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SANITIZE_MEMORY=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_UNDEFINED=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_COVERAGE=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DSANITIZE_ADDRESS=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, clang, clang++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=Off, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_SMALL=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, gcc, g++)
  • GitHub Check: run-ubuntu-unit-tests (-DFLB_JEMALLOC=On, 3.31.6, clang, clang++)
  • GitHub Check: pr-compile-centos-7
  • GitHub Check: PR - fuzzing test
🔇 Additional comments (12)
plugins/in_opentelemetry/opentelemetry_logs.c (1)

179-182: LGTM: Proper handling of unset protobuf values.

The explicit handling of VALUE__NOT_SET case by packing nil is a good improvement that ensures consistent msgpack encoding for unset OpenTelemetry values. This aligns well with the broader improvements in handling empty/missing values throughout the codebase.

tests/internal/pack.c (2)

973-1005: LGTM: Comprehensive test for nested JSON with empty arrays.

The new test effectively validates the packing of deeply nested JSON structures containing empty arrays, which aligns with the improvements made to JSON tokenization and msgpack conversion logic. The test properly:

  • Uses a complex nested structure to exercise edge cases
  • Validates successful packing with error checking
  • Unpacks the result to verify msgpack correctness
  • Includes proper resource cleanup

1152-1152: LGTM: Test properly registered.

The test is correctly added to the test list.

src/flb_pack.c (2)

82-83: LGTM: Essential parser state reset after token buffer resize.

The addition of jsmn_init(&state->parser) ensures the parser correctly restarts from the beginning of the input after expanding the tokens array. This prevents parsing inconsistencies that could occur when the buffer is resized mid-parse.


223-223: LGTM: Improved token boundary validation.

The simplified and broadened validation check (t->start < 0 || t->end <= 0) is more comprehensive than the previous implementation, properly catching invalid token boundaries regardless of specific zero combinations.

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

1229-1254: Well-designed test case for empty map and missing value handling.

This test case effectively covers the edge cases for handling empty maps as null values and missing "value" keys as empty strings in OpenTelemetry key-value lists. The expected output correctly demonstrates the intended behavior.


1255-1297: Comprehensive test for deeply nested array-wrapped structures.

This test case effectively validates the handling of complex nested structures where maps are wrapped inside arrays within key-value lists. The deep nesting pattern and expected flattened output demonstrate proper parsing logic.


1298-1325: Good coverage for unwrapped plain map structures.

This test case validates the handling of plain maps used directly as values in key-value lists, ensuring that mixed data types (strings and integers) are properly preserved without wrapper structures.

src/opentelemetry/flb_opentelemetry_utils.c (4)

138-142: Improved type flexibility for arrayValue handling.

The expansion to accept both MSGPACK_OBJECT_ARRAY and MSGPACK_OBJECT_MAP types for "arrayValue" keys enhances the parser's ability to handle diverse OpenTelemetry data structures, as demonstrated in the corresponding test cases.


377-379: Minor formatting improvement for readability.

The separation of the conditional logic and return statement enhances code readability without changing functionality.


450-505: Robust implementation for handling empty and missing values.

The introduction of boolean flags (pack_null_value, pack_string_value, pack_value) provides clear control flow for different value states. The logic correctly identifies empty maps as null values and missing "value" keys as empty strings, aligning with the OpenTelemetry specification.


515-539: Well-structured value packing logic with proper precedence.

The conditional structure properly handles the three distinct cases (null values, empty strings, and actual values) in the correct order of precedence. The implementation ensures consistent msgpack encoding for all edge cases.

@edsiper edsiper merged commit d385121 into master Aug 7, 2025
53 of 54 checks passed
@edsiper edsiper deleted the otel-logs-fixes branch August 7, 2025 00:08
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.

Logs with empty values not received via OpenTelemetry gRPC
1 participant