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

apiKey: string

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

apiSecret: string

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


Optional

trackingOptions: object

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

  • allowedWrappers: object

    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 (default: false)

      To track both stdout and stderr logs.

    • console: boolean (default: true)

      To track console logs.

    • http: boolean (default: true)

      To track outgoing http requests.

    • customLoggers: array (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: ‘AllowedCustomLoggers.winston’)

  • captureUnhandledRejections: boolean (default: true)

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

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

    The max allowed number for timeline items per bug keeping the first item from being removed is it presents the user HTTP request.

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

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

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

    To allow attaching the current user object to the bug context. Default value is true that allows the SDK to pick the userId and the username (Displayed 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}.

So, the default trackingOptions are:

trackingOptions = { 
  allowedWrappers: {
    stdLogs: false,
    console: true,
    http: true,
    customLogger: [],
  },
  captureUnhandledRejections: true,
  timelineLimit: 30,
  stacktraceLimit: 40,
  parseUser: true,
}

Code example on the trackingOptions property

const {djaty, AllowedCustomLoggers} = require('@djaty/djaty-nodejs');

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

proxy: object

The information about the proxy server.

  • hostname: string (Required)

    Server hostname

  • port: number

    Server listening port

  • secure: boolean

    To control using the http or the https protocol.

    • If secure is true and no port is specified, the default port value is 443
    • If secure is false and no port is specified, the default port value is 80
  • ca: Buffer

    The certification authority of the https certificate.

server: object

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

  • hostname: string (Required) (default: djaty.com)

    Server hostname

  • port: number

    Server listening port

  • secure: boolean (default: true)

    To control using the http or the https protocols.

    • If secure is true and no port is specified, the default port value is 443
    • If secure is false and no port is specified, the default port value is 80
  • ca: Buffer

    The certification authority of the https certificate.

  • apiPath: string (Required) (default: /api)

    The base api path of Djaty server.


release: string

The current release version of the app or the script


tags: array

Array of strings to be used as machine identifying tags

stage: string

It’s the machine identifying stage. Allowed values are Djaty.DefaultStages (DEV,PROD,STAG,TEST). I.e, Djaty.DefaultStages.PROD.


onBeforeBugSubmission: Function

A Callback function to filter the context data right before bug submission. It should not alter the Djaty core structure to avoid server validation errors.

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/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: Boolean (default: true)

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

djatyIsTracking: Boolean (default: true)

If process.env.DJATY_IS_TRACKING Or options.djatyIsTracking is false. Bug tracking should be disabled.

reportDjatyCrashes: boolean (default: true)

Flag to allow/disallow automatic djaty crashes reporting. Read more

showDjatyLogs: boolean (default: false)

Show Djaty internal log messages (For debugging purposes).

exitOnUncaughtExceptions: boolean (default: true)

Force the process to exit when the SDK tracks an uncaught exception. Noting that It’s highly recommended to exit - then restart - the process on uncaught exceptions.

Configuration as environment variables

The user can pass the following NodeJS SDK configurations as environment variables: (DJATY_API_KEY, DJATY_API_SECRET, DJATY_RELEASE).