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.

fix(engineering_analytics): bypass egress proxy for OTLP log emit (#67310)

Julian Bez8200d3e8c023
diff --git a/products/engineering_analytics/backend/logic/job_logs/emitter.py b/products/engineering_analytics/backend/logic/job_logs/emitter.py
index ddce0d1e54fd..509a804ecf30 100644
--- a/products/engineering_analytics/backend/logic/job_logs/emitter.py
+++ b/products/engineering_analytics/backend/logic/job_logs/emitter.py
@@ -22,6 +22,8 @@ from opentelemetry.sdk._logs.export import BatchLogRecordProcessor, LogExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.trace import TraceFlags
+from posthog.security.outbound_proxy import internal_requests_session
+
from products.engineering_analytics.backend.logic.job_logs.constants import CI_LOGS_SERVICE_NAME as _SERVICE_NAME
from products.engineering_analytics.backend.logic.job_logs.thinning import ThinnedLine
@@ -79,7 +81,15 @@ class JobLogsEmitter:
) -> None:
self._provider = LoggerProvider(resource=Resource.create({"service.name": _SERVICE_NAME}))
if exporter is None and endpoint and token:
- exporter = OTLPLogExporter(endpoint=endpoint, headers={"authorization": f"Bearer {token}"})
+ # capture-logs is in-cluster (a private ClusterIP). The worker's HTTP_PROXY/HTTPS_PROXY
+ # point at the Smokescreen egress proxy, which denies private-range hosts (407) — so the
+ # OTLP POST must bypass it. internal_requests_session sets trust_env=False; without it
+ # every batch export silently 407s and nothing lands in Logs.
+ exporter = OTLPLogExporter(
+ endpoint=endpoint,
+ headers={"authorization": f"Bearer {token}"},
+ session=internal_requests_session(),
+ )
self._enabled = exporter is not None
if exporter is not None:
self._provider.add_log_record_processor(BatchLogRecordProcessor(exporter))
diff --git a/products/engineering_analytics/backend/logic/job_logs/test/test_job_logs_emitter.py b/products/engineering_analytics/backend/logic/job_logs/test/test_job_logs_emitter.py
index 866764b21be3..58488605319a 100644
--- a/products/engineering_analytics/backend/logic/job_logs/test/test_job_logs_emitter.py
+++ b/products/engineering_analytics/backend/logic/job_logs/test/test_job_logs_emitter.py
@@ -1,5 +1,7 @@
from datetime import UTC, datetime
+from unittest.mock import patch
+
from opentelemetry.exporter.otlp.proto.common._internal._log_encoder import encode_logs
from opentelemetry.sdk._logs.export import InMemoryLogExporter
from parameterized import parameterized
@@ -131,6 +133,19 @@ def test_noop_when_unconfigured():
assert JobLogsEmitter().emit_log_archive(_lines("2026-06-25T09:14:02.000000Z x"), attributes=_ATTRS) == 0
+def test_production_exporter_bypasses_egress_proxy():
+ # The endpoint+token path builds the real OTLP exporter, and its requests.Session must have
+ # trust_env=False: capture-logs is an in-cluster private ClusterIP, and the worker's
+ # HTTP_PROXY/HTTPS_PROXY Smokescreen egress proxy denies private-range hosts (407) — so a
+ # proxy-routed export silently drops every batch. No other test hits this branch (they all inject
+ # an in-memory exporter), which is exactly how the 407 shipped unnoticed.
+ otlp = "products.engineering_analytics.backend.logic.job_logs.emitter.OTLPLogExporter"
+ with patch(otlp) as mock_otlp:
+ with JobLogsEmitter(endpoint="http://capture-logs.posthog.svc.cluster.local:4318/i/v1/logs", token="phc_x"):
+ pass
+ assert mock_otlp.call_args.kwargs["session"].trust_env is False
+
+
def test_noop_when_token_missing():
# Endpoint set but no token must also no-op — we never emit unauthenticated (it would 401 and
# the records would be lost), and a half-configured lane shouldn't crash the worker.