Skip to content

feat: add gzip batch compression#202

Merged
marandaneto merged 1 commit into
mainfrom
feat/gzip-compression
Jun 29, 2026
Merged

feat: add gzip batch compression#202
marandaneto merged 1 commit into
mainfrom
feat/gzip-compression

Conversation

@marandaneto

@marandaneto marandaneto commented Jun 29, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

Fixes #201.

The Ruby SDK sent batch payloads uncompressed, while other PostHog SDKs support request-body compression for ingestion uploads. This enables gzip compression by default for Ruby batch uploads, sets Content-Encoding: gzip, and preserves delivery by falling back to uncompressed JSON if local gzip compression fails before sending. Users can opt out with compress_request: false.

💚 How did you test it?

  • bundle exec rspec
  • bundle exec rubocop lib/posthog/client.rb lib/posthog/send_worker.rb lib/posthog/transport.rb spec/posthog/client_spec.rb spec/posthog/transport_spec.rb
  • bundle exec rake public_api:check

📝 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 pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with pi. I checked the existing SDK gzip behavior for the expected header-based compression, then made Ruby batch uploads gzip by default. The implementation uses Ruby stdlib gzip support, sets Content-Encoding: gzip without adding a compression query parameter, and falls back to the original uncompressed body only for Zlib::Error compression failures so events are not dropped.

@marandaneto marandaneto self-assigned this Jun 29, 2026
@marandaneto marandaneto force-pushed the feat/gzip-compression branch from cace75b to f3b9bc5 Compare June 29, 2026 12:15
@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (1)

  1. lib/posthog/transport.rb, line 153-155 (link)

    P2 The stub debug log still references @path (the original constant path) after the refactor, so when compression is enabled the log will show /batch/ instead of the actual /batch/?compression=gzip path that would be used for a real request. request_path is already in scope and captures the correct value.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "feat: add gzip batch compression" | Re-trigger Greptile

Comment thread lib/posthog/send_worker.rb Outdated
Comment thread lib/posthog/client.rb Outdated
@marandaneto marandaneto force-pushed the feat/gzip-compression branch from f3b9bc5 to 7ddabe2 Compare June 29, 2026 12:18
@marandaneto marandaneto force-pushed the feat/gzip-compression branch from 7ddabe2 to f40aedc Compare June 29, 2026 12:21
@marandaneto

Copy link
Copy Markdown
Member Author

Addressed Greptile feedback in f40aedc: simplified compress_request option forwarding in Client/SendWorker, and updated the stub debug log to reference the computed request path.

@marandaneto marandaneto marked this pull request as ready for review June 29, 2026 12:22
@marandaneto marandaneto requested a review from a team as a code owner June 29, 2026 12:22
@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "feat: add gzip batch compression" | Re-trigger Greptile

@marandaneto

Copy link
Copy Markdown
Member Author

@turnipdabeets can you review this one pls cus i am blocked here #200 (comment)

@marandaneto marandaneto merged commit ffc872d into main Jun 29, 2026
20 checks passed
@marandaneto marandaneto deleted the feat/gzip-compression branch June 29, 2026 14:14
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.

feat: support compressed batch payload uploads

2 participants