mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
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)
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
.heapsnapshotfiles 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:
- Open Chrome DevTools → Memory tab
- Load the generated
.heapsnapshotfiles - Compare snapshots to identify accumulating objects
- 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.