Overview
This article is meant to provide guidance to users who are implementing the Node.js tracing agent and would like granular control over whether or not the agent is included during application startup.
Requirements
- Node.js application
- Node.js agent installed
- package.json
How to
1. Open up the package.json, and find the "scripts" section - similar to the following:
"scripts": {
"build:frontend": "cd frontend && node ./node_modules/@angular/cli/bin/ng build --aot --configuration production --output-hashing=none --vendor-chunk=true --source-map=false",
"build:server": "tsc",
"e2e": "ts-node test/e2eTests.ts",
"start": "node build/app",
"test": "cd frontend && ng test --watch=false --source-map=true && cd .. && npm run test:server",
},
2. Add a script to control Node.js instrumentation - like so:
"scripts": {
"build:frontend": "cd frontend && node ./node_modules/@angular/cli/bin/ng build --aot --configuration production --output-hashing=none --vendor-chunk=true --source-map=false",
"build:server": "tsc",
"e2e": "ts-node test/e2eTests.ts",
"start": "node build/app",
"start-with-traceable": "TA_CONFIG_FILE=./config.yaml node -r @traceable/nodejsagent build/app",
"test": "cd frontend && ng test --watch=false --source-map=true && cd .. && npm run test:server",
},
with this you can use the "start" and "start-with-traceable" commands to control whether or not to start the app with instrumentation, for example:
- npm start
- npm run start-with-traceable