SDK API

更新时间:
复制 MD 格式

This topic describes the configuration items and provides important notes for each plugin of the Application Performance Management (APM) software development kit (SDK).

SDK initialization

The following table describes the SDK initialization configuration items.

Field

Type

Default value

Required

Description

appKey

string

None

Yes

The appKey assigned after you create an application in the EMAS console.

appSecret

string

None

Yes

The appSecret assigned after you create an application in the EMAS console.

appVersion

string

None

No

The version number of the current application. This parameter is optional.

channel

string

None

No

The channel number of the current application.

userNick

string

None

No

The user's nickname.

userId

string

None

No

The user ID.

loggerLevel

string

None

No

The log level. Set to 'debug' for the debug level. If you do not specify this parameter, the online mode is used by default.

Example

// Initialize the SDK
var apm = new window.EMAS.APM({
  appKey: 'appKey', // The appKey assigned after you create an application in the EMAS console.
  appSecret: 'appSecret', // The appSecret assigned after you create an application in the EMAS console.
  appVersion: 'appVersion', // The application version number.
  channel: 'channel', // The application channel number.
  userNick: 'userNick', // The user's nickname.
  userId: 'userId', // The user ID.
});

Plugin configuration

The following table describes the plugin configuration items.

Plugin name

Field

Type

Default value

Required

Description

pv

autoPV

boolean

true

No

Specifies whether to automatically send page view (PV) data. If you enable this feature, data is reported once when the SDK starts.

enableHistory

boolean

false

No

For single-page applications (SPAs) that use History Router. If you enable this feature, PV data is automatically reported when the page switches. This feature must be used with `autoPv` enabled.

enableHash

boolean

false

No

For SPAs that use Hash Router. If you enable this feature, PV data is automatically reported when the page switches. This feature must be used with `autoPv` enabled.

jsError

disable

boolean

false

No

The switch for the jsError plugin.

disableError

boolean

false

No

Specifies whether to disable error detection for `error` type events.

disableUnhandledRejection

boolean

false

No

Specifies whether to disable error detection for `unhandledRejection` type events.

ignoreList

(string|RegExp|function)[]

[]

No

Matches against `error.message`. JavaScript errors that match are ignored.

request

disable

boolean

false

No

The switch for the request plugin.

disableFetch

boolean

false

No

Specifies whether to ignore errors of the `Fetch` type.

disableXHR

boolean

false

No

Specifies whether to ignore requests of the `XHR` type.

ignoreList

(string|RegExp|function)[]

[]

No

Matches against `requestUri`. Requests that match are ignored.

resource

disable

boolean

false

No

The switch for the resource plugin.

ignoreList

(string|RegExp|function)[]

[]

No

Matches against `requestUri`. Requests that match are ignored.

whiteScreen

disable

boolean

false

No

The switch for the white screen plugin.

when

string[]

["timeout", "visibilitychange", "error", "unhandledrejection", "load"]

No

The timing for white screen detection. By default, all supported timings are included.

rootSelector

string

null

No

A custom root node for white screen detection. Supports CSS selector format.

  • #id - ID selector

  • .className - class selector

ignoreSelectors

string[]

[]

No

A list of elements to ignore. Matched elements and their child elements are not included in the white screen calculation.

  • #id - ID selector

  • .className - class selector

  • [attribute] - attribute selector

timeout

number

3000

No

When `when` includes `timeout`, this parameter specifies the countdown time in milliseconds to trigger the detection.

performance

disable

boolean

false

No

The switch for the performance plugin.

disableCLS

boolean

false

No

Specifies whether to enable Cumulative Layout Shift (CLS) metric detection.

disableLCP

boolean

false

No

Specifies whether to enable Largest Contentful Paint (LCP) metric detection.

disableINP

boolean

false

No

Specifies whether to enable Interaction to Next Paint (INP) metric detection.

disableFCP

boolean

false

No

Specifies whether to enable First Contentful Paint (FCP) metric detection.

disableFP

boolean

false

No

Specifies whether to enable First Paint (FP) metric detection.

disableTTFB

boolean

false

No

Specifies whether to enable Time to First Byte (TTFB) metric detection.

disableNavigationTiming

boolean

false

No

Specifies whether to enable Navigation Timing metric detection.

Start the SDK

/**
* Starts the SDK.
* @method start
* @param {{ [key: string]: Record<string, any> }} config The plugin configuration items.
* @returns {object} Returns the instance object of each plugin, which is used to call the API of the plugin instance.
*/
start(config?: { [key: string]: Record<string, any> } ) : object

Example

const apm = new window.EMAS.APM({
  appKey: 'appKey', // The appKey assigned after you create an application in the EMAS console.
  appSecret: 'appSecret', // The appSecret assigned after you create an application in the EMAS console.
});
const plugins = apm.start({
  pv: {
    autoPv: true,
    enableHistory: true,
  },
  request: {
    disableXHR: true,
    ignoreList: ['https://xxx.xx.xx'],
  },
});

// Get the plugin instance.
const pv_plugin = plugins.pv;

Manually report PV data

If automatic PV reporting does not meet your needs, you can use the manual reporting mode.

/**
*  Manually sends PV instrumentation data.
*/
sendPV(): void;

Example

const apm = new window.EMAS.APM({
  appKey: 'appKey', // The appKey assigned after you create an application in the EMAS console.
  appSecret: 'appSecret', // The appSecret assigned after you create an application in the EMAS console.
});
const plugins = apm.start({
  pv: {
    autoPv: false,
  },
});

// Manually report PV data.
plugins.pv.sendPV();

White screen

White screen score:

A score is calculated based on common industry definitions to determine whether a white screen has occurred. The system traverses the nodes on the page's Document Object Model (DOM). The score for each visible element is determined by its depth, according to the relationship expressed in the following formula: . The sum of the scores for all visible elements is the page's total white screen score.

A lower white screen score indicates a higher probability of a white screen. By default, if the DOM score is less than 1.5, a white screen is considered highly likely, and a report is sent.