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.

feat(ai-research): fetch images over HTTP/2 (#95947)

Robbiefcc51ee87d32
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/IMPLEMENTATION_NOTES.md b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/IMPLEMENTATION_NOTES.md
index 80153d258e8d..2d5400dd85ca 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/IMPLEMENTATION_NOTES.md
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/IMPLEMENTATION_NOTES.md
@@ -22,6 +22,8 @@ The fetcher follows configuration redirects only inside the source registrable d
The shared streamed-request helper preserves repeated response field lines. Policy evaluation therefore sees every opt-out field in received order.
+Image and configuration requests opt into HTTP/2 on the shared secure dispatcher. Requests to an origin reuse its session instead of opening a new TLS connection each time, which saves a handshake on both sides. The dispatcher decides how many sessions an origin gets and when an idle one closes. An origin that offers only HTTP/1.1 gets HTTP/1.1 with no change in behavior.
+
Production requests use Smokescreen. The Rust admission policy also refuses every IP literal, including a public IP literal.
Web Bot Auth uses the shared PostHog key directory. The directory response has a 60-second public cache lifetime.
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts
index 93ed3cd076e8..7cd413b64cb7 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.test.ts
@@ -420,6 +420,7 @@ describe('HttpConfigurationFetcher', () => {
['https://example.com/robots.txt'],
['https://cdn.example.com/robots'],
])
+ expect(fetchStreamedMock.mock.calls.map(([, options]) => options.allowH2)).toEqual([true, true])
})
it('does not follow a configuration redirect to another registrable domain', async () => {
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts
index 99aca0db16f0..9e94f19b9e54 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/configuration-policy.ts
@@ -110,6 +110,7 @@ export class HttpConfigurationFetcher {
try {
response = await fetchStreamed(target.toString(), {
timeoutMs: Math.max(1, deadlineMs - Date.now()),
+ allowH2: true,
headers: {
'user-agent': USER_AGENT,
accept: file === 'robots' ? 'text/plain,*/*;q=0.1' : 'application/json,*/*;q=0.1',
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/image-fetcher.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/image-fetcher.test.ts
index 40d9bc7272e1..0ce41ad3da43 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/image-fetcher.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/image-fetcher.test.ts
@@ -56,6 +56,17 @@ describe('HttpImageFetcher', () => {
})
afterEach(() => jest.restoreAllMocks())
+ it('opts every image request into HTTP/2', async () => {
+ fetchStreamedMock.mockResolvedValue(image(PNG, 'image/png'))
+
+ await fetcher().fetch('https://cdn.example.com/a.png', OPTIONS)
+
+ expect(fetchStreamedMock).toHaveBeenCalledWith(
+ 'https://cdn.example.com/a.png',
+ expect.objectContaining({ allowH2: true })
+ )
+ })
+
it('identifies every request as PostHogImageFetcherBot', async () => {
fetchStreamedMock.mockResolvedValue(image(PNG, 'image/png'))
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/image-fetcher.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/image-fetcher.ts
index c3ff3968d99f..89531d138a8d 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/image-fetcher.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror-image-fetch/image-fetcher.ts
@@ -233,7 +233,7 @@ export class HttpImageFetcher implements ImageFetcher {
headers['if-modified-since'] = previousCache.lastModified
}
try {
- const response = await fetchStreamed(url, { headers, timeoutMs })
+ const response = await fetchStreamed(url, { headers, timeoutMs, allowH2: true })
const status = response.status
requestOutcome = ImageFetchRequestMetrics.outcomeForHttpStatus(status)
const cache = cacheMetadata(requestTimeMs, Date.now(), response.headerLines)