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

  • Tests
    • Added extensive unit tests covering edge cases, event/link combinations, encoding consistency, status/flag mappings, and completeness of traced-field handling—improving confidence and reliability of telemetry/trace processing.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 15, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

Walkthrough

Added a suite of unit tests to src/otel/traces.rs validating flattening behavior for events, links, and span records, including empty-input edge cases and known-field / encoding consistency checks. No production code or API changes.

Changes

Cohort / File(s) Summary
Unit tests for OTEL traces flattening
src/otel/traces.rs
Added ~13 unit tests covering: empty-event/link slices, event-only and link-only span enrichment, spans with both events and links and without either, hex-encoding consistency, complete flattened-traces structure, and known-field-list completeness. No production logic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • nikhilsinhaparseable
  • parmesant

Poem

🐇 I nibble at bytes and hop through tests,

Events and links in tidy nests.
Empty slices bowed and checked,
Known fields counted, hex direct.
Hooray — the traces pass the quest!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately describes the main change: adding unit tests for empty events/links flattening in OTel traces.
Description check ✅ Passed PR description comprehensively covers the purpose, specific tests added, and their validation targets. However, the description template's testing/documentation checklist items were not addressed.
Linked Issues check ✅ Passed The PR directly addresses issue #1198 by adding four targeted unit tests that document and validate the expected behavior of the flattening logic introduced in #1196.
Out of Scope Changes check ✅ Passed All changes are scoped to adding unit tests in src/otel/traces.rs; no production code modifications or unrelated changes are present.
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
📝 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.

@LeC-D
Copy link
Author

LeC-D commented Mar 17, 2026

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

@nitisht
Copy link
Member

nitisht commented Mar 17, 2026

Thanks for the PR @LeC-D - looks like the commit email id is not linked to github account, so the CLA Assistant is failing. Would you add your commit email to github, so the CLA is signed properly.

…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
@LeC-D LeC-D force-pushed the test/otel-flatten-empty-events-links branch from ffc3e69 to 7a1b8fd Compare March 17, 2026 12:26
@LeC-D
Copy link
Author

LeC-D commented Mar 17, 2026

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

nitisht added a commit to parseablehq/.github that referenced this pull request Mar 17, 2026
Copy link
Contributor

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

🧹 Nitpick comments (2)
src/otel/traces.rs (2)

1059-1114: Well-structured test for events-only span flattening.

The test correctly validates that a span with events but no links produces one record per event, each enriched with span-level fields.

Consider also asserting that link-specific fields are absent from event records for completeness (similar to how test_flatten_span_record_without_events_and_links verifies absence of both):

💡 Optional enhancement
         // Each event record must also carry the span-level fields.
         for record in &result {
             assert_eq!(
                 record.get("span_name").unwrap(),
                 &Value::String("events-only-span".to_string()),
                 "Event records must be enriched with span fields"
             );
+            assert!(
+                !record.contains_key("link_trace_id"),
+                "Event-only records should not contain link fields"
+            );
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/otel/traces.rs` around lines 1059 - 1114, Update the test
test_flatten_span_record_events_only_no_links to also assert that link-specific
fields are absent on each event record: after the existing span-level checks,
iterate the result and assert that keys such as "link_trace_id" and
"link_span_id" (and any other link-related keys your flatten_span_record
produces) are either None or not present (e.g.,
record.get("link_trace_id").is_none()). This keeps the test aligned with
flatten_span_record's behavior and mirrors the completeness checks in
test_flatten_span_record_without_events_and_links.

1116-1158: Good coverage for links-only span flattening.

The test correctly validates that a span with links but no events produces one record per link, enriched with span-level fields.

For symmetry with the events-only test enhancement, consider also verifying the absence of event-specific fields:

💡 Optional enhancement
         assert_eq!(
             result[0].get("span_name").unwrap(),
             &Value::String("links-only-span".to_string()),
             "Link records must be enriched with span fields"
         );
+        assert!(
+            !result[0].contains_key("event_name"),
+            "Link-only records should not contain event fields"
+        );
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/otel/traces.rs` around lines 1116 - 1158, Update the
test_flatten_span_record_links_only_no_events test to also assert that
event-specific fields are not present on link records: after calling
flatten_span_record(&span) and the existing link assertions, add checks that
result[0] does not contain keys such as "event_name", "event_time_unix_nano",
"event_attributes" (or any other event-related keys used by flatten_span_record)
to ensure link-only records aren't populated with event fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/otel/traces.rs`:
- Around line 1059-1114: Update the test
test_flatten_span_record_events_only_no_links to also assert that link-specific
fields are absent on each event record: after the existing span-level checks,
iterate the result and assert that keys such as "link_trace_id" and
"link_span_id" (and any other link-related keys your flatten_span_record
produces) are either None or not present (e.g.,
record.get("link_trace_id").is_none()). This keeps the test aligned with
flatten_span_record's behavior and mirrors the completeness checks in
test_flatten_span_record_without_events_and_links.
- Around line 1116-1158: Update the
test_flatten_span_record_links_only_no_events test to also assert that
event-specific fields are not present on link records: after calling
flatten_span_record(&span) and the existing link assertions, add checks that
result[0] does not contain keys such as "event_name", "event_time_unix_nano",
"event_attributes" (or any other event-related keys used by flatten_span_record)
to ensure link-only records aren't populated with event fields.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6145842c-7f9c-43e1-bf48-c64391473ca0

📥 Commits

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

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

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

3 participants