Skip to content

feat: implement json.Marshaler for CLEFEvent - #15

Merged
desertwitch merged 2 commits into
masterfrom
devel
Jun 17, 2026
Merged

feat: implement json.Marshaler for CLEFEvent#15
desertwitch merged 2 commits into
masterfrom
devel

Conversation

@desertwitch

@desertwitch desertwitch commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Implemented custom JSON serialization for CLEF events with improved field omission and property handling.
  • Bug Fixes

    • Fixed README examples for file path handling and OpenTelemetry imports.
  • Tests

    • Added comprehensive test suite for event encoding and JSON marshaling.
  • Documentation

    • Added v0.8.1 changelog entry and improved inline documentation.
  • Chores

    • Updated test tool dependency version.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@desertwitch, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 41 minutes and 8 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b69cda52-a4d9-42be-bf96-dd587c4216c2

📥 Commits

Reviewing files that changed from the base of the PR and between 6b93acc and fc898b8.

📒 Files selected for processing (4)
  • CONTRIBUTING.md
  • LICENSE
  • SECURITY.md
  • handler.go

Walkthrough

CLEFEvent replaces struct-tag JSON serialization with a custom MarshalJSON backed by encodeEvent, dottedToNested, and addNested helpers. sendEvents in the flusher is rewritten to stream JSON directly via json.Encoder. Comprehensive tests are added for all new encoding logic, and documentation comments are expanded across handler.go, flusher.go, seqotel/seqotel.go, and README.md.

Changes

CLEFEvent custom marshaling and flusher integration

Layer / File(s) Summary
CLEFEvent struct and custom MarshalJSON implementation
event.go
CLEFEvent struct tags are removed and MarshalJSON is added, delegating to encodeEvent, which builds the CLEF JSON object by copying Properties, escaping @-prefixed user keys, always emitting @t, and conditionally emitting @m, @l, @x, @st, @tr, @sp, @ps, @ra, and @sk. dottedToNested and addNested helpers convert dotted ResourceAttributes keys into nested maps for the @ra field.
encodeEvent, dottedToNested, and addNested test coverage
event_test.go
New test file covers required CLEF keys, all conditional optional fields (exception, trace/span IDs, parent span ID, span start, span kind), property copying with reserved-key override precedence, @-sign escaping and no-double-escape, MarshalJSON round-trip, dottedToNested across all key shapes and conflict cases, and addNested for all path and merge scenarios.
sendEvents rewrite: direct json.Encoder body construction
flusher.go, flusher_test.go
sendEvents is rewritten to encode all events into a strings.Builder via a shared json.Encoder instead of per-event intermediate buffers. Error messages for request construction and transport failures are wrapped with fmt.Errorf. Oversized-event drop logging includes the HTTP status code. Non-2xx responses log a status-code-prefixed message and trigger retry. flusher_test.go adds assertions that unencodable events skip the HTTP call and invoke the error callback.
Documentation comments, README fixes, changelog, and dependency bump
handler.go, flusher.go, seqotel/seqotel.go, README.md, CHANGELOG.md, .changes/v0.8.1.md, tool/tester/go.mod
GoDoc comments are added or expanded on newHTTPClient, runFlusher, flushBatch, SeqHandler.start, SeqHandler.Close, resolveAndAddAttr, convertLevel, shared, worker, and seqotel helpers. README examples are corrected (filepath.Base, OTel imports). Changelog entries record the new json.Marshaler. tool/tester/go.mod bumps the slog-seq dependency to v0.8.0.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing json.Marshaler for CLEFEvent, which is the primary functional addition across the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 devel

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.

@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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)
event.go (1)

93-98: 💤 Low value

Modifying map during iteration is safe here but fragile.

The escaping loop modifies topLevel while iterating. This works because newly added @@-prefixed keys are excluded by the condition, but the pattern is subtle and could break if the logic changes.

Consider iterating over a snapshot of the keys or the original e.Properties:

♻️ Suggested alternative
-	// Escape any @ to @@ (according to specification).
-	for k, v := range topLevel {
-		if strings.HasPrefix(k, "@") && !strings.HasPrefix(k, "@@") {
-			topLevel["@"+k] = v
-			delete(topLevel, k)
-		}
-	}
+	// Escape any @ to @@ (according to specification).
+	for k, v := range e.Properties {
+		if strings.HasPrefix(k, "@") && !strings.HasPrefix(k, "@@") {
+			delete(topLevel, k)
+			topLevel["@"+k] = v
+		}
+	}

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c276ad9f-19b1-4da8-b8e4-4847cdeba15f

📥 Commits

Reviewing files that changed from the base of the PR and between ad56312 and 6b93acc.

📒 Files selected for processing (10)
  • .changes/v0.8.1.md
  • CHANGELOG.md
  • README.md
  • event.go
  • event_test.go
  • flusher.go
  • flusher_test.go
  • handler.go
  • seqotel/seqotel.go
  • tool/tester/go.mod
💤 Files with no reviewable changes (1)
  • flusher_test.go

Comment thread .changes/v0.8.1.md
Comment thread README.md
Comment thread README.md
@desertwitch
desertwitch merged commit f39aaa4 into master Jun 17, 2026
14 of 15 checks passed
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.

1 participant