{"id":12958,"library":"chrome-trace-event","title":"Chrome Trace Event Logger for Node.js","description":"The `chrome-trace-event` library provides a programmatic interface for Node.js applications to generate detailed performance logs in Google's Trace Event format. These logs, typically JSON files, can then be loaded and visualized using powerful analysis tools such as `chrome://tracing` in Chrome DevTools or Google's `trace-viewer`. This allows developers to gain deep insights into their application's execution flow, identify bottlenecks, and understand inter-process communication or asynchronous operations. The current stable version is 1.0.4, which was last published over two years ago. Due to its age and lack of recent updates, its release cadence is effectively dormant. Its primary differentiator is its straightforward approach to producing a universally accepted profiling format that integrates directly into established Chrome-based visualization ecosystems.","status":"maintenance","version":"1.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/samccone/chrome-trace-event","tags":["javascript","trace-event","trace","event","trace-viewer","google","typescript"],"install":[{"cmd":"npm install chrome-trace-event","lang":"bash","label":"npm"},{"cmd":"yarn add chrome-trace-event","lang":"bash","label":"yarn"},{"cmd":"pnpm add chrome-trace-event","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For modern Node.js ESM projects, use named ES module imports. The package ships TypeScript types, supporting this import style.","wrong":"const Tracer = require('chrome-trace-event').Tracer;","symbol":"Tracer","correct":"import { Tracer } from 'chrome-trace-event';"},{"note":"This is the CommonJS import style demonstrated in the package's README, suitable for older Node.js projects or CJS modules.","symbol":"Tracer (CommonJS)","correct":"const Tracer = require('chrome-trace-event').Tracer;"},{"note":"Import `TraceEvent` for type declarations if you need to work with the raw trace event structure in TypeScript.","symbol":"TraceEvent","correct":"import type { TraceEvent } from 'chrome-trace-event';"}],"quickstart":{"code":"import { Tracer } from 'chrome-trace-event';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nconst outPath = path.join(process.cwd(), 'my-trace.json');\nconst trace = new Tracer({\n    noStream: true // Collect events in memory until flushed\n});\n\n// Example: Record a duration event\ntrace.begin('main', 'heavyComputation', { duration: 'long' });\n\nfunction simulateWork(ms: number) {\n    const start = Date.now();\n    while (Date.now() - start < ms) {\n        // Busy-wait to simulate CPU-bound work\n    }\n}\n\ntrace.instant('main', 'startWork', { message: 'Starting simulated work' });\nsimulateWork(100);\n\ntrace.counter('main', 'progress', { value: 25 });\nsimulateWork(200);\n\ntrace.counter('main', 'progress', { value: 75 });\nsimulateWork(150);\n\ntrace.end('main', 'heavyComputation');\ntrace.instant('main', 'endWork', { message: 'Finished simulated work' });\n\nconst stream = fs.createWriteStream(outPath);\ntrace.pipe(stream);\n\nstream.on('finish', () => {\n    console.log(`Trace data written to ${outPath}`);\n    console.log('Open chrome://tracing in your browser and load this file.');\n});\n\ntrace.flush();\n","lang":"typescript","description":"This quickstart demonstrates how to initialize the Tracer, record various event types (duration, instant, counter), and write the collected trace data to a JSON file. The file can then be loaded into Chrome DevTools (`chrome://tracing`) for visualization."},"warnings":[{"fix":"Review the package's GitHub repository for forks or community-maintained versions if encountering compatibility issues with modern Node.js environments. Consider wrapping it or using a more actively maintained tracing library if extensive new features are required.","message":"The `chrome-trace-event` package has not been updated in over two years, with version 1.0.4 being the latest release. While still functional, this means it may not leverage the latest Node.js features, TypeScript syntax, or address compatibility issues with very recent runtime changes.","severity":"gotcha","affected_versions":">=1.0.4"},{"fix":"Always use ES module import syntax (`import { Tracer } from 'chrome-trace-event';`) in ES module contexts. If you must use `require` in an ESM file, you'll need to use `createRequire` from the `module` built-in module.","message":"The documentation and `Usage` examples primarily show CommonJS `require()` syntax. In modern Node.js projects using ES Modules, direct use of `require` will lead to errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statement to `import { Tracer } from 'chrome-trace-event';` and ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json` or `.mjs` file extension).","cause":"Attempting to use `require()` in an ECMAScript Module (ESM) file, which does not natively support CommonJS `require`.","error":"ReferenceError: require is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}