Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(django): use gzip compression for personhog (#60118)

Zach Brown5d9e6f7e1a14
diff --git a/posthog/personhog_client/client.py b/posthog/personhog_client/client.py
index 81b4948cebc1..98ebf8f9aa22 100644
--- a/posthog/personhog_client/client.py
+++ b/posthog/personhog_client/client.py
@@ -153,6 +153,7 @@ class PersonHogClient:
max_send_message_length: int = 4 * 1024 * 1024,
max_recv_message_length: int = 128 * 1024 * 1024,
client_idle_timeout_ms: int = 0,
+ compression_enabled: bool = True,
):
options = [
("grpc.keepalive_time_ms", keepalive_time_ms),
@@ -166,7 +167,8 @@ class PersonHogClient:
# Prevent the channel from transitioning to IDLE between requests.
("grpc.client_idle_timeout_ms", client_idle_timeout_ms),
]
- channel = grpc.insecure_channel(addr, options=options)
+ compression = grpc.Compression.Gzip if compression_enabled else grpc.Compression.NoCompression
+ channel = grpc.insecure_channel(addr, options=options, compression=compression)
self._channel = grpc.intercept_channel(
channel,
ClientNameInterceptor(client_name),
@@ -343,6 +345,7 @@ def get_personhog_client() -> Optional[PersonHogClient]:
max_send_message_length=getattr(settings, "PERSONHOG_MAX_SEND_MESSAGE_LENGTH", 4 * 1024 * 1024),
max_recv_message_length=getattr(settings, "PERSONHOG_MAX_RECV_MESSAGE_LENGTH", 128 * 1024 * 1024),
client_idle_timeout_ms=getattr(settings, "PERSONHOG_CLIENT_IDLE_TIMEOUT_MS", 0),
+ compression_enabled=getattr(settings, "PERSONHOG_COMPRESSION_ENABLED", True),
)
logger.info("personhog_client_initialized", addr=addr, timeout_ms=timeout_ms)