API Reference

init

Signature: init(options: UserConfigOptions): Djaty

Initiating Djaty tracking. It accepts an options config (Check Configuration section)

destroy

Signature: destroy(): Djaty

Destroying Djaty tracking by destroying existed states and Event listeners. It accepts an options config (Check Configuration section)

requestHandler

Signature: requestHandler(): (req: Express.Request, res: Express.Response, next: Express.Next) => void

A method that returns Express Request middleware (Check Installation section)

errorHandler

Signature: errorHandler(): (err: utils.RequestError, req: Express.Request, res: Express.Response, next: Express.Next) => void

A method that returns Express Error middleware (Check Installation section)

setUser

Signature: setUser(user: { userId?: string; logon?: string; }): void;

Dynamically set the user that will be sent with the context. Noting that at least logon or userId should be passed.

addBeforeSubmissionContextHandler

Signature: addBeforeSubmissionContextHandler(cb: (data: AgentData, next: (data: AgentData) => void) => void): void;

Dynamically attach a contextual onBeforeBugSubmission filter callbacks. If Djaty is installed inside a web server and catches the bug(s), this filter will be applied to the current submission(s) within the current request only. This filter will not be applied to other requests that have not configured with this filter. Note: If this method is used in a context other than a web server, it’ll acts similarly to addBeforeSubmissionHandler() method.

addBeforeSubmissionHandler

Signature: addBeforeSubmissionHandler(cb: (data: AgentData, next: (data: AgentData) => void) => void): void;

Dynamically attach a global onBeforeBugSubmission filter callbacks that will always be applied to every bug submission regardless of the current context is a server request or anything else.

Note

Inside filter methods addBeforeSubmissionContextHandler and addBeforeSubmissionHandler, console logs are not tracked and calling djaty contexual methods like djaty.addBeforeSubmissionContextHandler() and djaty.setUser() will not be useful and will be ignored.

addContextCustomData

Signature: addContextCustomData(data: any): void;

Dynamically add contextual custom data that will be sent with every bug submission inside the current request if Djaty is installed inside a web server. Note: If this method is used in a context other than a web server, it’ll acts similarly to addGlobalCustomData() method.

addGlobalCustomData

Signature: addGlobalCustomData(data: any): void;

Dynamically add global custom data that will be sent with every bug submission regardless of the current context is a server request or anything else.

trackBug

Signature: trackBug(bug: Error | string): Promise;

Manually submit a bug.

The bug submissions payload (AgentData)

Note

This structure should be taken into consideration especially when dealing with methods like onBeforeBugSubmission, addBeforeSubmissionContextHandler and addBeforeSubmissionHandler to filter payload data.

import {AgentPatchItem} from '.';

interface AgentData {
  agentDataPatch: AgentPatchItem[];
  agentId: string;
  agentVersion: string;
  apiKey: string;
  apiSecret: string;
  hashType: 'sha256';
  platform: string;
  platformVersion?: string;

  // Only include release information if it is set
  release?: string;

  serverLocalIp: string;
  serverName: string;
  stage?: string;
  tags?: string[];
}
import {ConsoleTimelineItem, ExceptionTimelineItem, HttpTimelineItem,
 TrimmingTimelineItem} from '.';

interface AgentPatchItem {
  bugType: string;
  customData?: any[];
  djatyReqId?: string;
  hash: string;
  isTemp: boolean;
  longTitle: string;
  shortTitle: string;
  timeline: (ConsoleTimelineItem | ExceptionTimelineItem |
    HttpTimelineItem | TrimmingTimelineItem)[];
  user?: {
    userIp: string;
    userId?: string;
    logon?: string;
  };
}
interface ConsoleTimelineItem {
  itemType: 'console';
  timestamp: number;
  method: string;
  consoleParams: any[];
  hash?: string;
}
interface ExceptionTimelineItem {
  itemType: 'exception';
  timestamp: number;
  stringifiedStack: string;
  type: string;
  msg: string;
  hash: string;
}
interface HttpTimelineItem {
  itemType: 'httpReq';
  timestamp: number;
  method: string;
  queryParams?: {
    [k: string]: any;
  }[];
  url: string;
  status?: number;
  statusText?: string;
  requestTime?: number;
  djatyReqId?: string;
  remoteAddr?: string;
}
interface TrimmingTimelineItem {
  timestamp: number;
  itemType: 'trimming';
}