SDK for API monitoring, Job monitoring and Error monitoring.
$ npm i @foxsenseinnovations/vigil-sdk-js
$ yarn add @foxsenseinnovations/vigil-sdk-js
# import Vigil to initialize the API KEY.
const { Vigil } = require('@foxsenseinnovations/vigil-sdk-js');
Vigil.initialize({apiKey: <API_KEY>});
Vigil.initialize({apiKey: <API_KEY>, version: <VERSION>});
# import ApiManager to monitor the APIs in the application.
const { ApiManager } = require('@foxsenseinnovations/vigil-sdk-js');
# apply as middleware to monitor all the APIs in the application.
# Express
app.use(ApiManager.captureAPIs());
# Fastify
app.addHook('onRequest', captureAPIs());
# import ApiManager to monitor the APIs in the application.
const { ApiManager } = require('@foxsenseinnovations/vigil-sdk-js');
# add middleware to specific APIs in the application.
app.get('/',ApiManager.captureAPIs(),(req,res) => {
...
...
});
app.post('/',ApiManager.captureAPIs(),(req,res) => {
...
...
});
# This particular API will not be monitored since the middleware is not applied to this API.
app.delete('/',(req,res) => {
...
...
});
Options are not mandatory.
Options | Mandatory | Default | Values |
---|---|---|---|
exclude | FALSE | {} | { GET: [], POST: [], PATCH: [], DELETE: [], } |
- Excludes the given API path's for each method. These API are not monitored.
- You can use express way of applying/ not applying global middleware to specific routes.
# import ApiManager to monitor the APIs in the application.
const { ApiManager } = require('@foxsenseinnovations/vigil-sdk-js');
const options = {
exclude: {
GET: ['/','/health']
}
};
# '/' and '/health' APIs of GET method are not monitored.
app.use(ApiManager.captureAPIs(options));
# import JobManager to monitor the Jobs in the application.
const { JobManager } = require('@foxsenseinnovations/vigil-sdk-js');
cron.schedule('<cron-expression>',() => {
try {
// log that the job triggered with a start message.
JobManager.captureJobStart({
jobSlug: <job-slug>,
message: <job-start-message>
});
...
...
// log that the job has completed its execution with a success message.
JobManager.captureJobEnd({
jobSlug: <job-slug>,
message: <job-end-message>
});
} catch(error) {
// if the job fails at some point,
// then its failure can be logged with a failure message.
JobManager.captureJobFailure({
jobSlug: <job-slug>,
message: <job-failure-message>
});
}
});
# import ErrorManager to capture any exceptions/errors that occur in the application.
const { ErrorManager } = require('@foxsenseinnovations/vigil-sdk-js');
function() {
try {
...
...
} catch(error) {
// capture the exception from the error object.
ErrorManager.captureException(error);
}
}
Options are not mandatory.
Options | Mandatory | Default | Value |
---|---|---|---|
tags | FALSE | [] | Array of strings |
context | FALSE | {} | An object |
- Gives extra information about the exception that occurred.
# import ErrorManager to capture exceptions/errors.
const { ErrorManager } = require('@foxsenseinnovations/vigil-sdk-js');
function() {
try {
...
...
} catch(error) {
const options = {
tags: ['tag1','tag2'],
context: {
<key1>: <value1>,
<key2>: <value2>
}
};
// capture the exception from the error object
// and pass extra information about the exception in options.
ErrorManager.captureException(error, options);
}
}