HarmonyOS NEXT API Description
I. Startup Configuration Interface
Please obtain <#Config Address#> and <#AppID#> from the platform. For the method to obtain them, refer to How to Query AppID and Config Address?. Please contact technical support if you have any questions.
Startup configuration interfaces are configured via chain calls along with Bonree.withAppID("<#AppID#>").start(this.context.getApplicationContext());. They need to be configured after calling withAppID and before calling the start function. Multiple configurations can be set simultaneously. Configurations after the start function are invalid.
Set Config Address
One platform or private deployment users need to set the private deployment config address during startup.
- Interface Description
withConfigAddress(configAddress: string): Bonree
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| configAddress | Private deployment config address | String length must be greater than 0 and less than or equal to 2083, otherwise the interface call fails | Agent stops |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.withAppID("<#AppID#>")
.withConfigAddress("<#Config Address#>")
.start(this.context.getApplicationContext())
Set Custom APP Version
If a custom device App version number is set using this method, the SDK will report this version number instead of using the default obtained version number.
- Interface Description
withAppVersion(version: string): Bonree
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| version | Custom version number | String length must be greater than 0 and less than or equal to 64, otherwise the interface call fails | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.withAppID("<#AppID#>")
.withAppVersion("custom app version")
.start(this.context.getApplicationContext());
Set Custom Application Environment
Set the application environment field using this method.
withAppEnvironment(environment: string): Bonree
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| environment | Application environment string | String length must be greater than 0 and less than or equal to 256, excess truncated. Cannot contain special characters (allows spaces (not pure spaces), letters, Chinese characters, numbers, -, _, ., @, /, :, *, #, !) | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.withAppID("<#AppID#>")
.withAppEnvironment("PROD")
.start(this.context.getApplicationContext());
Use Custom Cold Launch End Time
Whether to use a custom cold launch end time.
- Interface Description
withUseCustomLaunch(used: boolean): Bonree
| Parameter | Description |
|---|---|
| used | true uses custom end, false does not |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.withAppID("<#AppID#>")
.withUseCustomLaunch(true)
.start(this.context.getApplicationContext());
Set SDK's Own Request Headers
This interface is used to set custom request headers for network requests initiated by the SDK itself.
- Interface Description
withSDKRequestHeaders(headers: Map<string, string>): Bonree
| Parameter | Description | Failure Result |
|---|---|---|
| headers | Key-value pairs of request headers to set (maximum 64, key length limit 256 characters, value length limit 512 characters) | Single data item invalid if key/value length exceeds limit |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
const headers:Map<string,string> = new Map();
headers.set("headerKey1","headerValue1");
headers.set("headerKey2","headerValue2");
headers.set("headerKey3","headerValue3");
Bonree.withAppID("<#AppID#>")
.withSDKRequestHeaders(headers)
.start(this.context.getApplicationContext());
Enable Encryption and Set Encryption Information
This interface is used to set whether to use national encryption (GM) for the SDK's own requests.
The encryption feature currently only supports the One platform. Before using this feature, please be sure to communicate with technical support or implementation to obtain the encryption Key, ensuring it is consistent with the platform configuration. Otherwise, it may cause exceptions in SDK data requests.
withEnableGMSM4Encrypt(secretKey: Uint8Array, identifier: string):Bonree
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| secretKey | Encryption key | Required, byte[] type, key length must be exactly 16 bytes | Encryption feature fails |
| identifier | Key identifier | Required, string cannot be empty or null. String length less than or equal to 256, and cannot contain special characters (only letters, numbers, underscore _, hyphen - are allowed) | Encryption feature fails |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let secretKey = new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
//assert secretKey.length == 16; Must ensure the actual character length is 16 bytes. Do not use special characters < > & ' " %
let identifier :string ="v30";
Bonree.withAppID("<#AppID#>")
.withEnableGMSM4Encrypt(secretKey,identifier)
.start(this.context.getApplicationContext());
Or
let secretKeyStr="1234567890123456"
let textEncoder = new util.TextEncoder('utf-8');
let secretKey = textEncoder.encodeInto(secretKeyStr);
//assert secretKey.length == 16; Must ensure the actual character length is 16 bytes. Do not use special characters < > & ' " %
let identifier :string ="v30";
Bonree.withAppID("<#AppID#>")
.withEnableGMSM4Encrypt(secretKey,identifier)
.start(this.context.getApplicationContext());
Set User Channel ID
Distinguish the channel through which the application is published. Channel information will be displayed in the platform's performance data.
- Interface Description
withChannelID(channelID: string): Bonree
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| channelID | Custom channel number | String length must be greater than 0 and less than or equal to 256, otherwise the interface call fails | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.withAppID("<#AppID#>")
.withChannelID("channelID")
.start(this.context.getApplicationContext());
Start Session Replay Upload
When the session replay feature is enabled, the SDK by default only uploads replay data when an issue occurs. If the client actively calls this interface, it will immediately enable the continuous upload capability for session replays.
static startSessionReplayUpload();
- Example
ItemButton({ btnName: "Browse" }).onClick(() => {
Bonree.startSessionReplayUpload();
}).width('20%')
II. Data Acquisition Interface
Get Device ID
If the withDeviceID interface was set during SDK startup, the custom ID will be returned.
- Interface Description
static getDeviceID(): string
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
const deviceID = Bonree.getDeviceID();
console.log("BRSDK: "+deviceID);
Get Current SDK Version
Get the current SDK version.
- Interface Description
static getSdkVersion(): string
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
const sdkVersion = Bonree.getSdkVersion();
console.log("BRSDK: "+sdkVersion);
III. Custom Information Setting Interface
Custom User Information
BonreeSDK supports setting user-related information to fulfill requirement scenarios where performance data needs to be associated with actual users.
There are two ways to set user information:
- Set User ID, identifying the user with a string
setUserID(userID: string);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| userID | Identify the user with a string | Can be empty or null. String length less than or equal to 256, and cannot contain special characters (only allows numbers, letters, Chinese characters, colons, spaces, slashes, underscores, hyphens, periods, asterisks, exclamation marks, @, #, empty or null strings are invalid), otherwise the interface call fails | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.setUserID("18988888888");
Set User Additional Information
- Set more detailed additional information for the user.
static setUserExtraInfo(extraInfo: Map<string, Object>);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| extraInfo | User additional information | Map can have up to 64 key-value pairs, excess will retain only 64. Key length less than 256, excess makes the key invalid, and cannot contain special characters (only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid); value less than 512, excess truncated | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
const userInfo = new Map<string, Object>();
userInfo.set("phoneNumber", "18988888888");
userInfo.set("clientID", "harmony device id");
userInfo.set("type", "vip");
Bonree.setUserExtraInfo(userInfo);
Append User Additional Information
- Append user additional information
static addUserExtraInfo(key: string, value: Object);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Key to append | Key length less than 256, excess makes the key invalid, and cannot contain special characters (only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid); | Current setting is invalid |
| value | Value corresponding to the key | Value less than 512, excess truncated | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.addUserExtraInfo("age","18");
Remove User Additional Information
- Remove user additional information
static removeUserExtraInfo(key: string);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Key to remove | Key length less than 256, excess makes the key invalid, and cannot contain special characters (only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid); | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.removeUserExtraInfo("age");
Accumulate User Numerical Information
- Accumulate user numerical information
static increaseUserExtraInfo(key: string, value: number);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Key to accumulate | Key length less than 256, excess makes the key invalid, and cannot contain special characters (only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid); | Current setting is invalid |
| value | Value corresponding to the key | value only supports Number type | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.increaseUserExtraInfo("number",1);
Add Event Common Attributes
- Add event common attributes
static addEventAttributes(attributes: Map<string, Object>, isSaveLocal: boolean);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| attributes | Information to add, same key will overwrite previous settings | Map can have up to 64 key-value pairs, excess will retain only 64; key length less than 256, excess makes the key invalid, and cannot contain special characters (only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid); | Current setting is invalid |
| isSaveLocal | Whether to persist locally, true: common attributes will be persisted locally and will be included the next time the application is opened. false: only effective during this usage period | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
const attributes = new Map<string, Object>();
attributes.set("onclick", "1");
attributes.set("page", "1");
attributes.set("type", "vip");
Bonree.addEventAttributes(attributes, true);
Add Single Event Common Attribute
- Add a single event common attribute
static addEventAttribute(key: string, value: Object, isSaveLocal: boolean);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Key of the information to add | Key length less than or equal to 256, excess makes the key invalid, and cannot contain special characters (only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid); | Current setting is invalid |
| value | Value of the information to add | Value length less than or equal to 512, excess truncated | Current setting is invalid |
| isSaveLocal | Whether to persist locally, true: common attributes will be persisted locally and will be included the next time the application is opened. false: only effective during this usage period | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.addEventAttribute("onclick",1,true);
Remove Event Common Attributes
- Remove event common attributes
static removeEventAttribute(keys: string[])
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| keys | Array of keys to delete | Key length less than or equal to 256, excess makes the key invalid, and cannot contain special characters (only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid); | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
const removeKeys=["name","age"];
Bonree.removeEventAttribute(removeKeys);
Remove All Event Common Attributes
- Remove all event common attributes
static removeAllEventAttributes();
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.removeAllEventAttributes();
Custom Exception
Call the interface and pass the corresponding parameters to complete the statistical function for custom exception data.
static setCustomException(error: Error); // Recommended, directly pass the Exception or Throwable object
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| throwable | Exception object | System-thrown exception object, non-null | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
try {
throw new Error("Test");
} catch (err) {
Bonree.setCustomException(err);
}
// This overload is more flexible and can be used for business-type exception reporting. The relevant parameters can be filled with any content that meets the parameter constraints and will be directly displayed on the platform.
static setCustomException(errorType: string, causeBy?: string, errorDump?: string);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| exceptionType | Exception type (Required) | String length must be greater than 0 and less than or equal to 256, otherwise the interface call fails. | Current setting is invalid |
| causeBy | Exception cause | Can be empty or null. String length less than or equal to 512, excess truncated. | - |
| errorDump | Exception information | Will be truncated if exceeding 10000 characters | Can be empty or null. String length less than or equal to 10000, excess truncated. |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
try {
throw new Error("Test");
} catch (err) {
if (err instanceof Error) {
Bonree.setCustomException(err.name, err.message, err.stack);
}
}
Custom View
Call the interface and pass the corresponding parameters to complete the statistical function for custom view data.
// Custom View - Page start, must be called in pair with page end. Generally called at: onPageShow. The name view name is a required field. If empty, the call fails.
static setCustomPageStart(pageName: string, param?: string);
// Custom View - Page end, must be called in pair with page start. Generally called at: onPageHide
static setCustomPageEnd(pageName: string, param?: string);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| pageName | View name (Required) | String length must be greater than 0 and less than or equal to 256, otherwise the interface call fails. | Current setting is invalid |
| param | Additional information, can be set as view alias | Can be empty or null. String length less than or equal to 256, excess truncated. | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
onPageShow() {
Bonree.setCustomPageStart("Index", "Home Page");
}
onPageHide() {
Bonree.setCustomPageEnd("Index", "Home Page");
}
Custom Event (Full Version)
Call the start and end interfaces respectively and pass the corresponding parameters to complete the statistical function for custom event data and event duration.
static setCustomEventStart(eventID: string, name?: string, label?: string, param?: string, info?: Map<string, string>)
static setCustomEventEnd(eventID: string, name?: string, label?: string, param?: string, info?: Map<string, string>);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| eventID | Event ID (Required) | String length must be greater than 0 and less than or equal to 256, otherwise the interface call fails. | Current setting is invalid |
| name | Event name | Can be empty or null. String length less than or equal to 256, excess truncated. | - |
| label | Event label | Can be empty or null. String length less than or equal to 256, excess truncated. | - |
| param | Event additional information | Can be empty or null. String length less than or equal to 7000, excess truncated. | - |
| info | Event business information | Can be empty, length after converting to JSON must be within 7000 characters, otherwise the interface call fails. | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.setCustomEventStart("vip-login","Verification code sent","Login");
Bonree.setCustomEventEnd("vip-login","Verification code sent","Login");
// Call with info field
const info = new Map<string, string>();
info.set("eventNumber", "10001");
info.set("eventName", "bonree");
info.set("eventXX", "xx");
Bonree.setCustomEventStart("vip-login", "Verification code sent", "Login", undefined, info);
Bonree.setCustomEventEnd("vip-login", "Verification code sent", "Login", undefined, info);
Custom Event (Simplified Version)
Call the interface and pass the corresponding parameters to complete the statistical function for custom event data.
static setCustomEvent(eventID: string, name?: string, label?: string, param?: string, info?: Map<string, string>);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| eventID | Event ID (Required) | String length must be greater than 0 and less than or equal to 256, otherwise the interface call fails. | Current setting is invalid |
| name | Event name | Can be empty or null. String length less than or equal to 256, excess truncated. | - |
| label | Event label | Can be empty or null. String length less than or equal to 256, excess truncated. | - |
| param | Event additional information | Can be empty or null. String length less than or equal to 7000, excess truncated. | - |
| info | Event business information | Can be empty, length after converting to JSON must be within 7000 characters, otherwise the interface call fails. | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.setCustomEvent("001","Register");
const info = new Map<string, string>();
info.set("eventNumber", "10001");
info.set("eventName", "bonree");
info.set("eventXX", "xx");
Bonree.setCustomEvent("vip-login", "Login failed", undefined, undefined, info);
Custom Log
Call the interface and pass the corresponding parameters to complete the statistical function for custom log data.
static setCustomLog(logInfo: string);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| logInfo | Log information (Required) | String length must be greater than 0, otherwise the interface call fails. String length less than or equal to 10000, excess truncated. | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.setCustomLog("login successful...");
Custom Metric
Call the interface and pass the corresponding parameters to complete the statistical function for custom metric data.
static setCustomMetric(name: string, value: number)
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| name | Metric name (Required) | String length must be greater than 0 and less than or equal to 256, otherwise the interface call fails. | Current setting is invalid |
| value | Metric value (Required) | Long.MAX_VALUE | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.setCustomMetric("Custom Metric",systemDateTime.getTime(false));
Custom Method
Call the interface and pass the corresponding parameters to complete the statistical function for custom metric data. Custom method embedding is mostly used for manual embedding of business methods or asynchronous methods not automatically collected by the SDK.
static setCustomMethodStart(name: string);
static setCustomMethodEnd(name: string);
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| name | Method name (Required) | String length must be greater than 0 and less than or equal to 256, otherwise the interface call fails. | Current setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
onNetworkLoad(){
Bonree.setCustomMethodStart("onNetworkLoad");
//do something
Bonree.setCustomMethodEnd("onNetworkLoad");
}
Custom Network
Call the interface and pass the corresponding parameters to complete the statistical function for custom metric data. Custom method embedding is mostly used for manual embedding of business methods or asynchronous methods not automatically collected by the SDK.
static setCustomNetwork(networkCustomEvent: NetworkCustomEvent.NetworkCustomEventBean)
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| networkCustomEvent | Entity structure (Required) | Metric structure object. Required parameter. | Current setting is invalid |
@param requestUrl:string // Request URL
@param method:HttpMethod // Request method
@param targetIp:string | undefined // Target IP
@param targetPort:number // Target port
@param dnsTimeUs:number // DNS query time
@param connectTimeUs:number // TCP connection establishment time
@param sslTimeUs:number // SSL time
@param requestTimeUs:number // Request time
@param responseTimeUs:number // Response time
@param downloadTimeUs:number // Download time
@param downloadSizeByte:number // Response data size
@param protocolType:ProtocolType // Protocol type
@param cnameArray:Array<string> | undefined // Collection of cnames
@param errorCode:number | undefined // Error code
@param errorMessage:string | undefined // Error description information
@param errorOccurrentProcess:ErrorOccurrentProcess | undefined // Process stage where the error occurred
@param requestDataSize:number | undefined // Request size field
@param resourceType:string | undefined // Resource type
@param requestHeader:Map<string, string> | undefined // Request header
@param responseHeader:Map<string, string> | undefined; // Response header
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.setCustomNetwork(
new NetworkCustomEvent.NetworkCustomEventBean("https://www.bonree.com",
NetworkCustomEvent.HttpMethod.GET,
"127.0.0.1",
443, 20000,
10000,
50000,
20000,
500000,
10000,
55,
NetworkCustomEvent.ProtocolType.HTTPS));
Custom Cold Launch End
After configuring the withUseCustomLaunch interface in the startup configuration, calling this custom interface can set the current moment as the end point of the custom cold launch event.
static recordCustomLaunchEnd();
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
Bonree.recordCustomLaunchEnd();
IV. Protocol Extension Interface
This chapter introduces the usage and description of interfaces related to protocol extension.
Create Protocol Extension Instance
Call the creation interface to return an instance object implementing the Span protocol. Returns undefined on failure.
static startSpan(name: string, type: string): Span | undefined;
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| name | Name of the protocol extension (Required) | String length must be greater than 0 and less than or equal to 256, excess truncated. Only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid | Interface call invalid, returns undefined |
| type | Type of the protocol extension (Required) | String length must be greater than 0 and less than or equal to 256, excess truncated. Only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid | Interface call invalid, returns undefined |
| Return Type | Description |
|---|---|
Span | Protocol extension instance object |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
// Create Span
let span:Span = Bonree.startSpan("name","type");
Note: The creation interface, i.e.,
startSpan, must be called in pair with the completion interface, i.e.,finish(spanStatus?:SpanStatus).
Protocol Extension Completion
Complete the protocol extension data. Calling other instance methods after completion is invalid.
finish(spanStatus?:SpanStatus);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| spanStatus | Protocol extension status (Optional) | Values SPAN_STATUS_UNKNOWN, SPAN_STATUS_OK, SPAN_STATUS_ERROR | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
//...
// Complete the Span
span.finish();
//or
span.finish(SpanStatus.SPAN_STATUS_OK);
Create Child Protocol Extension Instance
Create a child protocol extension object on a protocol extension object, returning an instance implementing the Span protocol.
startChild(name:string,type:string):Span | undefined;
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| name | Name of the protocol extension (Required) | String length must be greater than 0 and less than or equal to 256, excess truncated. Only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid | Interface call invalid, returns undefined |
| type | Type of the protocol extension (Required) | String length must be greater than 0 and less than or equal to 256, excess truncated. Only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @, empty or null strings are invalid (should be consistent with the parent span type, otherwise the parent span type is used) | Interface call invalid, returns undefined |
| Return Type | Description |
|---|---|
Span | Protocol extension instance object |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
let childSpan:Span = span.startChild("childName","chindType");
Note: When finishing a parent protocol extension object, all its child protocol extension objects will be automatically finished (if their status hasn't been set, it defaults to SPAN_STATUS_OK)
Currently, only single-level protocol extension is supported, meaning top-level Spans can create child Spans, but child Spans cannot create further child Spans.
When the Span type is one of the two reserved types, socket or websocket, creating child Spans under it is temporarily not supported.
Set Data
Set the Data within the protocol extension.
setData(key:string,value:string);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Key corresponding to the Data (Required) | String length must be greater than 0 and less than or equal to 200, case-insensitive, allows letters, underscores, hyphens, periods, and must start and end with a letter | Interface call invalid |
| value | Data value (Required) | String length must be greater than 0 and less than or equal to 7000, excess truncated | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
//...
// Add Data
span.setData("key","value");
Remove Data
Remove the Data within the protocol extension.
removeData(key:string);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Remove the corresponding Data based on the key value (Required) | - | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
span.setData("key","value");
//...
// Delete Data
span.removeData("key");
Set Tag Data
Set the Tag within the protocol extension.
setTag(key:string,value:string);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Key corresponding to the Tag (Required) | String length must be greater than 0 and less than or equal to 200, case-insensitive. Allows letters, underscores, hyphens, periods, and must start and end with a letter | Interface call invalid |
| value | Tag value (Required) | String length must be greater than 0 and less than or equal to 7000, excess truncated | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span =Bonree.startSpan("name","type");
//...
// Add Tag data
span.setTag("key","value");
Remove Tag Data
Remove the Tag within the protocol extension.
removeTag(key:string);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Remove the corresponding Tag based on the key value (Required) | - | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
span.setTag("key","value");
//...
// Delete Tag data
span.removeTag("key");
Set Metric Data
Set the Metric within the protocol extension.
setMetric(key: string, value: number, unit?: SpanMetricUnit | string);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Key corresponding to the Metric (Required) | String length must be greater than 0 and less than or equal to 200, case-insensitive. Allows letters, underscores, hyphens, periods, and must start and end with a letter | Interface call invalid |
| value | Metric value (Required) | - | - |
| unit | Unit name for the Metric (Optional) | String length must be greater than 0 and less than or equal to 256. Only allows numbers, letters, colons, spaces, slashes, underscores, hyphens, periods, @. Can use preset enumeration units (SpanMetricUnit) | Only the unit setting is invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
//...
// Add Metric data
span.setMetric("key",1000,"tcp");
//or
span.setMetric("key",1000,SpanMetricUnit.Byte);
Note: The SDK has built-in units. The built-in unit types are in the SpanMetricUnit enumeration class. Custom string units are supported.
Remove Metric Data
Remove the Metric within the protocol extension.
removeMetric(key:string);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| key | Remove the corresponding Metric based on the key value (Required) | - | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
span.setMetric("key",1000,"ms");
//...
// Delete Metric data
span.removeMetric("key");
Set Status
Set the status of the protocol extension.
setStatus(status:SpanStatus);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| status | Protocol extension instance status, values SPAN_STATUS_UNKNOWN, SPAN_STATUS_OK, SPAN_STATUS_ERROR (Required) | - | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
//...
// Set Status
span.setStatus(SpanStatus.SPAN_STATUS_OK);
Set StatusCode
Set the status code of the protocol extension.
setStatusCode(code:string);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| code | Status code value (Required) | String length must be greater than 0 and less than or equal to 7000, excess makes interface call invalid | Interface call invalid |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
//...
// Set Status code
span.setStatusCode("200");
Set Duration
Actively set the span duration. If this method is not actively called, the span duration is the time from start to finish.
setDuration(duration:number);
- Interface Description
| Parameter | Description | Parameter Constraints | Failure Result |
|---|---|---|---|
| duration | Protocol extension duration, unit: microseconds (us) (Required) | - | - |
- Meta Service API
This interface is supported in the Meta Service SDK.
- Example
let span:Span = Bonree.startSpan("name","type");
//...
// Set duration
span.setDuration(100);