Configuration

djaty-nodejs can be configured through djaty.init() method which receives only one argument as an options object. The only required options are apiKey and apiSecret; all others are optional.


Required Options

apiKey: string (Required)

Project key identifier. You can find and control it through Djaty dashboard.

apiSecret: string (Required)

Project secret identifier. You can find and control it through Djaty dashboard.


Optional Options

trackingOptions: object (Optional, default: {})

An object to control the behaviour of timeline items tracking. All properties are optional.

  • allowedWrappers: object (Optional, default: {})

    To control which timeline items should be tracked: Console, HTTP, ... or set it to false to track only exceptions. Default is to track console and http timeline items.

    • stdLogs: boolean (Optional, default: false)

      To track both stdout and stderr logs.

    • console: boolean (Optional, default: true)

      To track console logs.

    • http: boolean (Optional, default: true)

      To track outgoing http requests.

    • customLogger: array (Optional, default: [])

      To track other loggers like winston logs. It’s an array of objects with the following properties:

      • name: string (Required)

        The logger name (Currently supported values: ‘winston’)

  • captureUnhandledRejections: boolean (Optional, default: true)

    To capture Promises that throws an exception without being caught with .catch()

  • timelineLimit: number (Optional, default: 30, Max allowed value: 100)

    The max allowed number of timeline items keeping the first item from being removed as it presents the request entry point that tracks the route, ...

  • stacktraceLimit: number (Optional, default: 40, Max allowed value: 100)

    The max allowed number of stacktrace frames when Djaty captures an exception.

  • parseUser: boolean | Function | object (Optional, default: true)

    To control how our wrappers track the current user object. Default value is true that allow the SDK to pick the userId and the username (to be displayed at Djaty dashboard as user logon) properties from the req.user object. To change this behaviour, parseUser can be one of the following values:

    • false: Prevent tracking userId and username.
    • function: That accepts the req object as a parameter and return an object with the following structure: {userId: number | string, logon: number | string}.

Code example on the trackingOptions property

const {djaty} = require('djaty-nodejs');

// If the application is using winston
const winston = require('winston');
const loggerIns = new winston.Logger({colorize: true, expressFormat: true});

djaty.init({
  apiKey: 'YOUR_PROJECT_API_KEY_HERE',
  apiSecret: 'YOUR_PROJECT_API_SECRET_HERE',
  trackingOptions: {
    allowedWrappers: {
      stdLogs: false,
      http: true,
      customLogger: [{
        name: 'winston',
        instance: loggerIns,
      }],
    },
    captureUnhandledRejections: true,
    timelineLimit: 50,
    stacktraceLimit: 30,
    parseUser: {userId: 'uid', logon: 'name'},
  },
});

server: object

Server information that should be used in case of hosting Djaty servers locally.

  • hostname: string (Required)

    Server hostname

  • port: number (Optional, default: 443)

    Server listening port

  • secure: boolean (Optional, default: true)

    To control using the http or the https protocol.

  • ca : Buffer (Optional)

    The certification authority of the https certificate.

proxy: object

Proxy information that should be used in case of hosting Djaty servers locally. It has the same properties as the server option


release: string (Optional)

The current release version of the app or the script


tags: array (Optional)

Array of strings to be used as machine identifying tags

stage: string (Optional)

Machine identifying stage


onBeforeBugSubmission: Function (Optional)

Callback function to be executed to filter the context data right before bug submission.

Note

User can use djaty.addBeforeSubmissionHandler() and djaty.addBeforeSubmissionContextHandler() to attach onBeforeBugSubmission filter callbacks dynamically.

It accepts only two params as the following example:

const {djaty} = require('djaty-nodejs');
djaty.init({
  apiKey: 'YOUR_PROJECT_API_KEY_HERE',
  apiSecret: 'YOUR_PROJECT_API_SECRET_HERE',

  /**
   * Filter  the context data right before bug submission
   * @param {object} data: ALL the SDK collected data
   * @param next: Callback Function to be called after filtering data passing the filtered data as its param
   */
  onBeforeBugSubmission: (data, next) => {
    Promise.all(data.agentDataPatch.map(AgentPatchItem => {
      const userId = AgentPatchItem.user.userId;

      return userModel.isAdmin().then(isAdmin => {
        if (!isAdmin) {
          delete AgentPatchItem.user;
        }
      });
    })).then(() => {
      // Passing the filtered data to the next `onBeforeBugSubmission` cb
      next(data);
    });
  }
});

allowAutoSubmission: Function (Optional)

Control to allow or not the tracked uncaught exceptions to be automatically submitted.

showDjatyLogs: boolean (Optional, default: false)

Allow Djaty internal log messages to be printed to the console (For debugging).


Section for web VS non web