Skip to content

test(otel): add unit tests for empty events/links flattening (#1198)#1584

Open
LeC-D wants to merge 1 commit intoparseablehq:mainfrom
LeC-D:test/otel-flatten-empty-events-links
Open

test(otel): add unit tests for empty events/links flattening (#1198)#1584
LeC-D wants to merge 1 commit intoparseablehq:mainfrom
LeC-D:test/otel-flatten-empty-events-links

Conversation

@LeC-D
Copy link

@LeC-D LeC-D commented Mar 15, 2026

Summary

Closes #1198

What

Adds four targeted unit tests to src/otel/traces.rs that document the expected behaviour of the specialised flattening logic introduced in #1196 (empty Events / Links in OTel spans):

Test What it validates
test_flatten_events_empty_slice flatten_events(&[]) returns an empty Vec
test_flatten_links_empty_slice flatten_links(&[]) returns an empty Vec
test_flatten_span_record_events_only_no_links Span with 2 events, 0 links → 2 records each enriched with span fields
test_flatten_span_record_links_only_no_events Span with 0 events, 1 link → 1 record enriched with span fields

The if span_records_json.is_empty() branch in flatten_span_record is the critical path for the #1196 fix; these tests pin its contract so that any future refactor that breaks the fallback will be caught immediately.

Summary by CodeRabbit

Release Notes

  • Tests
    • Enhanced test coverage with new unit tests validating edge cases and data enrichment behavior in telemetry processing, ensuring improved reliability of trace handling.

…lehq#1198)

Document the expected behaviour of flatten_events and flatten_links
when called with empty slices, and the fall-back logic inside
flatten_span_record that the PR parseablehq#1196 fix relies on:

- test_flatten_events_empty_slice: flatten_events(&[]) returns []
- test_flatten_links_empty_slice: flatten_links(&[]) returns []
- test_flatten_span_record_events_only_no_links: span with events but
  no links produces one record per event, each enriched with span fields
- test_flatten_span_record_links_only_no_events: span with links but
  no events produces one record per link, each enriched with span fields
@github-actions
Copy link
Contributor

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


Léo (LeC-D) seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ad6d2355-b88d-4f30-bed9-ab8e7b9df605

📥 Commits

Reviewing files that changed from the base of the PR and between fd9b9a4 and ffc3e69.

📒 Files selected for processing (1)
  • src/otel/traces.rs

Walkthrough

Unit tests were added to validate the behavior of event and link flattening functions in the OpenTelemetry traces module. Tests cover empty input edge cases and verify that enriched span fields are correctly included in flattened records for both events and links.

Changes

Cohort / File(s) Summary
Unit Tests for Flattening Logic
src/otel/traces.rs
Added four unit tests: test_flatten_events_empty_slice, test_flatten_links_empty_slice, test_flatten_span_record_events_only_no_links, and test_flatten_span_record_links_only_no_events to validate empty-input handling and per-event/per-link enrichment behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • nikhilsinhaparseable
  • parmesant

Poem

🐰 With whiskers twitching, tests now hop,
Empty slices? They never stop!
Events and links in flattened grace,
Each test finds its perfect place!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding unit tests for empty events/links flattening in the OTel module, with reference to the related issue.
Description check ✅ Passed The description is well-structured with a clear summary table showing what each test validates, explaining the rationale for pinning the critical path contract.
Linked Issues check ✅ Passed The PR directly addresses issue #1198 by adding four unit tests that document and validate the behavior of specialized flattening code for empty events/links, fulfilling the objective to document expected contract.
Out of Scope Changes check ✅ Passed All changes are within scope: only unit tests added to src/otel/traces.rs with no modifications to existing implementations or APIs, directly aligned with #1198 requirements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unit-tests to validate working of specialized flattening code

1 participant