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.

perf(cdp): skip geoip transformation invocations that cannot change the event (#123921)

Paweł Ledwoń8946b58cb1d1
diff --git a/nodejs/src/cdp/hog-transformations/geoip-noop.test.ts b/nodejs/src/cdp/hog-transformations/geoip-noop.test.ts
new file mode 100644
index 000000000000..62891cef0001
--- /dev/null
+++ b/nodejs/src/cdp/hog-transformations/geoip-noop.test.ts
@@ -0,0 +1,183 @@
+import { GeoIPService } from '~/common/utils/geoip'
+
+import shippedSources from '../../../tests/fixtures/geoip-template-sources.json'
+import { createHogFunction } from '../_tests/fixtures'
+import { HogExecutorService } from '../services/hog-executor.service'
+import { HogInputsService } from '../services/hog-inputs.service'
+import { template as geoipTemplate } from '../templates/_transformations/geoip/geoip.template'
+import { compileHog } from '../templates/compiler'
+import { CyclotronJobInvocationResult, HogFunctionType } from '../types'
+import { createInvocation } from '../utils/invocation-utils'
+import { geoipNoopResult, hogTransformationGeoipNoopSkips } from './geoip-noop'
+import { RustVmExecutor } from './rust-vm-executor'
+import { getTransformationFunctions } from './transformation-functions'
+
+const VALID_IP = '89.160.20.129'
+const NOOP_LOG = 'geoip disabled or no ip.'
+
+const createGeoipInvocation = (overrides: Partial<HogFunctionType>, properties: Record<string, unknown>) =>
+ createInvocation(
+ {
+ project: { id: 1, name: '', url: 'http://localhost' },
+ event: {
+ uuid: 'event-id',
+ event: 'event-name',
+ distinct_id: 'distinct-id',
+ properties,
+ elements_chain: '',
+ timestamp: '2024-01-01T00:00:00Z',
+ url: '',
+ },
+ inputs: {},
+ },
+ createHogFunction({ type: 'transformation', template_id: 'template-geoip', ...overrides })
+ )
+
+const skipCount = async (): Promise<number> => (await hogTransformationGeoipNoopSkips.get()).values[0]?.value ?? 0
+
+const tookEarlyReturn = (result: CyclotronJobInvocationResult): boolean =>
+ !result.error && result.logs.some(({ level, message }) => level === 'info' && message === NOOP_LOG)
+
+describe('geoipNoopResult', () => {
+ const currentSource = geoipTemplate.code
+ const eligibleSources = shippedSources.filter(({ eligible }) => eligible)
+ const bytecodeBySource = new Map<string, any[]>()
+ let nodeVm: HogExecutorService
+ let rustVm: RustVmExecutor
+ let transformationFunctions: ReturnType<typeof getTransformationFunctions>
+
+ beforeAll(async () => {
+ for (const { source } of eligibleSources) {
+ bytecodeBySource.set(source, await compileHog(source))
+ }
+ const mmdbPath = process.env.MMDB_FILE_LOCATION!
+ nodeVm = new HogExecutorService({ executionTimeoutMs: 1000 }, {} as HogInputsService)
+ rustVm = new RustVmExecutor({ mmdbPath })
+ transformationFunctions = getTransformationFunctions(await new GeoIPService(mmdbPath).get())
+ })
+
+ it.each([
+ ...shippedSources.map(({ shipped, eligible, source }) => ({
+ name: `the template shipped ${shipped} as saved, trimmed`,
+ fn: { hog: source.trim() },
+ eligible,
+ })),
+ { name: 'the current template code', fn: { hog: currentSource }, eligible: true },
+ {
+ name: 'the current template code with whitespace changed inside a string',
+ fn: { hog: currentSource.replace(NOOP_LOG, 'geoip disabled or no ip.') },
+ eligible: false,
+ },
+ {
+ name: 'the current template code with an edited statement',
+ fn: { hog: currentSource.replace("print('geoip disabled or no ip.')", "print('skipped')") },
+ eligible: false,
+ },
+ { name: 'no stored source', fn: { hog: null as unknown as string }, eligible: false },
+ {
+ name: 'another template id',
+ fn: { hog: currentSource, template_id: 'template-ip-anonymization' },
+ eligible: false,
+ },
+ { name: 'no template id', fn: { hog: currentSource, template_id: undefined }, eligible: false },
+ ])('eligible is $eligible for $name', ({ fn, eligible }) => {
+ const invocation = createGeoipInvocation(fn, { $geoip_disable: true, $ip: VALID_IP })
+
+ expect(geoipNoopResult(invocation) !== null).toBe(eligible)
+ })
+
+ it('rejects a source with a long inner whitespace run in linear time', () => {
+ const invocation = createGeoipInvocation(
+ { hog: `${currentSource}${' '.repeat(80_000)}// edited` },
+ { $geoip_disable: true, $ip: VALID_IP }
+ )
+
+ const start = performance.now()
+ const result = geoipNoopResult(invocation)
+
+ expect(result).toBeNull()
+ expect(performance.now() - start).toBeLessThan(500)
+ })
+
+ const conditionCases = [
+ { name: '$geoip_disable is true', properties: { $geoip_disable: true, $ip: VALID_IP }, skipped: true },
+ {
+ name: '$geoip_disable is a truthy string',
+ properties: { $geoip_disable: 'yes', $ip: VALID_IP },
+ skipped: true,
+ },
+ {
+ name: '$geoip_disable is a non-zero number',
+ properties: { $geoip_disable: 1, $ip: VALID_IP },
+ skipped: true,
+ },
+ { name: '$geoip_disable is false', properties: { $geoip_disable: false, $ip: VALID_IP }, skipped: false },
+ {
+ name: '$geoip_disable is an empty string',
+ properties: { $geoip_disable: '', $ip: VALID_IP },
+ skipped: false,
+ },
+ { name: '$geoip_disable is missing', properties: { $ip: VALID_IP }, skipped: false },
+ { name: '$ip is missing', properties: {}, skipped: true },
+ { name: '$ip is null', properties: { $ip: null }, skipped: true },
+ { name: '$ip is an empty string', properties: { $ip: '' }, skipped: true },
+ { name: '$ip is an empty array', properties: { $ip: [] }, skipped: true },
+ { name: '$ip is an empty object', properties: { $ip: {} }, skipped: true },
+ { name: '$ip is a non-empty array', properties: { $ip: [VALID_IP] }, skipped: false },
+ { name: '$ip is zero', properties: { $ip: 0 }, skipped: false },
+ { name: '$ip is a non-zero number', properties: { $ip: 42 }, skipped: false },
+ { name: '$ip is false', properties: { $ip: false }, skipped: false },
+ ]
+
+ it.each(
+ eligibleSources.flatMap(({ shipped, source }) =>
+ conditionCases.map((condition) => ({ ...condition, shipped, source }))
+ )
+ )(
+ 'skipped is $skipped when $name, as both vms decide (template shipped $shipped)',
+ async ({ source, properties, skipped }) => {
+ const fn = { hog: source, bytecode: bytecodeBySource.get(source) }
+ const onNode = await nodeVm.execute(createGeoipInvocation(fn, properties), {
+ functions: transformationFunctions,
+ })
+ const onRust = rustVm.execute(createGeoipInvocation(fn, properties), [])
+ const shortcut = geoipNoopResult(createGeoipInvocation(fn, properties))
+
+ expect(onRust).not.toBeNull()
+ expect({ error: onRust!.error, execResult: onRust!.execResult }).toEqual({
+ error: onNode.error,
+ execResult: onNode.execResult,
+ })
+ expect(tookEarlyReturn(onNode)).toBe(skipped)
+ expect(tookEarlyReturn(onRust!)).toBe(skipped)
+ expect(shortcut !== null).toBe(skipped)
+ if (shortcut) {
+ for (const onVm of [onNode, onRust!]) {
+ expect(onVm.execResult).toEqual(shortcut.execResult)
+ expect(shortcut.logs.map(({ level, message }) => ({ level, message }))).toEqual(
+ onVm.logs.map(({ level, message }) => ({
+ level,
+ message: level === 'debug' ? expect.stringMatching(/^Function completed in /) : message,
+ }))
+ )
+ }
+ }
+ }
+ )
+
+ it('returns the input event as a finished result with the template logs', async () => {
+ const invocation = createGeoipInvocation({ hog: currentSource }, { $geoip_disable: true, $ip: VALID_IP })
+ const skipsBefore = await skipCount()
+
+ const result = geoipNoopResult(invocation)
+
+ expect(result?.finished).toBe(true)
+ expect(result?.error).toBeUndefined()
+ expect(result?.execResult).toBe(invocation.state.globals.event)
+ expect(result?.logs.map(({ level, message }) => ({ level, message }))).toEqual([
+ { level: 'info', message: NOOP_LOG },
+ { level: 'debug', message: expect.stringMatching(/^Function completed in [\d.]+ms\.$/) },
+ ])
+ expect((await skipCount()) - skipsBefore).toBe(1)
+ })
+})
diff --git a/nodejs/src/cdp/hog-transformations/geoip-noop.ts b/nodejs/src/cdp/hog-transformations/geoip-noop.ts
new file mode 100644
index 000000000000..a7c915bd6675
--- /dev/null
+++ b/nodejs/src/cdp/hog-transformations/geoip-noop.ts
@@ -0,0 +1,90 @@
+import { createHash } from 'crypto'
+import { Counter } from 'prom-client'
+
+import { CyclotronJobInvocationHogFunction, CyclotronJobInvocationResult, HogFunctionType } from '../types'
+import { createAddLogFunction } from '../utils'
+import { createInvocationResult } from '../utils/invocation-utils'
+
+const GEOIP_TEMPLATE_ID = 'template-geoip'
+
+// sha256 of the trimmed source of each shipped GeoIP template version whose early return is the one
+// geoipNoopResult mirrors. Saving a function trims its source, so the stored text is trimmed too.
+// A function keeps the source it was saved with, so add every new version and never remove one.
+const NOOP_SOURCE_HASHES = new Set([
+ 'c60a2c9cf0d2f82812392c3c682f4223e17082f109e02fbf5467fbb0069d0770', // shipped 2025-01-30
+ '936b06d7d65914d43e5b9f45d8eecda36450e0c128bbfb522020fc0600261175', // shipped 2026-01-08
+])
+
+export const hogTransformationGeoipNoopSkips = new Counter({
+ name: 'hog_transformation_geoip_noop_skips_total',
+ help: 'GeoIP transformation invocations answered without the VM because the template returns the event unchanged',
+})
+
+const noopSourceByFunction = new WeakMap<HogFunctionType, boolean>()
+
+function isSaveTrimmedChar(code: number): boolean {
+ return code === 0x20 || code === 0x09 || code === 0x0d || code === 0x0a
+}
+
+function trimLikeSave(source: string): string {
+ let start = 0
+ let end = source.length
+ while (start < end && isSaveTrimmedChar(source.charCodeAt(start))) {
+ start++
+ }
+ while (end > start && isSaveTrimmedChar(source.charCodeAt(end - 1))) {
+ end--
+ }
+ return source.slice(start, end)
+}
+
+function hasNoopSource(hogFunction: HogFunctionType): boolean {
+ let matches = noopSourceByFunction.get(hogFunction)
+ if (matches === undefined) {
+ matches =
+ typeof hogFunction.hog === 'string' &&
+ NOOP_SOURCE_HASHES.has(createHash('sha256').update(trimLikeSave(hogFunction.hog)).digest('hex'))
+ noopSourceByFunction.set(hogFunction, matches)
+ }
+ return matches
+}
+
+// Hog's empty(), identical in the Node and Rust VMs.
+function isHogEmpty(value: unknown): boolean {
+ if (value === null || value === undefined) {
+ return true
+ }
+ if (typeof value === 'string' || Array.isArray(value)) {
+ return value.length === 0
+ }
+ if (typeof value === 'object') {
+ return Object.keys(value).length === 0
+ }
+ return false
+}
+
+/**
+ * The result the GeoIP template produces when it returns the event unchanged, or null when the VM
+ * must run it. Mirrors the template's `$geoip_disable or empty($ip)` early return.
+ */
+export function geoipNoopResult(
+ invocation: CyclotronJobInvocationHogFunction
+): CyclotronJobInvocationResult<CyclotronJobInvocationHogFunction> | null {
+ const startedAt = performance.now()
+ const { hogFunction } = invocation
+ if (hogFunction.template_id !== GEOIP_TEMPLATE_ID || !hasNoopSource(hogFunction)) {
+ return null
+ }
+
+ const event = invocation.state.globals.event
+ if (!event.properties.$geoip_disable && !isHogEmpty(event.properties.$ip)) {
+ return null
+ }
+
+ hogTransformationGeoipNoopSkips.inc()
+ const result = createInvocationResult<CyclotronJobInvocationHogFunction>(invocation, {}, { execResult: event })
+ const addLog = createAddLogFunction(result.logs)
+ addLog('info', 'geoip disabled or no ip.')
+ addLog('debug', `Function completed in ${Number((performance.now() - startedAt).toFixed(2))}ms.`)
+ return result
+}
diff --git a/nodejs/src/cdp/hog-transformations/hog-transformer.service.test.ts b/nodejs/src/cdp/hog-transformations/hog-transformer.service.test.ts
index 3bf2ae35fe60..3e82d615931d 100644
--- a/nodejs/src/cdp/hog-transformations/hog-transformer.service.test.ts
+++ b/nodejs/src/cdp/hog-transformations/hog-transformer.service.test.ts
@@ -3,6 +3,7 @@ import { mockProducer, mockProducerObserver } from '~/tests/helpers/mocks/produc
import { DateTime } from 'luxon'
import { closeHub, createHub } from '~/common/utils/db/hub'
+import { parseJSON } from '~/common/utils/json-parse'
import { PluginEvent } from '~/plugin-scaffold'
import { posthogFilterOutPlugin } from '../../../src/cdp/legacy-plugins/_transformations/posthog-filter-out-plugin/template'
@@ -16,7 +17,7 @@ import { Hub } from '../../types'
import { createHogFunction, insertHogFunction } from '../_tests/fixtures'
import { posthogPluginGeoip } from '../legacy-plugins/_transformations/posthog-plugin-geoip/template'
import { propertyFilterPlugin } from '../legacy-plugins/_transformations/property-filter-plugin/template'
-import { HogFunctionTemplate } from '../types'
+import { HogFunctionTemplate, HogFunctionType } from '../types'
import type { HogTransformerServiceConfig } from './hog-transformer.service'
import { HogTransformerService, createHogTransformerService } from './hog-transformer.service'
import { resetHogvmNodeModuleCacheForTests } from './rust-vm'
@@ -1599,6 +1600,100 @@ describe('HogTransformer', () => {
})
})
+ describe('geoip template no-op', () => {
+ const geoipFunction = async (overrides: Partial<HogFunctionType> = {}): Promise<HogFunctionType> =>
+ createHogFunction({
+ type: 'transformation',
+ name: geoipTemplate.name,
+ team_id: teamId,
+ template_id: 'template-geoip',
+ hog: geoipTemplate.code,
+ bytecode: await compileHog(geoipTemplate.code),
+ ...overrides,
+ })
+
+ const transform = async (hogFunctions: HogFunctionType[], properties: Record<string, any>) => {
+ const executeSpy = jest.spyOn(hogTransformer['hogExecutor'], 'execute')
+ const queueAppMetricSpy = jest.spyOn(hogTransformer['hogFunctionMonitoringService'], 'queueAppMetric')
+ const result = await hogTransformer.transformEvent(createPluginEvent({ properties }, teamId), hogFunctions)
+ hogTransformer['hogFunctionMonitoringService'].queueInvocationResults(result.invocationResults)
+ const outcome = {
+ vmCalls: executeSpy.mock.calls.length,
+ event: JSON.stringify(result.event),
+ logs: result.invocationResults.flatMap((r) => r.logs.map(({ level, message }) => ({ level, message }))),
+ metrics: queueAppMetricSpy.mock.calls.map(([{ metric_kind, metric_name, count }]) => ({
+ metric_kind,
+ metric_name,
+ count,
+ })),
+ }
+ executeSpy.mockRestore()
+ queueAppMetricSpy.mockRestore()
+ return outcome
+ }
+
+ it.each([
+ { name: '$geoip_disable is true', properties: { $ip: '216.160.83.56', $geoip_disable: true } },
+ { name: '$ip is missing', properties: { $current_url: 'https://example.com' } },
+ { name: '$ip is empty', properties: { $ip: '', $geoip_disable: false } },
+ { name: '$ip is an empty object', properties: { $ip: {} } },
+ ])('answers without the vm and matches its output when $name', async ({ properties }) => {
+ const onVm = await transform([await geoipFunction({ template_id: undefined })], properties)
+ const skipped = await transform([await geoipFunction()], properties)
+
+ expect(onVm.vmCalls).toBe(1)
+ expect(skipped.vmCalls).toBe(0)
+ expect(skipped.event).toBe(onVm.event)
+ expect(skipped.metrics).toEqual(onVm.metrics)
+ expect(skipped.metrics).toEqual([{ metric_kind: 'success', metric_name: 'succeeded', count: 1 }])
+ for (const outcome of [onVm, skipped]) {
+ expect(outcome.logs).toEqual([
+ { level: 'info', message: 'geoip disabled or no ip.' },
+ { level: 'debug', message: expect.stringMatching(/^Function completed in [\d.]+ms\./) },
+ ])
+ }
+ })
+
+ it.each([
+ { name: 'the event has an ip', code: geoipTemplate.code, properties: { $ip: '216.160.83.56' } },
+ {
+ name: 'the function code differs from the template',
+ code: geoipTemplate.code.replace('geoip disabled or no ip.', 'geoip skipped.'),
+ properties: { $ip: '216.160.83.56', $geoip_disable: true },
+ },
+ ])('runs the vm when $name', async ({ code, properties }) => {
+ const outcome = await transform(
+ [await geoipFunction({ hog: code, bytecode: await compileHog(code) })],
+ properties
+ )
+
+ expect(outcome.vmCalls).toBe(1)
+ })
+
+ it('decides on the event as changed by an earlier transformation', async () => {
+ const disableGeoipCode = `
+ let returnEvent := event
+ returnEvent.properties.$geoip_disable := true
+ return returnEvent
+ `
+ const disableGeoip = createHogFunction({
+ type: 'transformation',
+ team_id: teamId,
+ hog: disableGeoipCode,
+ bytecode: await compileHog(disableGeoipCode),
+ })
+ const properties = { $ip: '216.160.83.56' }
+
+ const onVm = await transform([disableGeoip, await geoipFunction({ template_id: undefined })], properties)
+ const skipped = await transform([disableGeoip, await geoipFunction()], properties)
+
+ expect(onVm.vmCalls).toBe(2)
+ expect(skipped.vmCalls).toBe(1)
+ expect(skipped.event).toBe(onVm.event)
+ expect(parseJSON(skipped.event).properties).toEqual({ $ip: '216.160.83.56', $geoip_disable: true })
+ })
+ })
+
it('should throw when trying to capture events in transformations', async () => {
// Create a transformation function that captures an event
const captureTemplate: HogFunctionTemplate = {
@@ -1709,6 +1804,24 @@ describe('HogTransformer', () => {
})
})
+ it('answers a geoip no-op without calling the rust vm', async () => {
+ const geoipFunction = createHogFunction({
+ type: 'transformation',
+ team_id: teamId,
+ template_id: 'template-geoip',
+ hog: geoipTemplate.code,
+ bytecode: await compileHog(geoipTemplate.code),
+ })
+ const properties = { $ip: '216.160.83.56', $geoip_disable: true }
+
+ const result = await hogTransformer.transformEvent(createPluginEvent({ properties }, teamId), [
+ geoipFunction,
+ ])
+
+ expect(mockHogvmNode.executeSync).not.toHaveBeenCalled()
+ expect(result.event?.properties).toEqual(properties)
+ })
+
it('routes through executeBatch instead of executeSync when batch execution is enabled', async () => {
hub.CDP_HOG_RUST_VM_BATCH_EXECUTION_ENABLED = true
hogTransformer = createHogTransformerService(hub, {
diff --git a/nodejs/src/cdp/hog-transformations/hog-transformer.service.ts b/nodejs/src/cdp/hog-transformations/hog-transformer.service.ts
index f2994e539d03..b7f9c5f35cab 100644
--- a/nodejs/src/cdp/hog-transformations/hog-transformer.service.ts
+++ b/nodejs/src/cdp/hog-transformations/hog-transformer.service.ts
@@ -27,6 +27,7 @@ import { EncryptedFields } from '../utils/encryption-utils'
import { HogConfigurationError } from '../utils/hog-error-classification'
import { convertToHogFunctionFilterGlobal, filterFunctionInstrumented } from '../utils/hog-function-filtering'
import { createInputsFailureResult, createInvocation } from '../utils/invocation-utils'
+import { geoipNoopResult } from './geoip-noop'
import { RustVmExecutor } from './rust-vm-executor'
import { getTransformationFunctions } from './transformation-functions'
@@ -383,6 +384,11 @@ export class HogTransformerService implements HogTransformer {
const invocation = createInvocation(globalsWithInputs, hogFunction)
+ const geoipNoop = geoipNoopResult(invocation)
+ if (geoipNoop) {
+ return geoipNoop
+ }
+
if (isLegacyPluginHogFunction(hogFunction)) {
return await this.pluginExecutor.execute(invocation)
}
diff --git a/nodejs/src/cdp/services/managers/hog-function-manager.service.test.ts b/nodejs/src/cdp/services/managers/hog-function-manager.service.test.ts
index 47ec204c98e7..a8a1bb2c0820 100644
--- a/nodejs/src/cdp/services/managers/hog-function-manager.service.test.ts
+++ b/nodejs/src/cdp/services/managers/hog-function-manager.service.test.ts
@@ -58,6 +58,7 @@ describe('HogFunctionManager', () => {
await insertHogFunction(hub.postgres, teamId1, {
name: 'Test Hog Function team 1 - transformation',
type: 'transformation',
+ hog: 'return event',
inputs_schema: [],
inputs: {},
})
@@ -114,6 +115,7 @@ describe('HogFunctionManager', () => {
},
"execution_order": null,
"filters": null,
+ "hog": null,
"id": "<REPLACED-UUID-0>",
"inputs": {
"input_1": {
@@ -175,6 +177,7 @@ describe('HogFunctionManager', () => {
expect((await manager.getHogFunctionsForTeam(teamId1, ['transformation']))[0].type).toEqual(
'transformation'
)
+ expect((await manager.getHogFunctionsForTeam(teamId1, ['transformation']))[0].hog).toEqual('return event')
})
it('for just destinations', async () => {
diff --git a/nodejs/src/cdp/services/managers/hog-function-manager.service.ts b/nodejs/src/cdp/services/managers/hog-function-manager.service.ts
index 412993a4b32f..a4ec0b00eaf4 100644
--- a/nodejs/src/cdp/services/managers/hog-function-manager.service.ts
+++ b/nodejs/src/cdp/services/managers/hog-function-manager.service.ts
@@ -29,6 +29,8 @@ const HOG_FUNCTION_FIELDS = [
'batch_export_id',
'created_at',
'updated_at',
+ // Only the transformer reads the source, so other types skip the text.
+ "CASE WHEN type = 'transformation' THEN hog END AS hog",
]
export type HogFunctionTeamInfo = Pick<HogFunctionType, 'id' | 'team_id' | 'type'>
diff --git a/nodejs/tests/fixtures/geoip-template-sources.json b/nodejs/tests/fixtures/geoip-template-sources.json
new file mode 100644
index 000000000000..60304e8db8e1
--- /dev/null
+++ b/nodejs/tests/fixtures/geoip-template-sources.json
@@ -0,0 +1,22 @@
+[
+ {
+ "shipped": "2025-01-16",
+ "eligible": false,
+ "source": "\n// Define the properties to be added to the event\nlet geoipProperties := {\n 'city_name': null,\n 'city_confidence': null,\n 'subdivision_2_name': null,\n 'subdivision_2_code': null,\n 'subdivision_1_name': null,\n 'subdivision_1_code': null,\n 'country_name': null,\n 'country_code': null,\n 'continent_name': null,\n 'continent_code': null,\n 'postal_code': null,\n 'latitude': null,\n 'longitude': null,\n 'accuracy_radius': null,\n 'time_zone': null\n}\n// Check if the event has an IP address l\nif (event.properties?.$geoip_disable or empty(event.properties?.$ip)) {\n print('geoip disabled or no ip', event.properties, event.properties?.$ip)\n return event\n}\nlet ip := event.properties.$ip\nif (ip == '127.0.0.1') {\n ip := '13.106.122.3' // Spoofing an Australian IP address for local development\n}\nlet response := geoipLookup(ip)\nprint(response)\nif (not response) {\n return event\n}\nlet location := {}\nif (response.city) {\n location['city_name'] := response.city.names?.en\n}\nprint(location)\nif (response.country) {\n location['country_name'] := response.country.names?.en\n location['country_code'] := response.country.isoCode\n}\nif (response.continent) {\n location['continent_name'] := response.continent.names?.en\n location['continent_code'] := response.continent.code\n}\nif (response.postal) {\n location['postal_code'] := response.postal.code\n}\nif (response.location) {\n location['latitude'] := response.location?.latitude\n location['longitude'] := response.location?.longitude\n location['accuracy_radius'] := response.location?.accuracyRadius\n location['time_zone'] := response.location?.timeZone\n}\nif (response.subdivisions) {\n for (let index, subdivision in response.subdivisions) {\n location[f'subdivision_{index + 1}_code'] := subdivision.isoCode\n location[f'subdivision_{index + 1}_name'] := subdivision.names?.en\n }\n}\nlet returnEvent := event\nreturnEvent.properties := returnEvent.properties ?? {}\nreturnEvent.properties.$set := returnEvent.properties.$set ?? {}\nreturnEvent.properties.$set_once := returnEvent.properties.$set_once ?? {}\nfor (let key, value in geoipProperties) {\n if (value != null) {\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n }\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n}\nfor (let key, value in location) {\n returnEvent.properties[f'$geoip_{key}'] := value\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n}\nreturn returnEvent\n "
+ },
+ {
+ "shipped": "2025-01-17",
+ "eligible": false,
+ "source": "\n// Define the properties to be added to the event\nlet geoipProperties := {\n 'city_name': null,\n 'city_confidence': null,\n 'subdivision_2_name': null,\n 'subdivision_2_code': null,\n 'subdivision_1_name': null,\n 'subdivision_1_code': null,\n 'country_name': null,\n 'country_code': null,\n 'continent_name': null,\n 'continent_code': null,\n 'postal_code': null,\n 'latitude': null,\n 'longitude': null,\n 'accuracy_radius': null,\n 'time_zone': null\n}\n// Check if the event has an IP address l\nif (event.properties?.$geoip_disable or empty(event.properties?.$ip)) {\n print('geoip disabled or no ip', event.properties, event.properties?.$ip)\n return event\n}\nlet ip := event.properties.$ip\nif (ip == '127.0.0.1') {\n print('spoofing ip for local development', ip)\n ip := '89.160.20.129'\n}\nlet response := geoipLookup(ip)\nif (not response) {\n print('geoip lookup failed for ip', ip)\n return event\n}\nlet location := {}\nif (response.city) {\n location['city_name'] := response.city.names?.en\n}\nif (response.country) {\n location['country_name'] := response.country.names?.en\n location['country_code'] := response.country.isoCode\n}\nif (response.continent) {\n location['continent_name'] := response.continent.names?.en\n location['continent_code'] := response.continent.code\n}\nif (response.postal) {\n location['postal_code'] := response.postal.code\n}\nif (response.location) {\n location['latitude'] := response.location?.latitude\n location['longitude'] := response.location?.longitude\n location['accuracy_radius'] := response.location?.accuracyRadius\n location['time_zone'] := response.location?.timeZone\n}\nif (response.subdivisions) {\n for (let index, subdivision in response.subdivisions) {\n location[f'subdivision_{index + 1}_code'] := subdivision.isoCode\n location[f'subdivision_{index + 1}_name'] := subdivision.names?.en\n }\n}\nprint('geoip location data for ip:', location) \nlet returnEvent := event\nreturnEvent.properties := returnEvent.properties ?? {}\nreturnEvent.properties.$set := returnEvent.properties.$set ?? {}\nreturnEvent.properties.$set_once := returnEvent.properties.$set_once ?? {}\nfor (let key, value in geoipProperties) {\n if (value != null) {\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n }\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n}\nfor (let key, value in location) {\n returnEvent.properties[f'$geoip_{key}'] := value\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n}\nreturn returnEvent\n "
+ },
+ {
+ "shipped": "2025-01-30",
+ "eligible": true,
+ "source": "\n// Define the properties to be added to the event\nlet geoipProperties := {\n 'city_name': null,\n 'city_confidence': null,\n 'subdivision_2_name': null,\n 'subdivision_2_code': null,\n 'subdivision_1_name': null,\n 'subdivision_1_code': null,\n 'country_name': null,\n 'country_code': null,\n 'continent_name': null,\n 'continent_code': null,\n 'postal_code': null,\n 'latitude': null,\n 'longitude': null,\n 'accuracy_radius': null,\n 'time_zone': null\n}\n// Check if the event has an IP address\nif (event.properties?.$geoip_disable or empty(event.properties?.$ip)) {\n print('geoip disabled or no ip.')\n return event\n}\nlet ip := event.properties.$ip\nif (ip == '127.0.0.1') {\n print('spoofing ip for local development', ip)\n ip := '89.160.20.129'\n}\nlet response := geoipLookup(ip)\nif (not response) {\n print('geoip lookup failed for ip', ip)\n return event\n}\nlet location := {}\nif (response.city) {\n location['city_name'] := response.city.names?.en\n}\nif (response.country) {\n location['country_name'] := response.country.names?.en\n location['country_code'] := response.country.isoCode\n}\nif (response.continent) {\n location['continent_name'] := response.continent.names?.en\n location['continent_code'] := response.continent.code\n}\nif (response.postal) {\n location['postal_code'] := response.postal.code\n}\nif (response.location) {\n location['latitude'] := response.location?.latitude\n location['longitude'] := response.location?.longitude\n location['accuracy_radius'] := response.location?.accuracyRadius\n location['time_zone'] := response.location?.timeZone\n}\nif (response.subdivisions) {\n for (let index, subdivision in response.subdivisions) {\n location[f'subdivision_{index + 1}_code'] := subdivision.isoCode\n location[f'subdivision_{index + 1}_name'] := subdivision.names?.en\n }\n}\nprint('geoip location data for ip:', location) \nlet returnEvent := event\nreturnEvent.properties := returnEvent.properties ?? {}\nreturnEvent.properties.$set := returnEvent.properties.$set ?? {}\nreturnEvent.properties.$set_once := returnEvent.properties.$set_once ?? {}\nfor (let key, value in geoipProperties) {\n if (value != null) {\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n }\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n}\nfor (let key, value in location) {\n returnEvent.properties[f'$geoip_{key}'] := value\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n}\nreturn returnEvent\n "
+ },
+ {
+ "shipped": "2026-01-08",
+ "eligible": true,
+ "source": "\n// Define the properties to be added to the event\nlet geoipProperties := {\n 'city_name': null,\n 'city_confidence': null,\n 'subdivision_2_name': null,\n 'subdivision_2_code': null,\n 'subdivision_1_name': null,\n 'subdivision_1_code': null,\n 'country_name': null,\n 'country_code': null,\n 'continent_name': null,\n 'continent_code': null,\n 'postal_code': null,\n 'latitude': null,\n 'longitude': null,\n 'accuracy_radius': null,\n 'time_zone': null\n}\n// Check if the event has an IP address\nif (event.properties?.$geoip_disable or empty(event.properties?.$ip)) {\n print('geoip disabled or no ip.')\n return event\n}\nlet ip := event.properties.$ip\n// Check for localhost and common private network IPs\nif (ip == '127.0.0.1' or substring(ip, 1, 8) == '192.168.') {\n print('spoofing ip for local development', ip)\n ip := '89.160.20.129'\n}\nlet response := geoipLookup(ip)\nif (not response) {\n print('geoip lookup failed for ip', ip)\n return event\n}\nlet location := {}\nif (response.city) {\n location['city_name'] := response.city.names?.en\n}\nif (response.country) {\n location['country_name'] := response.country.names?.en\n location['country_code'] := response.country.isoCode\n}\nif (response.continent) {\n location['continent_name'] := response.continent.names?.en\n location['continent_code'] := response.continent.code\n}\nif (response.postal) {\n location['postal_code'] := response.postal.code\n}\nif (response.location) {\n location['latitude'] := response.location?.latitude\n location['longitude'] := response.location?.longitude\n location['accuracy_radius'] := response.location?.accuracyRadius\n location['time_zone'] := response.location?.timeZone\n}\nif (response.subdivisions) {\n for (let index, subdivision in response.subdivisions) {\n location[f'subdivision_{index + 1}_code'] := subdivision.isoCode\n location[f'subdivision_{index + 1}_name'] := subdivision.names?.en\n }\n}\nprint('geoip location data for ip:', location) \nlet returnEvent := event\nreturnEvent.properties := returnEvent.properties ?? {}\nreturnEvent.properties.$set := returnEvent.properties.$set ?? {}\nreturnEvent.properties.$set_once := returnEvent.properties.$set_once ?? {}\nfor (let key, value in geoipProperties) {\n if (value != null) {\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n }\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n}\nfor (let key, value in location) {\n returnEvent.properties[f'$geoip_{key}'] := value\n returnEvent.properties.$set[f'$geoip_{key}'] := value\n returnEvent.properties.$set_once[f'$initial_geoip_{key}'] := value\n}\nreturn returnEvent\n "
+ }
+]
diff --git a/nodejs/tests/fixtures/hog-bytecode/69b320537befcd1d8854bb996805ca22d83ca71388a5f18bcf2caaea0f1bf5d8.json b/nodejs/tests/fixtures/hog-bytecode/69b320537befcd1d8854bb996805ca22d83ca71388a5f18bcf2caaea0f1bf5d8.json
new file mode 100644
index 000000000000..8c48cccc5323
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/69b320537befcd1d8854bb996805ca22d83ca71388a5f18bcf2caaea0f1bf5d8.json
@@ -0,0 +1 @@
+["_H",1,32,"city_name",31,32,"city_confidence",31,32,"subdivision_2_name",31,32,"subdivision_2_code",31,32,"subdivision_1_name",31,32,"subdivision_1_code",31,32,"country_name",31,32,"country_code",31,32,"continent_name",31,32,"continent_code",31,32,"postal_code",31,32,"latitude",31,32,"longitude",31,32,"accuracy_radius",31,32,"time_zone",31,42,15,32,"properties",32,"event",1,2,32,"$geoip_disable",48,32,"properties",32,"event",1,2,32,"$ip",48,2,"empty",1,4,2,40,11,32,"geoip skipped.",2,"print",1,35,32,"event",1,1,38,32,"$ip",32,"properties",32,"event",1,3,32,"127.0.0.1",36,1,11,32,"192.168.",36,1,33,1,33,8,2,"substring",3,11,4,2,40,12,32,"spoofing ip for local development",36,1,2,"print",2,35,32,"89.160.20.129",37,1,36,1,2,"geoipLookup",1,36,2,5,40,13,32,"geoip lookup failed for ip",36,1,2,"print",2,35,32,"event",1,1,38,42,0,36,2,32,"city",45,40,16,36,3,32,"city_name",36,2,32,"city",45,32,"names",45,32,"en",48,46,36,2,32,"country",45,40,29,36,3,32,"country_name",36,2,32,"country",45,32,"names",45,32,"en",48,46,36,3,32,"country_code",36,2,32,"country",45,32,"isoCode",45,46,36,2,32,"continent",45,40,29,36,3,32,"continent_name",36,2,32,"continent",45,32,"names",45,32,"en",48,46,36,3,32,"continent_code",36,2,32,"continent",45,32,"code",45,46,36,2,32,"postal",45,40,13,36,3,32,"postal_code",36,2,32,"postal",45,32,"code",45,46,36,2,32,"location",45,40,52,36,3,32,"latitude",36,2,32,"location",45,32,"latitude",48,46,36,3,32,"longitude",36,2,32,"location",45,32,"longitude",48,46,36,3,32,"accuracy_radius",36,2,32,"location",45,32,"accuracyRadius",48,46,36,3,32,"time_zone",36,2,32,"location",45,32,"timeZone",48,46,36,2,32,"subdivisions",45,40,104,36,2,32,"subdivisions",45,36,4,2,"keys",1,36,4,2,"values",1,33,1,36,6,2,"length",1,31,31,36,8,36,7,16,40,66,36,5,36,7,45,37,9,36,6,36,7,45,37,10,36,3,32,"subdivision_",33,1,36,9,6,32,"_code",2,"concat",3,36,10,32,"isoCode",45,46,36,3,32,"subdivision_",33,1,36,9,6,32,"_name",2,"concat",3,36,10,32,"names",45,32,"en",48,46,36,7,33,1,6,37,7,39,-73,35,35,35,35,35,35,35,32,"geoip location data for ip:",36,3,2,"print",2,35,32,"event",1,1,36,4,32,"properties",36,4,32,"properties",45,47,3,35,42,0,46,36,4,32,"properties",45,32,"$set",36,4,32,"properties",45,32,"$set",45,47,3,35,42,0,46,36,4,32,"properties",45,32,"$set_once",36,4,32,"properties",45,32,"$set_once",45,47,3,35,42,0,46,36,0,36,5,2,"keys",1,36,5,2,"values",1,33,1,36,7,2,"length",1,31,31,36,9,36,8,16,40,101,36,6,36,8,45,37,10,36,7,36,8,45,37,11,31,36,11,12,40,36,36,4,32,"properties",45,32,"$set",45,32,"$geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set_once",45,32,"$initial_geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set",45,32,"$geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set_once",45,32,"$initial_geoip_",36,10,2,"concat",2,36,11,46,36,8,33,1,6,37,8,39,-108,35,35,35,35,35,35,35,36,3,36,5,2,"keys",1,36,5,2,"values",1,33,1,36,7,2,"length",1,31,31,36,9,36,8,16,40,74,36,6,36,8,45,37,10,36,7,36,8,45,37,11,36,4,32,"properties",45,32,"$geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set",45,32,"$geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set_once",45,32,"$initial_geoip_",36,10,2,"concat",2,36,11,46,36,8,33,1,6,37,8,39,-81,35,35,35,35,35,35,35,36,4,38,35,35,35,35,35]
diff --git a/nodejs/tests/fixtures/hog-bytecode/a03ecaada5cc237ef936f9660349eb6f93becfffd7d50c58c636eef5060532be.json b/nodejs/tests/fixtures/hog-bytecode/a03ecaada5cc237ef936f9660349eb6f93becfffd7d50c58c636eef5060532be.json
new file mode 100644
index 000000000000..d4254c297ffe
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/a03ecaada5cc237ef936f9660349eb6f93becfffd7d50c58c636eef5060532be.json
@@ -0,0 +1 @@
+["_H",1,32,"city_name",31,32,"city_confidence",31,32,"subdivision_2_name",31,32,"subdivision_2_code",31,32,"subdivision_1_name",31,32,"subdivision_1_code",31,32,"country_name",31,32,"country_code",31,32,"continent_name",31,32,"continent_code",31,32,"postal_code",31,32,"latitude",31,32,"longitude",31,32,"accuracy_radius",31,32,"time_zone",31,42,15,32,"properties",32,"event",1,2,32,"$geoip_disable",48,32,"properties",32,"event",1,2,32,"$ip",48,2,"empty",1,4,2,40,11,32,"geoip disabled or no ip.",2,"print",1,35,32,"event",1,1,38,32,"$ip",32,"properties",32,"event",1,3,32,"127.0.0.1",36,1,11,40,12,32,"spoofing ip for local development",36,1,2,"print",2,35,32,"89.160.20.129",37,1,36,1,2,"geoipLookup",1,36,2,5,40,13,32,"geoip lookup failed for ip",36,1,2,"print",2,35,32,"event",1,1,38,42,0,36,2,32,"city",45,40,16,36,3,32,"city_name",36,2,32,"city",45,32,"names",45,32,"en",48,46,36,2,32,"country",45,40,29,36,3,32,"country_name",36,2,32,"country",45,32,"names",45,32,"en",48,46,36,3,32,"country_code",36,2,32,"country",45,32,"isoCode",45,46,36,2,32,"continent",45,40,29,36,3,32,"continent_name",36,2,32,"continent",45,32,"names",45,32,"en",48,46,36,3,32,"continent_code",36,2,32,"continent",45,32,"code",45,46,36,2,32,"postal",45,40,13,36,3,32,"postal_code",36,2,32,"postal",45,32,"code",45,46,36,2,32,"location",45,40,52,36,3,32,"latitude",36,2,32,"location",45,32,"latitude",48,46,36,3,32,"longitude",36,2,32,"location",45,32,"longitude",48,46,36,3,32,"accuracy_radius",36,2,32,"location",45,32,"accuracyRadius",48,46,36,3,32,"time_zone",36,2,32,"location",45,32,"timeZone",48,46,36,2,32,"subdivisions",45,40,104,36,2,32,"subdivisions",45,36,4,2,"keys",1,36,4,2,"values",1,33,1,36,6,2,"length",1,31,31,36,8,36,7,16,40,66,36,5,36,7,45,37,9,36,6,36,7,45,37,10,36,3,32,"subdivision_",33,1,36,9,6,32,"_code",2,"concat",3,36,10,32,"isoCode",45,46,36,3,32,"subdivision_",33,1,36,9,6,32,"_name",2,"concat",3,36,10,32,"names",45,32,"en",48,46,36,7,33,1,6,37,7,39,-73,35,35,35,35,35,35,35,32,"geoip location data for ip:",36,3,2,"print",2,35,32,"event",1,1,36,4,32,"properties",36,4,32,"properties",45,47,3,35,42,0,46,36,4,32,"properties",45,32,"$set",36,4,32,"properties",45,32,"$set",45,47,3,35,42,0,46,36,4,32,"properties",45,32,"$set_once",36,4,32,"properties",45,32,"$set_once",45,47,3,35,42,0,46,36,0,36,5,2,"keys",1,36,5,2,"values",1,33,1,36,7,2,"length",1,31,31,36,9,36,8,16,40,101,36,6,36,8,45,37,10,36,7,36,8,45,37,11,31,36,11,12,40,36,36,4,32,"properties",45,32,"$set",45,32,"$geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set_once",45,32,"$initial_geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set",45,32,"$geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set_once",45,32,"$initial_geoip_",36,10,2,"concat",2,36,11,46,36,8,33,1,6,37,8,39,-108,35,35,35,35,35,35,35,36,3,36,5,2,"keys",1,36,5,2,"values",1,33,1,36,7,2,"length",1,31,31,36,9,36,8,16,40,74,36,6,36,8,45,37,10,36,7,36,8,45,37,11,36,4,32,"properties",45,32,"$geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set",45,32,"$geoip_",36,10,2,"concat",2,36,11,46,36,4,32,"properties",45,32,"$set_once",45,32,"$initial_geoip_",36,10,2,"concat",2,36,11,46,36,8,33,1,6,37,8,39,-81,35,35,35,35,35,35,35,36,4,38,35,35,35,35,35]
diff --git a/nodejs/tests/fixtures/hog-bytecode/c890442405a1d8372a17f83db9b3acebe1b1f1312a6ea0b9cbb83ba7ef49f656.json b/nodejs/tests/fixtures/hog-bytecode/c890442405a1d8372a17f83db9b3acebe1b1f1312a6ea0b9cbb83ba7ef49f656.json
new file mode 100644
index 000000000000..8a19b722ec50
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/c890442405a1d8372a17f83db9b3acebe1b1f1312a6ea0b9cbb83ba7ef49f656.json
@@ -0,0 +1 @@
+["_H",1,32,"event",1,1,36,0,32,"properties",45,32,"$geoip_disable",29,46,36,0,38,35]