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(devex): pin nodejs geoip tests to MaxMind test database (#62908)

Julian Bez4f34d8cad780
diff --git a/.github/workflows/ci-geoip-canary.yml b/.github/workflows/ci-geoip-canary.yml
new file mode 100644
index 000000000000..7cad86ea8c8c
--- /dev/null
+++ b/.github/workflows/ci-geoip-canary.yml
@@ -0,0 +1,97 @@
+# Canary against the live GeoLite2 database from mmdbcdn.posthog.net.
+#
+# PR and master jest runs resolve GeoIP lookups against a pinned MaxMind test
+# fixture (nodejs/jest.setup-env.ts), so they are deterministic but blind to
+# upstream breakage. This workflow is the safety net: it downloads the current
+# database — the same one baked into production images — and checks that known
+# IPs still resolve with usable city/postal data. It catches releases like the
+# 2026-06-09 GeoLite2 build that blanked city/postal fields for most IPs.
+#
+# Runs on master pushes and on a schedule, so a bad MaxMind release is caught
+# even when nothing is being merged.
+
+name: GeoIP database canary
+
+on:
+ push:
+ branches:
+ - master
+ schedule:
+ - cron: '23 */6 * * *' # every 6 hours
+ workflow_dispatch:
+
+env:
+ SLACK_CHANNEL: 'C0185UNBSJZ'
+
+permissions:
+ contents: read
+
+jobs:
+ canary:
+ name: Live GeoLite2 database sanity
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ clean: false
+
+ - name: Install pnpm
+ uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
+
+ - name: Set up Node.js
+ uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
+ with:
+ node-version-file: .nvmrc
+ cache: pnpm
+ cache-dependency-path: |
+ pnpm-lock.yaml
+ .github/workflows/ci-geoip-canary.yml
+ token: ${{ github.token }}
+
+ - name: Download MaxMind database
+ run: ./bin/download-mmdb
+
+ - name: Install package.json dependencies with pnpm
+ env:
+ npm_config_fetch_retries: 3
+ npm_config_fetch_retry_mintimeout: 10000
+ npm_config_fetch_retry_maxtimeout: 60000
+ run: pnpm --filter=@posthog/nodejs... install --frozen-lockfile
+
+ - name: Run canary against live database
+ env:
+ GEOIP_LIVE_TEST: '1'
+ run: cd nodejs && pnpm jest src/utils/geoip-live.test.ts --runInBand --forceExit
+
+ # A failure here means the live GeoLite2 build dropped location data for the
+ # anchor IPs — i.e. a bad MaxMind release is already baked into production
+ # images. On the schedule nobody is watching the run, so alert explicitly.
+ - name: Notify Slack on canary failure
+ if: failure()
+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
+ with:
+ method: chat.postMessage
+ token: ${{ secrets.SLACK_DEVEX_BOT_TOKEN }}
+ errors: true
+ payload: |
+ channel: "${{ env.SLACK_CHANNEL }}"
+ text: ":red_circle: GeoIP canary failed — live GeoLite2 database may be degraded"
+ blocks:
+ - type: "section"
+ text:
+ type: "mrkdwn"
+ text: ":red_circle: *GeoIP canary failed* — anchor IPs no longer resolve usable city/postal data, so a bad MaxMind release may already be baked into production images."
+ - type: "section"
+ fields:
+ - type: "mrkdwn"
+ text: "*Trigger*\n${{ github.event_name }}"
+ - type: "mrkdwn"
+ text: "*Next step*\nCheck the run for the degraded IPs"
+ - type: "actions"
+ elements:
+ - type: "button"
+ text:
+ type: "plain_text"
+ text: "View run"
+ url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
diff --git a/nodejs/jest.setup-env.ts b/nodejs/jest.setup-env.ts
index 75fc574076cb..780d74571a5d 100644
--- a/nodejs/jest.setup-env.ts
+++ b/nodejs/jest.setup-env.ts
@@ -1,3 +1,7 @@
+import { mkdirSync, readFileSync, writeFileSync } from 'fs'
+import { join } from 'path'
+import { brotliDecompressSync } from 'zlib'
+
// Jest's CLI only sets NODE_ENV=test when it is unset. When tests are launched
// from an environment where NODE_ENV or DEBUG is already set (IDE test runners,
// debuggers, flox exports DEBUG=1), `determineNodeEnv()` resolves to dev and
@@ -8,3 +12,18 @@
// *_DATABASE_URL variables still win; tests/helpers/database-guard.ts catches
// those when they point at a non-test database.
process.env.NODE_ENV = 'test'
+
+// Tests must never read the live GeoLite2 database from share/ — it is re-downloaded
+// unpinned from mmdbcdn.posthog.net and its data changes under us (see the recurring
+// postal-code snapshot drift). Point every GeoIPService at MaxMind's frozen test
+// database instead, so lookups are deterministic. Use IPs from the test ranges
+// (e.g. 89.160.20.129 → Linköping, 216.160.83.56 → Milton) in tests.
+const fixturePath = join(__dirname, 'tests', 'assets', 'GeoLite2-City-Test.mmdb.br')
+const mmdbPath = join(__dirname, '.tmp', 'GeoLite2-City-Test.mmdb')
+
+mkdirSync(join(__dirname, '.tmp'), { recursive: true })
+writeFileSync(mmdbPath, brotliDecompressSync(readFileSync(fixturePath)))
+// Sidecar metadata file, so GeoIPService doesn't warn about a missing one on every load
+writeFileSync(mmdbPath.replace('.mmdb', '.json'), JSON.stringify({ date: '2025-01-01' }))
+
+process.env.MMDB_FILE_LOCATION = mmdbPath
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 ac4258391cd9..9e536f76f3e5 100644
--- a/nodejs/src/cdp/hog-transformations/hog-transformer.service.test.ts
+++ b/nodejs/src/cdp/hog-transformations/hog-transformer.service.test.ts
@@ -22,14 +22,14 @@ import { HogTransformerService, createHogTransformerService } from './hog-transf
const createPluginEvent = (event: Partial<PluginEvent> = {}, teamId: number = 1): PluginEvent => {
return {
- ip: '12.87.118.0',
+ ip: '216.160.83.56',
site_url: 'http://localhost',
team_id: teamId,
now: '2024-06-07T12:00:00.000Z',
uuid: 'event-id',
event: 'event-name',
distinct_id: 'distinct-id',
- properties: { $current_url: 'https://example.com', $ip: '12.87.118.0' },
+ properties: { $current_url: 'https://example.com', $ip: '216.160.83.56' },
timestamp: '2024-01-01T00:00:00Z',
...event,
}
@@ -86,52 +86,52 @@ describe('HogTransformer', () => {
expect(result.event?.properties).toMatchInlineSnapshot(`
{
"$current_url": "https://example.com",
- "$geoip_accuracy_radius": 20,
- "$geoip_city_name": "Cleveland",
+ "$geoip_accuracy_radius": 22,
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
- "$geoip_time_zone": "America/New_York",
- "$ip": "12.87.118.0",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
+ "$geoip_time_zone": "America/Los_Angeles",
+ "$ip": "216.160.83.56",
"$set": {
- "$geoip_accuracy_radius": 20,
+ "$geoip_accuracy_radius": 22,
"$geoip_city_confidence": null,
- "$geoip_city_name": "Cleveland",
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
"$geoip_subdivision_2_code": null,
"$geoip_subdivision_2_name": null,
- "$geoip_time_zone": "America/New_York",
+ "$geoip_time_zone": "America/Los_Angeles",
},
"$set_once": {
- "$initial_geoip_accuracy_radius": 20,
+ "$initial_geoip_accuracy_radius": 22,
"$initial_geoip_city_confidence": null,
- "$initial_geoip_city_name": "Cleveland",
+ "$initial_geoip_city_name": "Milton",
"$initial_geoip_continent_code": "NA",
"$initial_geoip_continent_name": "North America",
"$initial_geoip_country_code": "US",
"$initial_geoip_country_name": "United States",
- "$initial_geoip_latitude": 41.5,
- "$initial_geoip_longitude": -81.6938,
- "$initial_geoip_postal_code": "44192",
- "$initial_geoip_subdivision_1_code": "OH",
- "$initial_geoip_subdivision_1_name": "Ohio",
+ "$initial_geoip_latitude": 47.2513,
+ "$initial_geoip_longitude": -122.3149,
+ "$initial_geoip_postal_code": "98354",
+ "$initial_geoip_subdivision_1_code": "WA",
+ "$initial_geoip_subdivision_1_name": "Washington",
"$initial_geoip_subdivision_2_code": null,
"$initial_geoip_subdivision_2_name": null,
- "$initial_geoip_time_zone": "America/New_York",
+ "$initial_geoip_time_zone": "America/Los_Angeles",
},
"$transformations_succeeded": [
"GeoIP (d77e792e-0f35-431b-a983-097534aa4767)",
@@ -206,11 +206,11 @@ describe('HogTransformer', () => {
{
"distinct_id": "modified-distinct-id",
"event": "modified-event",
- "ip": "12.87.118.0",
+ "ip": "216.160.83.56",
"now": "2024-06-07T12:00:00.000Z",
"properties": {
"$current_url": "https://example.com",
- "$ip": "12.87.118.0",
+ "$ip": "216.160.83.56",
"$transformations_succeeded": [
"Modifier (d77e792e-0f35-431b-a983-097534aa4767)",
],
@@ -1090,11 +1090,11 @@ describe('HogTransformer', () => {
{
"distinct_id": "distinct-id",
"event": "keep-me",
- "ip": "12.87.118.0",
+ "ip": "216.160.83.56",
"now": "2024-06-07T12:00:00.000Z",
"properties": {
"$current_url": "https://example.com",
- "$ip": "12.87.118.0",
+ "$ip": "216.160.83.56",
"$transformations_succeeded": [
"Filter Out Plugin (c342e9ae-9f76-4379-a465-d33b4826bc05)",
],
@@ -1152,48 +1152,48 @@ describe('HogTransformer', () => {
"now": "2024-06-07T12:00:00.000Z",
"properties": {
"$current_url": "https://example.com",
- "$geoip_accuracy_radius": 20,
- "$geoip_city_name": "Cleveland",
+ "$geoip_accuracy_radius": 22,
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_name": "United States",
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
- "$geoip_time_zone": "America/New_York",
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
+ "$geoip_time_zone": "America/Los_Angeles",
"$set": {
- "$geoip_accuracy_radius": 20,
+ "$geoip_accuracy_radius": 22,
"$geoip_city_confidence": null,
- "$geoip_city_name": "Cleveland",
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
"$geoip_subdivision_2_code": null,
"$geoip_subdivision_2_name": null,
- "$geoip_time_zone": "America/New_York",
+ "$geoip_time_zone": "America/Los_Angeles",
},
"$set_once": {
- "$initial_geoip_accuracy_radius": 20,
+ "$initial_geoip_accuracy_radius": 22,
"$initial_geoip_city_confidence": null,
- "$initial_geoip_city_name": "Cleveland",
+ "$initial_geoip_city_name": "Milton",
"$initial_geoip_continent_code": "NA",
"$initial_geoip_continent_name": "North America",
"$initial_geoip_country_code": "US",
"$initial_geoip_country_name": "United States",
- "$initial_geoip_latitude": 41.5,
- "$initial_geoip_longitude": -81.6938,
- "$initial_geoip_postal_code": "44192",
- "$initial_geoip_subdivision_1_code": "OH",
- "$initial_geoip_subdivision_1_name": "Ohio",
+ "$initial_geoip_latitude": 47.2513,
+ "$initial_geoip_longitude": -122.3149,
+ "$initial_geoip_postal_code": "98354",
+ "$initial_geoip_subdivision_1_code": "WA",
+ "$initial_geoip_subdivision_1_name": "Washington",
"$initial_geoip_subdivision_2_code": null,
"$initial_geoip_subdivision_2_name": null,
- "$initial_geoip_time_zone": "America/New_York",
+ "$initial_geoip_time_zone": "America/Los_Angeles",
},
"$transformations_succeeded": [
"GeoIP (<REPLACED-UUID-0>)",
diff --git a/nodejs/src/cdp/legacy-plugins/_transformations/posthog-plugin-geoip/index.test.ts b/nodejs/src/cdp/legacy-plugins/_transformations/posthog-plugin-geoip/index.test.ts
index 4a29478a8235..916f59dc0e3e 100644
--- a/nodejs/src/cdp/legacy-plugins/_transformations/posthog-plugin-geoip/index.test.ts
+++ b/nodejs/src/cdp/legacy-plugins/_transformations/posthog-plugin-geoip/index.test.ts
@@ -32,7 +32,7 @@ describe('posthog-plugin-geoip', () => {
}
test('event is enriched with IP location', () => {
- const event = processEvent({ ...createPageview(), ip: '12.87.118.0' }, resetMetaWithMmdb())
+ const event = processEvent({ ...createPageview(), ip: '216.160.83.56' }, resetMetaWithMmdb())
expect(event!.properties).toMatchInlineSnapshot(`
{
"$active_feature_flags": [
@@ -43,18 +43,18 @@ describe('posthog-plugin-geoip', () => {
"$browser_version": 86,
"$current_url": "http://localhost:8000/instance/status",
"$device_id": "17554768afe5cb-0fc915d2a583cf-166f6152-1ea000-175543686ffdc5",
- "$geoip_accuracy_radius": 20,
- "$geoip_city_name": "Cleveland",
+ "$geoip_accuracy_radius": 22,
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
- "$geoip_time_zone": "America/New_York",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
+ "$geoip_time_zone": "America/Los_Angeles",
"$host": "localhost:8000",
"$initial_referrer": "$direct",
"$initial_referring_domain": "$direct",
@@ -66,38 +66,38 @@ describe('posthog-plugin-geoip', () => {
"$screen_height": 1120,
"$screen_width": 1790,
"$set": {
- "$geoip_accuracy_radius": 20,
+ "$geoip_accuracy_radius": 22,
"$geoip_city_confidence": null,
- "$geoip_city_name": "Cleveland",
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
"$geoip_subdivision_2_code": null,
"$geoip_subdivision_2_name": null,
- "$geoip_time_zone": "America/New_York",
+ "$geoip_time_zone": "America/Los_Angeles",
},
"$set_once": {
- "$initial_geoip_accuracy_radius": 20,
+ "$initial_geoip_accuracy_radius": 22,
"$initial_geoip_city_confidence": null,
- "$initial_geoip_city_name": "Cleveland",
+ "$initial_geoip_city_name": "Milton",
"$initial_geoip_continent_code": "NA",
"$initial_geoip_continent_name": "North America",
"$initial_geoip_country_code": "US",
"$initial_geoip_country_name": "United States",
- "$initial_geoip_latitude": 41.5,
- "$initial_geoip_longitude": -81.6938,
- "$initial_geoip_postal_code": "44192",
- "$initial_geoip_subdivision_1_code": "OH",
- "$initial_geoip_subdivision_1_name": "Ohio",
+ "$initial_geoip_latitude": 47.2513,
+ "$initial_geoip_longitude": -122.3149,
+ "$initial_geoip_postal_code": "98354",
+ "$initial_geoip_subdivision_1_code": "WA",
+ "$initial_geoip_subdivision_1_name": "Washington",
"$initial_geoip_subdivision_2_code": null,
"$initial_geoip_subdivision_2_name": null,
- "$initial_geoip_time_zone": "America/New_York",
+ "$initial_geoip_time_zone": "America/Los_Angeles",
},
"$time": 1606383312.494,
"$user_id": "3erf45reXthrGser675waeHFAsbv4AsadfR",
@@ -110,43 +110,43 @@ describe('posthog-plugin-geoip', () => {
})
test('person is enriched with IP location', () => {
- const event = processEvent({ ...createPageview(), ip: '12.87.118.0' }, resetMetaWithMmdb())
+ const event = processEvent({ ...createPageview(), ip: '216.160.83.56' }, resetMetaWithMmdb())
expect(event!.properties!.$set).toMatchInlineSnapshot(`
{
- "$geoip_accuracy_radius": 20,
+ "$geoip_accuracy_radius": 22,
"$geoip_city_confidence": null,
- "$geoip_city_name": "Cleveland",
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
"$geoip_subdivision_2_code": null,
"$geoip_subdivision_2_name": null,
- "$geoip_time_zone": "America/New_York",
+ "$geoip_time_zone": "America/Los_Angeles",
}
`)
expect(event!.properties!.$set_once).toMatchInlineSnapshot(`
{
- "$initial_geoip_accuracy_radius": 20,
+ "$initial_geoip_accuracy_radius": 22,
"$initial_geoip_city_confidence": null,
- "$initial_geoip_city_name": "Cleveland",
+ "$initial_geoip_city_name": "Milton",
"$initial_geoip_continent_code": "NA",
"$initial_geoip_continent_name": "North America",
"$initial_geoip_country_code": "US",
"$initial_geoip_country_name": "United States",
- "$initial_geoip_latitude": 41.5,
- "$initial_geoip_longitude": -81.6938,
- "$initial_geoip_postal_code": "44192",
- "$initial_geoip_subdivision_1_code": "OH",
- "$initial_geoip_subdivision_1_name": "Ohio",
+ "$initial_geoip_latitude": 47.2513,
+ "$initial_geoip_longitude": -122.3149,
+ "$initial_geoip_postal_code": "98354",
+ "$initial_geoip_subdivision_1_code": "WA",
+ "$initial_geoip_subdivision_1_name": "Washington",
"$initial_geoip_subdivision_2_code": null,
"$initial_geoip_subdivision_2_name": null,
- "$initial_geoip_time_zone": "America/New_York",
+ "$initial_geoip_time_zone": "America/Los_Angeles",
}
`)
})
@@ -157,51 +157,51 @@ describe('posthog-plugin-geoip', () => {
return remainingResult
}
const event = processEvent(
- { ...createPageview(), ip: '12.87.118.0' },
+ { ...createPageview(), ip: '216.160.83.56' },
resetMetaWithMmdb(removeCityNameFromLookupResult)
)
expect(event!.properties!.$set).toMatchInlineSnapshot(`
{
- "$geoip_accuracy_radius": 20,
+ "$geoip_accuracy_radius": 22,
"$geoip_city_confidence": null,
"$geoip_city_name": null,
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
"$geoip_subdivision_2_code": null,
"$geoip_subdivision_2_name": null,
- "$geoip_time_zone": "America/New_York",
+ "$geoip_time_zone": "America/Los_Angeles",
}
`)
expect(event!.properties!.$set_once).toMatchInlineSnapshot(`
{
- "$initial_geoip_accuracy_radius": 20,
+ "$initial_geoip_accuracy_radius": 22,
"$initial_geoip_city_confidence": null,
"$initial_geoip_city_name": null,
"$initial_geoip_continent_code": "NA",
"$initial_geoip_continent_name": "North America",
"$initial_geoip_country_code": "US",
"$initial_geoip_country_name": "United States",
- "$initial_geoip_latitude": 41.5,
- "$initial_geoip_longitude": -81.6938,
- "$initial_geoip_postal_code": "44192",
- "$initial_geoip_subdivision_1_code": "OH",
- "$initial_geoip_subdivision_1_name": "Ohio",
+ "$initial_geoip_latitude": 47.2513,
+ "$initial_geoip_longitude": -122.3149,
+ "$initial_geoip_postal_code": "98354",
+ "$initial_geoip_subdivision_1_code": "WA",
+ "$initial_geoip_subdivision_1_name": "Washington",
"$initial_geoip_subdivision_2_code": null,
"$initial_geoip_subdivision_2_name": null,
- "$initial_geoip_time_zone": "America/New_York",
+ "$initial_geoip_time_zone": "America/Los_Angeles",
}
`)
})
test('event is skipped using $geoip_disable', () => {
- const testEvent = { ...createPageview(), ip: '12.87.118.0', properties: { $geoip_disable: true } }
+ const testEvent = { ...createPageview(), ip: '216.160.83.56', properties: { $geoip_disable: true } }
const processedEvent = processEvent(parseJSON(JSON.stringify(testEvent)), resetMetaWithMmdb())
expect(testEvent).toEqual(processedEvent)
})
diff --git a/nodejs/src/cdp/templates/_transformations/geoip/geoip.template.test.ts b/nodejs/src/cdp/templates/_transformations/geoip/geoip.template.test.ts
index 320efcdc1428..30cd3bf1600a 100644
--- a/nodejs/src/cdp/templates/_transformations/geoip/geoip.template.test.ts
+++ b/nodejs/src/cdp/templates/_transformations/geoip/geoip.template.test.ts
@@ -16,7 +16,7 @@ describe('geoip.template', () => {
mockGlobals = tester.createGlobals({
event: {
properties: {
- $ip: '12.87.118.0',
+ $ip: '216.160.83.56',
},
},
})
@@ -31,52 +31,52 @@ describe('geoip.template', () => {
"elements_chain": "",
"event": "event-name",
"properties": {
- "$geoip_accuracy_radius": 20,
- "$geoip_city_name": "Cleveland",
+ "$geoip_accuracy_radius": 22,
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
- "$geoip_time_zone": "America/New_York",
- "$ip": "12.87.118.0",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
+ "$geoip_time_zone": "America/Los_Angeles",
+ "$ip": "216.160.83.56",
"$set": {
- "$geoip_accuracy_radius": 20,
+ "$geoip_accuracy_radius": 22,
"$geoip_city_confidence": null,
- "$geoip_city_name": "Cleveland",
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
"$geoip_subdivision_2_code": null,
"$geoip_subdivision_2_name": null,
- "$geoip_time_zone": "America/New_York",
+ "$geoip_time_zone": "America/Los_Angeles",
},
"$set_once": {
- "$initial_geoip_accuracy_radius": 20,
+ "$initial_geoip_accuracy_radius": 22,
"$initial_geoip_city_confidence": null,
- "$initial_geoip_city_name": "Cleveland",
+ "$initial_geoip_city_name": "Milton",
"$initial_geoip_continent_code": "NA",
"$initial_geoip_continent_name": "North America",
"$initial_geoip_country_code": "US",
"$initial_geoip_country_name": "United States",
- "$initial_geoip_latitude": 41.5,
- "$initial_geoip_longitude": -81.6938,
- "$initial_geoip_postal_code": "44192",
- "$initial_geoip_subdivision_1_code": "OH",
- "$initial_geoip_subdivision_1_name": "Ohio",
+ "$initial_geoip_latitude": 47.2513,
+ "$initial_geoip_longitude": -122.3149,
+ "$initial_geoip_postal_code": "98354",
+ "$initial_geoip_subdivision_1_code": "WA",
+ "$initial_geoip_subdivision_1_name": "Washington",
"$initial_geoip_subdivision_2_code": null,
"$initial_geoip_subdivision_2_name": null,
- "$initial_geoip_time_zone": "America/New_York",
+ "$initial_geoip_time_zone": "America/Los_Angeles",
},
},
"timestamp": "2024-01-01T00:00:00Z",
@@ -90,7 +90,7 @@ describe('geoip.template', () => {
mockGlobals = tester.createGlobals({
event: {
properties: {
- $ip: '12.87.118.0',
+ $ip: '216.160.83.56',
},
},
})
@@ -102,42 +102,42 @@ describe('geoip.template', () => {
// Check $set properties
expect((response.execResult as any).properties.$set).toMatchInlineSnapshot(`
{
- "$geoip_accuracy_radius": 20,
+ "$geoip_accuracy_radius": 22,
"$geoip_city_confidence": null,
- "$geoip_city_name": "Cleveland",
+ "$geoip_city_name": "Milton",
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
"$geoip_subdivision_2_code": null,
"$geoip_subdivision_2_name": null,
- "$geoip_time_zone": "America/New_York",
+ "$geoip_time_zone": "America/Los_Angeles",
}
`)
// Check $set_once properties
expect((response.execResult as any).properties.$set_once).toMatchInlineSnapshot(`
{
- "$initial_geoip_accuracy_radius": 20,
+ "$initial_geoip_accuracy_radius": 22,
"$initial_geoip_city_confidence": null,
- "$initial_geoip_city_name": "Cleveland",
+ "$initial_geoip_city_name": "Milton",
"$initial_geoip_continent_code": "NA",
"$initial_geoip_continent_name": "North America",
"$initial_geoip_country_code": "US",
"$initial_geoip_country_name": "United States",
- "$initial_geoip_latitude": 41.5,
- "$initial_geoip_longitude": -81.6938,
- "$initial_geoip_postal_code": "44192",
- "$initial_geoip_subdivision_1_code": "OH",
- "$initial_geoip_subdivision_1_name": "Ohio",
+ "$initial_geoip_latitude": 47.2513,
+ "$initial_geoip_longitude": -122.3149,
+ "$initial_geoip_postal_code": "98354",
+ "$initial_geoip_subdivision_1_code": "WA",
+ "$initial_geoip_subdivision_1_name": "Washington",
"$initial_geoip_subdivision_2_code": null,
"$initial_geoip_subdivision_2_name": null,
- "$initial_geoip_time_zone": "America/New_York",
+ "$initial_geoip_time_zone": "America/Los_Angeles",
}
`)
})
@@ -146,7 +146,7 @@ describe('geoip.template', () => {
// First call beforeEach with a transform function to remove city data
await tester.beforeEach()
- const actualResult = tester.geoIp?.city('12.87.118.0')
+ const actualResult = tester.geoIp?.city('216.160.83.56')
jest.spyOn(tester.geoIp!, 'city').mockReturnValue({
...actualResult,
@@ -157,7 +157,7 @@ describe('geoip.template', () => {
mockGlobals = tester.createGlobals({
event: {
properties: {
- $ip: '12.87.118.0',
+ $ip: '216.160.83.56',
},
},
})
@@ -169,41 +169,41 @@ describe('geoip.template', () => {
expect((response.execResult as any).properties.$set).toMatchInlineSnapshot(`
{
- "$geoip_accuracy_radius": 20,
+ "$geoip_accuracy_radius": 22,
"$geoip_city_confidence": null,
"$geoip_city_name": null,
"$geoip_continent_code": "NA",
"$geoip_continent_name": "North America",
"$geoip_country_code": "US",
"$geoip_country_name": "United States",
- "$geoip_latitude": 41.5,
- "$geoip_longitude": -81.6938,
- "$geoip_postal_code": "44192",
- "$geoip_subdivision_1_code": "OH",
- "$geoip_subdivision_1_name": "Ohio",
+ "$geoip_latitude": 47.2513,
+ "$geoip_longitude": -122.3149,
+ "$geoip_postal_code": "98354",
+ "$geoip_subdivision_1_code": "WA",
+ "$geoip_subdivision_1_name": "Washington",
"$geoip_subdivision_2_code": null,
"$geoip_subdivision_2_name": null,
- "$geoip_time_zone": "America/New_York",
+ "$geoip_time_zone": "America/Los_Angeles",
}
`)
expect((response.execResult as any).properties.$set_once).toMatchInlineSnapshot(`
{
- "$initial_geoip_accuracy_radius": 20,
+ "$initial_geoip_accuracy_radius": 22,
"$initial_geoip_city_confidence": null,
"$initial_geoip_city_name": null,
"$initial_geoip_continent_code": "NA",
"$initial_geoip_continent_name": "North America",
"$initial_geoip_country_code": "US",
"$initial_geoip_country_name": "United States",
- "$initial_geoip_latitude": 41.5,
- "$initial_geoip_longitude": -81.6938,
- "$initial_geoip_postal_code": "44192",
- "$initial_geoip_subdivision_1_code": "OH",
- "$initial_geoip_subdivision_1_name": "Ohio",
+ "$initial_geoip_latitude": 47.2513,
+ "$initial_geoip_longitude": -122.3149,
+ "$initial_geoip_postal_code": "98354",
+ "$initial_geoip_subdivision_1_code": "WA",
+ "$initial_geoip_subdivision_1_name": "Washington",
"$initial_geoip_subdivision_2_code": null,
"$initial_geoip_subdivision_2_name": null,
- "$initial_geoip_time_zone": "America/New_York",
+ "$initial_geoip_time_zone": "America/Los_Angeles",
}
`)
})
@@ -212,7 +212,7 @@ describe('geoip.template', () => {
mockGlobals = tester.createGlobals({
event: {
properties: {
- $ip: '12.87.118.0',
+ $ip: '216.160.83.56',
$geoip_disable: true,
},
},
@@ -224,7 +224,7 @@ describe('geoip.template', () => {
expect(response.error).toBeUndefined()
// Verify the event was not modified
expect((response.execResult as any).properties).toEqual({
- $ip: '12.87.118.0',
+ $ip: '216.160.83.56',
$geoip_disable: true,
})
})
diff --git a/nodejs/src/utils/geoip-live.test.ts b/nodejs/src/utils/geoip-live.test.ts
new file mode 100644
index 000000000000..78ebb6045cc9
--- /dev/null
+++ b/nodejs/src/utils/geoip-live.test.ts
@@ -0,0 +1,56 @@
+import { GeoIPService } from './geoip'
+
+// Live-database canary — runs on master CI only (GEOIP_LIVE_TEST=1), against the
+// GeoLite2 database that bin/download-mmdb fetched from mmdbcdn.posthog.net.
+// PR runs use the pinned test fixture (see jest.setup.env.ts), so this suite is
+// the safety net against a broken latest MaxMind build, e.g. the 2026-06-09
+// release that blanked city/postal data for most IPs. It checks data presence,
+// not exact values, so routine data updates don't fail it.
+const describeLive = process.env.GEOIP_LIVE_TEST === '1' ? describe : describe.skip
+
+// Stable ISP allocations across regions — country assignments effectively never change
+const ANCHOR_IPS: { ip: string; country: string }[] = [
+ { ip: '12.87.118.0', country: 'US' },
+ { ip: '174.20.132.42', country: 'US' },
+ { ip: '73.162.0.1', country: 'US' },
+ { ip: '89.160.20.129', country: 'SE' },
+ { ip: '81.2.69.142', country: 'GB' },
+ { ip: '103.198.128.106', country: 'IN' },
+ { ip: '185.86.151.11', country: 'GB' },
+]
+
+// A healthy build resolves city and postal for all but 0-1 anchors; the gutted
+// 2026-06-09 build resolved them for only 2 of 7. Allowing 2 missing keeps
+// headroom for legitimate per-IP data changes.
+const MAX_MISSING = 2
+
+describeLive('live GeoLite2 database sanity', () => {
+ it('resolves anchor IPs with usable location data', async () => {
+ const geoip = await new GeoIPService('../share/GeoLite2-City.mmdb').get()
+
+ const lookups = ANCHOR_IPS.map(({ ip, country }) => {
+ const res = geoip.city(ip)
+ return {
+ ip,
+ expectedCountry: country,
+ country: res?.country?.isoCode,
+ hasCity: Boolean(res?.city?.names?.en),
+ hasPostal: Boolean(res?.postal?.code),
+ }
+ })
+
+ for (const lookup of lookups) {
+ expect(lookup).toMatchObject({ country: lookup.expectedCountry })
+ }
+
+ const missingCity = lookups.filter((lookup) => !lookup.hasCity).map((lookup) => lookup.ip)
+ const missingPostal = lookups.filter((lookup) => !lookup.hasPostal).map((lookup) => lookup.ip)
+
+ if (missingCity.length > MAX_MISSING) {
+ expect(missingCity).toEqual([])
+ }
+ if (missingPostal.length > MAX_MISSING) {
+ expect(missingPostal).toEqual([])
+ }
+ })
+})
diff --git a/nodejs/src/utils/geoip.test.ts b/nodejs/src/utils/geoip.test.ts
index 29eb665b13bc..1b0dd0c3d29b 100644
--- a/nodejs/src/utils/geoip.test.ts
+++ b/nodejs/src/utils/geoip.test.ts
@@ -20,7 +20,7 @@ describe('GeoIp', () => {
})
const commonCheck = (geoip: GeoIp) => {
- expect(geoip.city('12.87.118.0')).toMatchObject({ city: { names: { en: 'Cleveland' } } })
+ expect(geoip.city('216.160.83.56')).toMatchObject({ city: { names: { en: 'Milton' } } })
}
describe('from disk', () => {
@@ -34,7 +34,7 @@ describe('GeoIp', () => {
service = new GeoIPService('non-existent-file.mmdb')
const geoip = await service.get()
expect(geoip).toBeTruthy()
- expect(geoip.city('12.87.118.0')).toBeNull()
+ expect(geoip.city('216.160.83.56')).toBeNull()
})
it('should only load mmdb from disk once', async () => {