{"id":20806309,"url":"https://github.com/nodesource/ah-collector","last_synced_at":"2025-12-26T04:57:15.206Z","repository":{"id":57174663,"uuid":"79390181","full_name":"nodesource/ah-collector","owner":"nodesource","description":"Super light wrapper around async-hooks to collect information about resources created during async operations.","archived":false,"fork":false,"pushed_at":"2017-02-09T19:23:49.000Z","size":1205,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-18T13:28:36.195Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://nodesource.github.io/ah-collector","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodesource.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-18T22:16:05.000Z","updated_at":"2021-12-26T19:11:37.000Z","dependencies_parsed_at":"2022-08-29T00:11:08.469Z","dependency_job_id":null,"html_url":"https://github.com/nodesource/ah-collector","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodesource%2Fah-collector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodesource%2Fah-collector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodesource%2Fah-collector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodesource%2Fah-collector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodesource","download_url":"https://codeload.github.com/nodesource/ah-collector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243152876,"owners_count":20244657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T19:19:15.199Z","updated_at":"2025-12-26T04:57:15.180Z","avatar_url":"https://github.com/nodesource.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ah-collector\n\nSuper light wrapper around async-hooks to collect information about resources created during async operations.\n\n```js\nconst ActivityCollector = require('ah-collector')\n\nfunction captureStack(hook, { uid, type, triggerId }, resource) {\n  // Predicate to decide if a stack should be captured or not.\n  // Capture only inits of the TIMERWRAP but everything of the Timeout.\n  return type === 'Timeout' || (type === 'TIMERWRAP' \u0026\u0026 hook === 'init')\n}\n\nconst collector = new ActivityCollector({\n    start: process.hrtime()\n  , captureStack\n}).enable()\n\nsetTimeout(ontimeout, 100)\n\nfunction ontimeout() {\n  collector\n    .processStacks()\n    .dump()\n}\n```\n\n## Requirements\n\nNeeds async hooks feature, therefore build from [this PR](https://github.com/nodejs/node/pull/8531) for now.\n\n[EPS document](https://github.com/nodejs/node-eps/pull/18)\n\n[Documentation in\nprogress](https://github.com/nodesource/node/blob/trevnorris-async-wrap-eps-impl%2Bdocs/doc/api/async_hooks.md)\n\n## Installation\n\n    npm install ah-collector\n\n## [API](https://nodesource.github.io/ah-collector)\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n### ActivityCollector\n\nCreates an instance of an ActivityCollector\n\n**Parameters**\n\n-   `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** \n    -   `$0.start` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)\u0026lt;[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)\u003e** start time obtained via `process.hrtime()`\n    -   `$0.stackCapturer` **StackCapturer?** which is used to decide if a stack\n        should be captured as well as to capture and process it @see\n        [thlorenz/ah-stack-capturer](https://github.com/nodesource/ah-stack-capturer)\n        The default capturer used doesn't ever capture a stack so this feature is\n        turned off by default. (optional, default `defaultStackCapturer`)\n    -   `$0.requireInit` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** when `true` any activities whose `init` hook we missed\n        are ignored even if we see `before`, `after` and/or `destroy` hooks. (optional, default `false`)\n\nReturns **[ActivityCollector](#activitycollector)** instance of ActivityCollector\n\n### activityCollector.enable\n\nEnables the collection of async hooks.\n**Needs to be called** as otherwise nothing will be collected.\n\nReturns **[ActivityCollector](#activitycollector)** activityCollector\n\n### activityCollector.disable\n\nDisables the collection of async hooks.\nNothing will be collected until `activityCollector.enable()` is called.\n\nReturns **[ActivityCollector](#activitycollector)** activityCollector\n\n### activityCollector.clear\n\nClears all currently collected activity.\n\nReturns **[ActivityCollector](#activitycollector)** activityCollector\n\n### activityCollector.activitiesOfTypes\n\nReturns an Array of all activities collected so far that are of the specified type(s).\n\n**Parameters**\n\n-   `type` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)\u0026lt;[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)\u003e | [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** the type to match\n\nReturns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** activities matching the specified type(s)\n\n### activityCollector.activities\n\nA `getter` that returns a map of all activities collected so far.\n\nReturns **[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)** activities\n\n### activityCollector.activitiesArray\n\nA `getter` that returns an Array  of all activities collected so far.\n\nReturns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** activities\n\n### activityCollector.processStacks\n\nProcesses all stacks that were captured for specific activities\nThis is done in line, i.e. the actual stacks of the activity objects\nare modified.\n\nReturns **[ActivityCollector](#activitycollector)** activityCollector\n\n### activityCollector.dump\n\nDumps all so far collected activities to the console.\nThis is useful for diagnostic purposes.\n\nIf no arguments are provided, all activities are dumped.\n\n**Parameters**\n\n-   `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** allow tweaking which activities are dumped and how\n    -   `opts.types` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)\u0026lt;[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)\u003e | [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** type(s) to dump\n    -   `opts.stage` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the stage to print as the title of the dump\n    -   `opts.depth` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the depth with which the dumped object is dumped\n\nReturns **[ActivityCollector](#activitycollector)** activityCollector\n\n### activityCollector.dumpTypes\n\nDumps all types in the order they were collected including\nid and trigger id.\n\nExample: `FSREQWRAP:id:triggerId`\n\n### ActivityCollector#UNKNOWN_TYPE\n\nStatic getter that denotes the type given to activities whose type is unkown since\nwe missed their `init` event.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodesource%2Fah-collector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodesource%2Fah-collector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodesource%2Fah-collector/lists"}