Protocol Extension
This document introduces the use and description of the TingYun SDK based on custom execution unit-related interfaces.
Create Execution Unit
Note:startSpan() must be called in pairs with finish().
- Related Interface
/*
* @param name The name, cannot be empty, limited to 1024 characters, exceeding will take the first 1024 characters
* @param operation The data type, cannot be empty, limited to 128 characters, exceeding will take the first 128 characters
*/
NBSAppAgent.startSpan(String name, String operation);
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.finish();
Complete Execution Unit
Note: startSpan() must be called in pairs with finish().
- Related Interface
/*
* @param status The execution status, default is SpanStatus.SPAN_STATUS_OK, optional SpanStatus.SPAN_STATUS_OK, SpanStatus.SPAN_STATUS_ERROR, SpanStatus.SPAN_STATUS_UNKNOWN
*/
ISpan.finish()
ISpan.finish(SpanStatus status)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.finish(SpanStatus.SPAN_STATUS_OK);
Create Sub Execution Unit
Note: startChild() must be called in pairs with finish().
- Related Interface
/*
* @param name The name, cannot be empty, limited to 1024 characters, exceeding will take the first 1024 characters
* @param operation The data type, cannot be empty, limited to 128 characters, exceeding will take the first 128 characters
* @param description The description, limited to 1024 characters, exceeding will take the first 1024 characters
*/
ISpan.startChild(String name, String operation)
ISpan.startChild(String name, String operation, String description)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
ISpan span_regist = span_login.startChild("regist", "event");
span_regist.finish(SpanStatus.SPAN_STATUS_OK);
span_login.finish(SpanStatus.SPAN_STATUS_OK);
Set Data
- Related Interface
/*
* @param key The key of the Data
* @param value The value of the Data
*/
ISpan.setData(String key, Object value)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.setData("name", "Zhang San");
span_login.finish();
Set Tag Data
- Related Interface
/*
* @param key The key of the Tag
* @param value The value of the Tag
*/
ISpan.setTag(String key, String value)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.setTag("tag", "login");
span_login.finish();
Set Metric Data
- Related Interface
/*
* @param key The key of the Metric
* @param value The value of the Metric
* @param unit The unit of the Metric, optional Bit, Byte, Kilobytes, Megabytes, Millisecond, Second, Hour, Day, Bitps, Byteps, KBps, MBps, support custom
*/
ISpan.setMetric(String key, long value)
ISpan.setMetric(String key, long value, String unit)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.setMetric("time", 50, NBSSpanMetricUnit.Millisecond);
span_login.setMetric("size", 100, "Byteps");
span_login.finish();
Remove Data
- Related Interface
/*
* @param key The key of the Data
*/
ISpan.removeData(String key)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.setData("name", "Zhang San");
span_login.removeData("name");
span_login.finish();
Remove Tag Data
- Related Interface
/*
* @param key The key of the Tag
*/
ISpan.removeTag(String key)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.setTag("tag", "login");
span_login.removeTag("tag");
span_login.finish();
Remove Metric Data
- Related Interface
/*
* @param key The key of the Metric
*/
ISpan.removeMetric(String key)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.setMetric("time", 100);
span_login.removeMetric("time");
span_login.finish();
Set Status
- Related Interface
/*
* @param status The execution status, default is SpanStatus.SPAN_STATUS_OK, optional SpanStatus.SPAN_STATUS_OK, SpanStatus.SPAN_STATUS_ERROR, SpanStatus.SPAN_STATUS_UNKNOWN
*/
ISpan.Status(SpanStatus status)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.setStatus(SpanStatus.SPAN_STATUS_OK);
span_login.finish();
Set Duration
- Related Interface
/*
* @param time The duration of the execution unit, in milliseconds
*/
ISpan.setDuration(long time)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.setDuration(100)
span_login.finish();
Set StatusCode
- Related Interface
/*
* @param code The status code, default is "0"
*/
ISpan.setStatusCode(String code)
- Code Example
ISpan span_login = NBSAppAgent.startSpan("login", "event");
span_login.setStatusCode("200");
span_login.finish();