: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(llma): encrypt evaluation scheduler temporal payloads (#63186)
Carlos Marchal89936fa9ada8
diff --git a/nodejs/package.json b/nodejs/package.jsonindex f2f4aa721c64..b082b42f0295 100644--- a/nodejs/package.json+++ b/nodejs/package.json@@ -86,10 +86,10 @@"@pyroscope/nodejs": "^0.4.8","@segment/action-destinations": "3.387.0","@temporalio/activity": "1.15.0",- "@temporalio/client": "^1.12.0",+ "@temporalio/client": "1.15.0","@temporalio/common": "1.15.0","@temporalio/proto": "1.15.0",- "@temporalio/worker": "^1.12.0",+ "@temporalio/worker": "1.15.0","@types/node": "catalog:","@types/tail": "^2.2.1","avsc": "^5.7.9",diff --git a/nodejs/src/ai-observability/config.ts b/nodejs/src/ai-observability/config.tsindex de57120da8ac..cf86b119bf52 100644--- a/nodejs/src/ai-observability/config.ts+++ b/nodejs/src/ai-observability/config.ts@@ -7,6 +7,9 @@ export type AIObservabilityConfig = {TEMPORAL_CLIENT_CERT: string | undefinedTEMPORAL_CLIENT_KEY: string | undefined+ TEMPORAL_SECRET_KEY: string | undefined+ TEMPORAL_FALLBACK_SECRET_KEYS: string+// Topic the evaluation scheduler reads from. 'events' is the legacy shared// events topic; 'ai_events' is the AI-only topic which carries the// unstripped payload required for teams that have heavy props stripped from@@ -29,6 +32,8 @@ export function getDefaultAIObservabilityConfig(): AIObservabilityConfig {TEMPORAL_CLIENT_ROOT_CA: undefined,TEMPORAL_CLIENT_CERT: undefined,TEMPORAL_CLIENT_KEY: undefined,+ TEMPORAL_SECRET_KEY: process.env.TEMPORAL_SECRET_KEY ?? process.env.SECRET_KEY,+ TEMPORAL_FALLBACK_SECRET_KEYS: process.env.TEMPORAL_FALLBACK_SECRET_KEYS ?? '',LLMA_EVAL_SCHEDULER_TOPIC: 'events',LLMA_EVAL_SCHEDULER_AI_TOPIC_TEAMS: '',LLMA_EVAL_SCHEDULER_PROVIDER_KEY_GATING: false,diff --git a/nodejs/src/ai-observability/services/temporal.service.test.ts b/nodejs/src/ai-observability/services/temporal.service.test.tsindex 3bf27d68a786..d43fc6029cae 100644--- a/nodejs/src/ai-observability/services/temporal.service.test.ts+++ b/nodejs/src/ai-observability/services/temporal.service.test.ts@@ -1,5 +1,6 @@import { Client, Connection } from '@temporalio/client'+import { EncryptionCodec } from '~/common/temporal/codec'import { Hub, RawKafkaEvent } from '~/types'import { closeHub, createHub } from '~/utils/db/hub'@@ -90,6 +91,28 @@ describe('TemporalService', () => {})})+ it('configures an encryption codec when a secret key is set', async () => {+ hub.TEMPORAL_SECRET_KEY = 'test-secret-key-for-codec-000000'+ hub.TEMPORAL_FALLBACK_SECRET_KEYS = 'fallback-key-one-000000000000000,fallback-key-two-000000000000000'++ const newService = new TemporalService(hub)+ await newService.startEvaluationRunWorkflow('test', createMockEvent({ uuid: 'test-uuid' }))++ const clientOptions = (Client as unknown as jest.Mock).mock.calls[0][0]+ expect(clientOptions.dataConverter.payloadCodecs).toHaveLength(1)+ expect(clientOptions.dataConverter.payloadCodecs[0]).toBeInstanceOf(EncryptionCodec)+ })++ it('sends payloads unencrypted when no secret key is set', async () => {+ hub.TEMPORAL_SECRET_KEY = undefined++ const newService = new TemporalService(hub)+ await newService.startEvaluationRunWorkflow('test', createMockEvent({ uuid: 'test-uuid' }))++ const clientOptions = (Client as unknown as jest.Mock).mock.calls[0][0]+ expect(clientOptions.dataConverter).toBeUndefined()+ })+it('disconnects client properly', async () => {await service.startEvaluationRunWorkflow('test', createMockEvent({ uuid: 'test-uuid' }))await service.disconnect()diff --git a/nodejs/src/ai-observability/services/temporal.service.ts b/nodejs/src/ai-observability/services/temporal.service.tsindex 52ca152c73f5..7ab69703af38 100644--- a/nodejs/src/ai-observability/services/temporal.service.ts+++ b/nodejs/src/ai-observability/services/temporal.service.ts@@ -1,7 +1,9 @@-import { Client, Connection, TLSConfig, WorkflowHandle } from '@temporalio/client'+import { Client, Connection, DataConverter, TLSConfig, WorkflowHandle } from '@temporalio/client'import fs from 'fs/promises'import { Counter } from 'prom-client'+import { EncryptionCodec } from '~/common/temporal/codec'+import { RawKafkaEvent } from '../../types'import { isDevEnv } from '../../utils/env-utils'import { logger } from '../../utils/logger'@@ -15,6 +17,8 @@ export type TemporalServiceConfig = Pick<| 'TEMPORAL_PORT'| 'TEMPORAL_HOST'| 'TEMPORAL_NAMESPACE'+ | 'TEMPORAL_SECRET_KEY'+ | 'TEMPORAL_FALLBACK_SECRET_KEYS'>const EVALUATION_TASK_QUEUE = isDevEnv() ? 'development-task-queue' : 'llm-analytics-evals-task-queue'@@ -82,6 +86,22 @@ export class TemporalService {}}+ private buildDataConverter(): DataConverter | undefined {+ const { TEMPORAL_SECRET_KEY, TEMPORAL_FALLBACK_SECRET_KEYS } = this.config++ if (!TEMPORAL_SECRET_KEY) {+ logger.warn('⚠️ No TEMPORAL_SECRET_KEY configured — workflow payloads will NOT be encrypted')+ return undefined+ }++ const fallbackKeys = (TEMPORAL_FALLBACK_SECRET_KEYS ?? '')+ .split(',')+ .map((key) => key.trim())+ .filter(Boolean)++ return { payloadCodecs: [new EncryptionCodec(TEMPORAL_SECRET_KEY, fallbackKeys)] }+ }+private async createClient(): Promise<Client> {const tls = await this.buildTLSConfig()@@ -90,15 +110,19 @@ export class TemporalService {const connection = await Connection.connect({ address, tls })+ const dataConverter = this.buildDataConverter()+const client = new Client({connection,namespace: this.config.TEMPORAL_NAMESPACE || 'default',+ dataConverter,})logger.info('✅ Connected to Temporal', {address,namespace: this.config.TEMPORAL_NAMESPACE,tlsEnabled: tls !== false,+ payloadEncryption: dataConverter !== undefined,})return clientdiff --git a/nodejs/src/session-replay/recording-rasterizer/temporal/codec.ts b/nodejs/src/common/temporal/codec.tssimilarity index 100%rename from nodejs/src/session-replay/recording-rasterizer/temporal/codec.tsrename to nodejs/src/common/temporal/codec.tsdiff --git a/nodejs/src/session-replay/recording-rasterizer/__tests__/codec.test.ts b/nodejs/src/session-replay/recording-rasterizer/__tests__/codec.test.tsindex 937de0a282c2..80fa31446365 100644--- a/nodejs/src/session-replay/recording-rasterizer/__tests__/codec.test.ts+++ b/nodejs/src/session-replay/recording-rasterizer/__tests__/codec.test.ts@@ -1,4 +1,4 @@-import { EncryptionCodec } from '../temporal/codec'+import { EncryptionCodec } from '~/common/temporal/codec'// Fixture generated by Python's EncryptionCodec with secret_key='test-secret-key-for-codec':// inner payload = Payload(metadata={'encoding': b'json/plain'}, data=b'{"key":"value"}')diff --git a/nodejs/src/session-replay/recording-rasterizer/temporal/worker.ts b/nodejs/src/session-replay/recording-rasterizer/temporal/worker.tsindex eed488b2afc8..2ff918189f74 100644--- a/nodejs/src/session-replay/recording-rasterizer/temporal/worker.ts+++ b/nodejs/src/session-replay/recording-rasterizer/temporal/worker.ts@@ -5,12 +5,13 @@ import * as http from 'http'import * as prometheus from 'prom-client'import express from 'ultimate-express'+import { EncryptionCodec } from '~/common/temporal/codec'+import { BrowserPool } from '../capture/browser-pool'import { playerHtmlCache } from '../capture/capture-page'import { config } from '../config'import { createLogger } from '../logger'import { createActivities } from './activities'-import { EncryptionCodec } from './codec'prometheus.collectDefaultMetrics()diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex d5572a595db0..3f6d4905d18a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1504,8 +1504,8 @@ importers:specifier: 1.15.0version: 1.15.0'@temporalio/client':- specifier: ^1.12.0- version: 1.13.1+ specifier: 1.15.0+ version: 1.15.0'@temporalio/common':specifier: 1.15.0version: 1.15.0@@ -1513,7 +1513,7 @@ importers:specifier: 1.15.0version: 1.15.0'@temporalio/worker':- specifier: ^1.12.0+ specifier: 1.15.0'@types/node':specifier: 'catalog:'@@ -6860,10 +6860,6 @@ packages:resolution: {integrity: sha512-lOs/dCyveVF8TkVFnFSF7IGd0CJrTm91qiK6JLu+Z8qiT+7Ag0RyVhxZIWkhiACqwABo7kSHDm8FdH8p2wxSSw==}engines: {node: '>=10'}- '@grpc/[email protected]':- resolution: {integrity: sha512-GsFaMXCkMqkKIvwCQjCrwH+GHbPKBjhwo/8ZuUkWHqbI73Kky9I+pQltrlT0+MWpedCoosda53lgjYfyEPgxBg==}- engines: {node: '>=12.10.0'}-'@grpc/[email protected]':resolution: {integrity: sha512-k9Dj3DV/itK9D06Y8f190Qgop7/Ui+D0njFV3LHMPwPT75DpXLQohE9Wmz0QElrJnzsjB7KPWiKJbOl7IPDArQ==}engines: {node: '>=12.10.0'}@@ -11214,18 +11210,10 @@ packages:resolution: {integrity: sha512-kKEIrHMTsANiEpDVZd+v3OT6kU20UtcvAK7iibJNzQnoZUGC7XnqdKQlBuGYBxgpJzD9ppGgskXRczW+XU5Kng==}engines: {node: '>= 20.0.0'}- '@temporalio/[email protected]':- resolution: {integrity: sha512-EW++yWZhMhHOBCJ5hz4EZank9D5NskJO2zq25THXWGWRDNLeZPGT2rblOPz38Yexu7N6JcSLh8OglWRDohMCzg==}- engines: {node: '>= 18.0.0'}-'@temporalio/[email protected]':resolution: {integrity: sha512-SxTGqRIa2+Vy4P9+06ZpUf4u7ZZmOXfx/kr9XvNqAApLxTMKjTQIg5OH5Wt4JLUtIR7dFkuHIyhewdRyG+hSsQ==}engines: {node: '>= 20.0.0'}- '@temporalio/[email protected]':- resolution: {integrity: sha512-Z8t+uN33gu0Hw0T6o0J0Lmn2v6KJ2j7rDBjPYJwRTqrzY8On8wCkgkrq0JaqNRoMzkSJCjj+eanuBswiltsZlg==}- engines: {node: '>= 18.0.0'}-'@temporalio/[email protected]':resolution: {integrity: sha512-tBfC3fdOExsNoS5krkMUXnaMtCRKj05Jts4+TH+cgHpbys68nslFvUQLqwPIw2x6155Divb9MF219a/75itbTg==}engines: {node: '>= 20.0.0'}@@ -11238,10 +11226,6 @@ packages:resolution: {integrity: sha512-E6CdIjskkbK2aObxcb76Z4V3o1D3QDxEtsxmuHX5D7HEABuYGdV+oeOzDyxMlfeY9GyIM9Nvky4XCiSz2h2XRA==}engines: {node: '>= 20.0.0'}- '@temporalio/[email protected]':- resolution: {integrity: sha512-Lx7ge+XEk9Gk7z5gXX5VreSNLr4GfBxhe4wxmoDI618PilL0hA14nTh48fZxi72gfSFSfZmJCDBEak6lNdbA2A==}- engines: {node: '>= 18.0.0'}-'@temporalio/[email protected]':resolution: {integrity: sha512-Awy4Fjzyba7Pg/CVZjjQ3x2CWkDL1qELyTZWcLlyjXq8bX694JVfBsmiMmF6tHn5/ySOIxDTcc0MSScZ0oKX5A==}engines: {node: '>= 20.0.0'}@@ -17556,9 +17540,6 @@ packages:resolution: {integrity: sha512-BFRuQUqc7x2NWxfJBCyUrN8iYUYznzL9JROmRz1gZ6KlOIgmoD+njPVbb+VNn2nGMKggMsK79iUNErillsrx7w==}- resolution: {integrity: sha512-qtzLbJE8hq7VabR3mISmVGtoXP8KGc2Z/AT8OuqlYD7JTR3oqrgwdjnk07wpj1twXxYmgDXgoKVWUG/fReSzHg==}-resolution: {integrity: sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==}@@ -27025,11 +27006,6 @@ snapshots:- encoding- supports-color- '@grpc/[email protected]':- dependencies:- '@grpc/proto-loader': 0.7.15- '@js-sdsl/ordered-map': 4.4.2-'@grpc/[email protected]':dependencies:'@grpc/proto-loader': 0.8.1@@ -32427,15 +32403,6 @@ snapshots:'@temporalio/common': 1.15.0abort-controller: 3.0.0- '@temporalio/[email protected]':- dependencies:- '@grpc/grpc-js': 1.13.4- '@temporalio/common': 1.13.1- '@temporalio/proto': 1.13.1- abort-controller: 3.0.0- long: 5.2.4- uuid: 9.0.1-'@temporalio/[email protected]':dependencies:'@grpc/grpc-js': 1.14.4@@ -32445,14 +32412,6 @@ snapshots:long: 5.3.2uuid: 11.1.1- '@temporalio/[email protected]':- dependencies:- '@temporalio/proto': 1.13.1- long: 5.3.2- ms: 3.0.0-canary.1- nexus-rpc: 0.0.1- proto3-json-serializer: 2.0.2-'@temporalio/[email protected]':dependencies:'@temporalio/proto': 1.15.0@@ -32474,11 +32433,6 @@ snapshots:long: 5.3.2nexus-rpc: 0.0.1- '@temporalio/[email protected]':- dependencies:- long: 5.3.2- protobufjs: 7.6.1-'@temporalio/[email protected]':dependencies:long: 5.3.2@@ -32486,7 +32440,7 @@ snapshots:dependencies:- '@grpc/grpc-js': 1.13.4+ '@grpc/grpc-js': 1.14.4'@swc/core': 1.15.18'@temporalio/activity': 1.15.0'@temporalio/client': 1.15.0@@ -40813,8 +40767,6 @@ snapshots:- [email protected]: {}-