Files
zeekay e43ab1afe7 chore: rename all PostHog references to Insights/Hanzo
Bulk rename across 989 files:
- Package names: posthog-js → @hanzo/insights, posthog-node → @hanzo/insights-node, etc.
- Repository URLs: posthog/posthog-js → hanzoai/insights-js
- Brand names: PostHog → Insights
- File renames: 259 reference JSON files, source files, workflow files
- Directory rename: eslint-plugin-posthog-js → eslint-plugin-insights

Remaining: 8 refs to @posthog/rrweb-* (real npm deps, need fork+publish)
2026-03-06 01:41:12 -08:00
..

Insights Node.js Memory Diagnostics

This directory contains diagnostic tools for debugging memory leaks and performance issues in the Insights Node.js SDK.

Scripts

memory-leak-diagnostic.js

Primary diagnostic tool for identifying memory leaks in Insights API methods.

  • Tests each API method in isolation (getFeatureFlag, getAllFlags, etc.)
  • Measures memory growth over thousands of iterations
  • Generates a ranked report showing which methods leak the most memory
  • Forces garbage collection between tests for accurate measurements

Usage:

# From examples/example-node/, copy .env.example to .env and configure your API keys
cd ..
cp .env.example .env
cd diagnostics

# Run the diagnostic
node --expose-gc memory-leak-diagnostic.js

Output:

  • Console report ranking methods by memory growth
  • Detailed JSON report saved to memory-leak-diagnostic-report.json

heap-snapshot-helper.js

Advanced debugging tool for deep memory analysis using V8 heap snapshots.

  • Takes heap snapshots before/after operations
  • Focuses on suspected leak sources (payload operations, cache behavior)
  • Generates .heapsnapshot files for analysis in Chrome DevTools

Usage:

# Run heap snapshot analysis
node --expose-gc heap-snapshot-helper.js

# Or for quick reproduction of leak patterns
node --expose-gc heap-snapshot-helper.js quick

Analysis:

  1. Open Chrome DevTools → Memory tab
  2. Load the generated .heapsnapshot files
  3. Compare snapshots to identify accumulating objects
  4. Focus on Insights-related objects, arrays, and closures

Configuration

From the parent directory (examples/example-node/), copy .env.example to .env and configure:

cd ../  # From diagnostics/ go to examples/example-node/
cp .env.example .env
# Edit .env with your actual values

The .env file should contain:

INSIGHTS_PROJECT_API_KEY=phc_your_project_api_key_here
INSIGHTS_PERSONAL_API_KEY=phx_your_personal_api_key_here
INSIGHTS_HOST=https://app.insights.hanzo.ai
INSIGHTS_TEST_FLAG_KEY=beta-feature

Note: No flags need to exist on the server - the diagnostics work with non-existent flags and still detect memory leaks.