1.3.4 • Published 16 days ago

@foxsenseinnovations/vigil-sdk-js v1.3.4

Weekly downloads
-
License
ISC
Repository
-
Last release
16 days ago

Vigil - SDK

SDK for API monitoring, Job monitoring and Error monitoring.

Installation

npm

  $ npm i @foxsenseinnovations/vigil-sdk-js

yarn

  $ yarn add @foxsenseinnovations/vigil-sdk-js

Usage

# 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>});

API Monitoring

# 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

Options are not mandatory. | Options | Mandatory | Default | Values | | ------- | --------- | ------- | --------------------------------------------- | | exclude | FALSE | {} | { GET: [], POST: [], PATCH: [], DELETE: [], } |

Exclude

  • 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));

Job Monitoring

# 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({
            jobId: <job-id>,
            message: <job-start-message>
        });
        ...
        ...

        // log that the job has completed its execution with a success message.
        JobManager.captureJobEnd({
            jobId: <job-id>,
            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({
            jobId: <job-id>,
            message: <job-failure-message>
        });
    }
});

Error Monitoring

# 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

Options are not mandatory. | Options | Mandatory | Default | Value | | ------- | --------- | ------- | -----------------| | tags | FALSE | [] | Array of strings | | context | FALSE | {} | An object |

Tags and Context

  • 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);
    }
}
1.3.4

16 days ago

1.3.3

3 months ago

1.3.2

4 months ago

1.3.1

9 months ago

1.2.0

1 year ago

1.3.0

1 year ago

1.1.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago