Skip to content

fix: omit null object properties when serializing events - #204

Draft
marandaneto wants to merge 2 commits into
mainfrom
fix/null-property-serialization-sqq3ojkm
Draft

fix: omit null object properties when serializing events#204
marandaneto wants to merge 2 commits into
mainfrom
fix/null-property-serialization-sqq3ojkm

Conversation

@marandaneto

@marandaneto marandaneto commented Sep 9, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

Event properties currently keep null object members on the wire. This implements the capture contract in sdk-specs #60 at the shared batch boundary, after enrichment and before_send.

Null object members are omitted recursively. Array positions, empty objects, false, zero, strings, and nullable envelope fields stay intact. Jason encoder output keeps duplicate members and precise numeric tokens. Only event-specific exception metadata and generated feature-flag response fields retain their intentional nulls. Privacy-filtered fields are not recreated. Flags requests are unchanged.

💚 How did you test it?

  • 44 focused serialization, API client, Sender, and wire snapshot tests passed on the final committed head. Tests inspect real Req JSON bytes in plain and gzip modes, including capture, AI, exception, hook, count, timer, and shutdown paths.
  • Three existing feature-flag privacy controls passed. New tests cover custom encoders, duplicate keys, precise and overflow-size numeric tokens, malformed JSON, null array slots, and caller preservation.
  • Compile with warnings as errors, formatting, strict Credo, and the public API snapshot check passed. A Jason-only check preserved duplicate keys and 1e400 without Decimal. No dependencies changed.
  • Installed isolated autoreview passed at 34f0aa9bd9aef03b48e2c4e3bf5512400013a951 against 0208567b4790f51be431af23b22241a0d83446b3, with TruffleHog clean and no findings.

Local validation used Elixir 1.20.4, OTP 29, and Jason 1.4.5 with existing offline dependencies. SDK requests terminate at Req adapters or API mocks with fake keys. The test application was disabled and integration config absent. This is not system-wide DNS/socket denial, live-backend testing, a full suite, minimum-runtime coverage, or a performance benchmark. This SDK has no event disk queue. Shared compliance harness gaps remain outside this change. Hosted CI reached 28 passing checks at the same head, including the supported runtime matrix and compliance workflow. The compliance harness has known null-policy fixture and assertion gaps, so its success is not independent proof of this contract.

The first CI attempt failed in Elixir 1.17/OTP 26 with two Logger.flush / ExUnit.CaptureLog errors about a missing default logger handler. Five sibling jobs were cancelled by fail-fast. After inspecting the logs, one failed-jobs rerun was approved for a suspected logger-handler race. Attempt 2 passed at the unchanged SHA, including all six failed or cancelled jobs. No source or test changes were made for the rerun. The race classification is suspected, not a proven baseline defect.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

The existing repository-native Sampo patch entry uses hex/posthog: patch. It was authored directly without installing or running Sampo. No release is requested.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Pi assisted with implementation, local validation, and this draft under marandaneto's direction. Tools included Git, Mix, Jason, GitHub CLI, and the installed isolated Pi autoreview helper. Session reference: 09dfe7ee-3109-49db-82c8-ae60d5a5b2af (local session, no public transcript).

The change stays at the shared API.batch boundary. It does not add a blanket reserved-property exemption, Decimal dependency, or wrapper-specific serializer. Human review is required before merging. This PR remains a draft.

@marandaneto marandaneto self-assigned this Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-09-09 10:41:49 UTC
Duration: 117605ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 610ms
Format Validation.Event Has Uuid 609ms
Format Validation.Event Has Lib Properties 609ms
Format Validation.Distinct Id Is String 609ms
Format Validation.Token Is Present 609ms
Format Validation.Custom Properties Preserved 609ms
Format Validation.Event Has Timestamp 609ms
Retry Behavior.Retries On 503 5614ms
Retry Behavior.Does Not Retry On 400 2612ms
Retry Behavior.Does Not Retry On 401 2612ms
Retry Behavior.Respects Retry After Header 5612ms
Retry Behavior.Implements Backoff 15614ms
Retry Behavior.Retries On 500 5615ms
Retry Behavior.Retries On 502 5615ms
Retry Behavior.Retries On 504 5615ms
Retry Behavior.Max Retries Respected 15624ms
Deduplication.Generates Unique Uuids 621ms
Deduplication.Preserves Uuid On Retry 5609ms
Deduplication.Preserves Uuid And Timestamp On Retry 10620ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5617ms
Deduplication.No Duplicate Events In Batch 615ms
Deduplication.Different Events Have Different Uuids 611ms
Compression.Sends Gzip When Enabled 609ms
Batch Format.Uses Proper Batch Structure 609ms
Batch Format.Flush With No Events Sends Nothing 606ms
Batch Format.Multiple Events Batched Together 614ms
Error Handling.Does Not Retry On 403 2611ms
Error Handling.Does Not Retry On 413 2612ms
Error Handling.Retries On 408 5615ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 610ms
Request Payload.Flags Request Uses V2 Query Param 608ms
Request Payload.Flags Request Hits Flags Path Not Decide 608ms
Request Payload.Flags Request Omits Authorization Header 608ms
Request Payload.Token In Flags Body Matches Init 608ms
Request Payload.Groups Round Trip 608ms
Request Payload.Groups Default To Empty Object 608ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 608ms
Request Payload.Disable Geoip Omitted Defaults To False 608ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 608ms
Request Lifecycle.No Flags Request On Init Alone 4ms
Request Lifecycle.No Flags Request On Normal Capture 609ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 1211ms
Request Lifecycle.Mock Response Value Is Returned To Caller 609ms
Retry Behavior.Retries Flags On 502 911ms
Retry Behavior.Retries Flags On 504 911ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1210ms

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