HyperTest's npm packages are hosted on a github private NPM registry
To Install and use HyperTest's node-sdk package in your application, we will do the following steps:
Create NPM_TOKEN - The Hypertest Team share this with you.
set NPM_TOKEN in .npmrc file
Install HyperTest's node-sdk package
Add the following content in your .npmrc
1st line in this file has authToken for pulling packages from NPM registry.
2nd line indicates to use https://npm.pkg.github.com registry to pull packages scoped with @hypertestco
2.1 Adding SDK in code and Initialize open telemetry sdk with hypertest
Initalize hypertest node sdk.
This needs to happen as early in your app as possible. Make sure no require/import call is made before these lines
// import * as htSdk from '@hypertestco/node-sdk'; // for esm/tsconsthtSdk=require('@hypertestco/node-sdk'); // for commonJShtSdk.initialize({ apiKey:'<your-api-key>', serviceId:'<your-service-identifier-from-dashboard>', serviceName:'<organizationName:service-name>', exporterUrl:'<hypertest-logger-url>',// ignoredHostsForHttpReqs: ['abc.xyz.com', /^\d+\.abcd\.co(m|)$/],// disableInstrumentations: [] // htSdk.HtInstrumentations enum is defined below. });
Call the markAppAsReady method when the app is ready to receive traffic, it indicates that tests can be started (This is important ONLY FOR REPLAY mode).
// Rest Application code...// add htSdk.markAppAsReady(); when your app is ready to accept requestsapp.listen(3000, () => {console.log(`Listening for requests on http://localhost:3000`);// Indicates the App has booted up successfully for REPLAY And Tests can be startedhtSdk.markAppAsReady();});
To enable hypertest, set the HT_MODE env variable to RECORD and start your app
// Set this on top inside your JS appprocess.env.HT_MODE=process.env.HT_MODE||'RECORD';
2.3 Set env if opentelemetry is already being used.
// Set this on top inside your JS app
process.env.APPLY_HT_OTEL_PATCH = 'yes'; // Set this env only if opentelemetry is already being used in your application.
3. Verifying traffic is captured
Start sending http requests on your app running with hypertest sdk.
You should start seeing requests under All requests section on the dashboard