{"_id":"@bradleyheubel/pyroscope-nodejs","_rev":"4-b720a52e77d69302920266dec1c45f36","time":{"created":"2023-07-13T07:49:15.451Z","0.2.6":"2023-07-13T07:38:48.872Z","modified":"2023-07-13T07:50:27.431Z","0.2.7":"2023-07-13T07:49:15.713Z","0.2.8":"2023-07-13T07:50:27.270Z"},"name":"@bradleyheubel/pyroscope-nodejs","dist-tags":{"latest":"0.2.8"},"versions":{"0.2.7":{"name":"@bradleyheubel/pyroscope-nodejs","version":"0.2.7","description":"pyroscope nodejs package","exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"}},"main":"./dist/cjs/index.js","types":"dist/types/index.d.js","scripts":{"prepublishOnly":"pinst --disable","postpublish":"pinst --enable","build":"npm run build:cjs && npm run build:esm && npm run build:types","build:cjs":"node tools/cleanup cjs && tsc -p config/tsconfig.cjs.json","build:esm":"node tools/cleanup esm && tsc -p config/tsconfig.esm.json && echo '{\"type\":\"module\"}' >./dist/esm/package.json","build:types":"node tools/cleanup types && tsc -p config/tsconfig.types.json","clean":"node tools/cleanup","package":"npm run build && npm pack","test":"jest --no-cache --runInBand --forceExit --detectOpenHandles","test:cov":"jest --coverage --no-cache --runInBand --forceExit --detectOpenHandles","addscope":"node tools/packagejson name @pyroscope"},"publishConfig":{"access":"public"},"keywords":[],"author":{"name":"Pyroscope Team","email":"hello@pyroscope.io"},"license":"Apache-2.0","homepage":"https://github.com/pyroscope-io/pyroscope-nodejs","repository":{"type":"git","url":"git+ssh://git@github.com/pyroscope-io/pyroscope-nodejs.git"},"bugs":{"url":"https://github.com/pyroscope-io/pyroscope-nodejs/issues"},"dependencies":{"axios":"^0.26.1","debug":"^4.3.3","form-data":"^4.0.0","pprof":"^3.2.0","regenerator-runtime":"^0.13.11","source-map":"^0.7.3"},"devDependencies":{"@commitlint/cli":"^13.1.0","@commitlint/config-conventional":"^13.1.0","@types/debug":"^4.1.7","@types/express":"^4.17.13","@types/jest":"^27.0.1","@types/source-map":"^0.5.7","@types/supertest":"^2.0.12","@typescript-eslint/eslint-plugin":"^4.31.1","@typescript-eslint/parser":"^4.31.1","eslint":"^7.32.0","eslint-config-prettier":"^8.3.0","eslint-plugin-prettier":"^4.0.0","express":"^4.18.1","husky":"^7.0.2","jest":"^27.2.0","pinst":"^2.1.6","prettier":"^2.4.0","supertest":"^6.2.3","ts-jest":"^27.0.5","ts-loader":"^9.2.5","typescript":"^4.4.3","webpack":"^5.52.1","webpack-cli":"^4.8.0"},"engines":{"node":"^12.20.0 || >=14.13.1"},"gitHead":"71a3f7c7ab59a7a16706ccbb1055cbf55bbc7b2c","_id":"@bradleyheubel/pyroscope-nodejs@0.2.7","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-o7WIESy7PdMsdeT6arYGhB/Jn0XCDPfsff0Nns4ixRDVNk4nDPEENy/xkxvBEHmPY4ymqkjBH7rET4QdGDVzlw==","shasum":"2d31e51b01cd2674eb88b24b71187a1a3f021fc8","tarball":"https://registry.npmjs.org/@bradleyheubel/pyroscope-nodejs/-/pyroscope-nodejs-0.2.7.tgz","fileCount":3,"unpackedSize":19452,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGN/ds4Mpa/ev2gZr1VpQFOSSmHV1APvGWs/Np2fFcs9AiA+Qs2c/YimZEByt6nSEMvXLoCLpKbZxPCarUSax23jfQ=="}]},"_npmUser":{"name":"bradleyheubel","email":"bradley.heubel@gmail.com"},"directories":{},"maintainers":[{"name":"bradleyheubel","email":"bradley.heubel@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pyroscope-nodejs_0.2.7_1689234555555_0.521897373708065"},"_hasShrinkwrap":false},"0.2.8":{"name":"@bradleyheubel/pyroscope-nodejs","version":"0.2.8","description":"pyroscope nodejs package","exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"}},"main":"./dist/cjs/index.js","types":"dist/types/index.d.js","scripts":{"prepublishOnly":"pinst --disable","postpublish":"pinst --enable","build":"npm run build:cjs && npm run build:esm && npm run build:types","build:cjs":"node tools/cleanup cjs && tsc -p config/tsconfig.cjs.json","build:esm":"node tools/cleanup esm && tsc -p config/tsconfig.esm.json && echo '{\"type\":\"module\"}' >./dist/esm/package.json","build:types":"node tools/cleanup types && tsc -p config/tsconfig.types.json","clean":"node tools/cleanup","package":"npm run build && npm pack","test":"jest --no-cache --runInBand --forceExit --detectOpenHandles","test:cov":"jest --coverage --no-cache --runInBand --forceExit --detectOpenHandles","addscope":"node tools/packagejson name @pyroscope"},"publishConfig":{"access":"public"},"keywords":[],"author":{"name":"Pyroscope Team","email":"hello@pyroscope.io"},"license":"Apache-2.0","homepage":"https://github.com/pyroscope-io/pyroscope-nodejs","repository":{"type":"git","url":"git+ssh://git@github.com/pyroscope-io/pyroscope-nodejs.git"},"bugs":{"url":"https://github.com/pyroscope-io/pyroscope-nodejs/issues"},"dependencies":{"axios":"^0.26.1","debug":"^4.3.3","form-data":"^4.0.0","pprof":"^3.2.0","regenerator-runtime":"^0.13.11","source-map":"^0.7.3"},"devDependencies":{"@commitlint/cli":"^13.1.0","@commitlint/config-conventional":"^13.1.0","@types/debug":"^4.1.7","@types/express":"^4.17.13","@types/jest":"^27.0.1","@types/source-map":"^0.5.7","@types/supertest":"^2.0.12","@typescript-eslint/eslint-plugin":"^4.31.1","@typescript-eslint/parser":"^4.31.1","eslint":"^7.32.0","eslint-config-prettier":"^8.3.0","eslint-plugin-prettier":"^4.0.0","express":"^4.18.1","husky":"^7.0.2","jest":"^27.2.0","pinst":"^2.1.6","prettier":"^2.4.0","supertest":"^6.2.3","ts-jest":"^27.0.5","ts-loader":"^9.2.5","typescript":"^4.4.3","webpack":"^5.52.1","webpack-cli":"^4.8.0"},"engines":{"node":"^12.20.0 || >=14.13.1"},"gitHead":"71a3f7c7ab59a7a16706ccbb1055cbf55bbc7b2c","_id":"@bradleyheubel/pyroscope-nodejs@0.2.8","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-rBlYqjqr5/GtbEV2Mk5+kEQgAiwVeqrJIV5zH9GaNu68d17Mtc870Z05d2cL6M+Af1hGZTm87x9JuhxbtnGdnQ==","shasum":"acb3d6cf5c25d79f12e5df646192083639d73905","tarball":"https://registry.npmjs.org/@bradleyheubel/pyroscope-nodejs/-/pyroscope-nodejs-0.2.8.tgz","fileCount":10,"unpackedSize":50129,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDHFHzyrDJzGLa9hCukf5N3hKJvvMQE4K5wd3FWE6gSjQIhAOmhoXOkcCKPC9U2YDxYW9dPOHlToClXoZS3yX5jPJ7+"}]},"_npmUser":{"name":"bradleyheubel","email":"bradley.heubel@gmail.com"},"directories":{},"maintainers":[{"name":"bradleyheubel","email":"bradley.heubel@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pyroscope-nodejs_0.2.8_1689234627062_0.26822369404575475"},"_hasShrinkwrap":false}},"maintainers":[{"name":"bradleyheubel","email":"bradley.heubel@gmail.com"}],"description":"pyroscope nodejs package","homepage":"https://github.com/pyroscope-io/pyroscope-nodejs","keywords":[],"repository":{"type":"git","url":"git+ssh://git@github.com/pyroscope-io/pyroscope-nodejs.git"},"author":{"name":"Pyroscope Team","email":"hello@pyroscope.io"},"bugs":{"url":"https://github.com/pyroscope-io/pyroscope-nodejs/issues"},"license":"Apache-2.0","readme":"# Pyroscope nodejs package\n\n## Running Pyroscope server\nIn order to send data from your node application to Pyroscope, you'll first need to run the Pyroscope server. If on a mac you can simply do this with\n```\n# install pyroscope\nbrew install pyroscope-io/brew/pyroscope\n\n# start pyroscope server:\npyroscope server\n```\nor if not then see [the documentation](https://github.com/pyroscope-io/pyroscope#add-pyroscope-server-locally-in-2-steps) for more info on how to start the server.\n\n## Configuration\n\n| env var                       | default                 | description                                                          |\n| ----------------------------- | ----------------------- | -------------------------------------------------------------------- |\n| `PYROSCOPE_SAMPLING_INTERVAL` | `10`                    | The interval in milliseconds between samples.                        |\n| `PYROSCOPE_SAMPLING_DURATION` | `10000` (10s)           | The duration in milliseconds for which you want to collect a sample. |\n| `PYROSCOPE_SERVER_ADDRESS`    | `http://localhost:4040` | The address of the Pyroscope server.                                 |\n| `PYROSCOPE_APPLICATION_NAME`  | `\"\"`                    | The application name used when uploading profiling data.             |\n| `PYROSCOPE_AUTH_TOKEN`        | N/A                     | The authorization token used to upload profiling data.               |\n\n## Modes\n\nPyroscope supports two main operation modes: \n * Push mode\n * Pull mode\n\nPush mode means the package itself uploads profile data to a pyroscope server, when pull mode means you provide pyroscope server with an endponts to scrape profile data\n\nNodeJS Pyroscope module supports collecting wall-time and heap. More details you may find [here](https://cloud.google.com/profiler/docs/concepts-profiling)\n\n## Push mode\n\nUsage is differs for first you need to import and init pyroscope module.\nModule is available for both CommonJS and ESM variants, so you can use it the way it fits your project.\n\n### Javascript\n\n```javascript\nconst Pyroscope = require('pyroscope');\n\nPyroscope.init({serverAddress: 'http://pyroscope:4040', appName: 'nodejs'});\nPyroscope.start()\n```\n\n### Typescript:\n```typescript\nimport Pyroscope from 'pyroscope';\n\nPyroscope.init({serverAddress: 'http://pyroscope:4040', appName: 'nodejs'});\nPyroscope.start()\n```\n\nBoth params `appName` and `serverAddress` are mandatory. Once you `init` you may `startCpuProfiling()` and/or `startHeapProfiling()`. `start()` starts both memory and CPU profiling\n\n## Pull Mode\n\nIn order to enable pull mode you need to implement follwing endpoints:\n * `/debug/pprof/profile` -- for wall-time profiling\n * `/debug/pprof/heap` -- for heap profiling\n\nYou may implement your own enpoints with Pyroscope API, like in the example:\n\n```javascript\nPyroscope.init()\n\napp.get('/debug/pprof/profile', async function handler(req, res) {\n  console.log('Collecting Cpu for', req.query.seconds);\n  try {\n    const p = await Pyroscope.collectCpu(req.query.seconds);\n    res.send(p);\n  } catch (e) {\n    console.error('Error collecting cpu', e);\n    res.sendStatus(500);\n  }\n});\n```\n\nParameter `appName` is mandatory in pull mode.\n\n## Pull Mode\n\nIn order to enable pull mode you need to implement follwing endpoints:\n * `/debug/pprof/profile` -- for wall-time profiling\n * `/debug/pprof/heap` -- for heap profiling\n\nYou may implement your own enpoints with Pyroscope API, like in the example:\n\n```javascript\napp.get('/debug/pprof/profile', async function handler(req, res) {\n  console.log('Collecting Cpu for', req.query.seconds);\n  try {\n    const p = await Pyroscope.collectCpu(req.query.seconds);\n    res.send(p);\n  } catch (e) {\n    console.error('Error collecting cpu', e);\n    res.sendStatus(500);\n  }\n});\n```\n\nor you may use express middleware. \n\n```javascript\nimport Pyroscope, { expressMiddleware } from '@pyroscope/nodejs'\n\nPyroscope.init()\nconst app = express()\napp.use(expressMiddleware());\n```\n\nthen you also need to configure your pyroscope server by providing config file \n\n```yaml\n---\nlog-level: debug\nscrape-configs:\n  - job-name: testing            # any name \n    enabled-profiles: [cpu, mem] # cpu and mem for wall and heap\n    static-configs:\n      - application: rideshare\n        spy-name: nodespy        # make pyroscope know it's node profiles\n        targets:\n          - localhost:3000       # address of your scrape target\n        labels:     \n          env: dev               # labels\n\n```\n### Debugging\n\nUse `DEBUG` env var set to `pyroscope` to enable debugging messages. Otherwise all messages will be suppressed.\n\n`DEBUG=pyroscope node index.js`\n## API\n### Configuration\n\n```\ninit(c : PyroscopeConfig)\n\n```\n\nConfiguration options\n```typescript\ninterface PyroscopeConfig {\n    serverAddress?: string;          // Server address for push mode\n    sourceMapPath?: string[];       // Sourcemaps directories (optional)\n    appName?: string;                // Application name\n    tags?: Record<string, any>;     // Tags \n    authToken?: string              // Auth token for cloud version\n}\n```\n\nBoth `serverAddress` and `appName` are mandatory for push mode.\n\n### CPU Profiling\n```javascript\n// Start collecting for 10s and push to server\nPyroscope.startCpuProfiling()\nPyroscope.stopCpuProfiling()\n\n// Or do it manually\nPyroscope.collectCpu(seconds?:number);\n```\n### Heap Profiling\n```javascript\n// Start heap profiling and upload to server\nPyroscope.startHeapProfiling()\nPyroscope.stopHeapProfiling()\n\n// Or do it manually\nPyroscope.startHeapCollecting()\nPyroscope.collectHeap();\nPyroscope.stopHeapCollecting()\n```\n\n","readmeFilename":"README.md"}