Skip to main content

Protocol Extension

This document introduces the usage and explanation of SDK interfaces related to custom execution units.

Create Execution Unit (Span)

Note

startSpanWithName:operation: must be paired with finish or finishWithStatus:.

  • API
+ (id<NBSSpan>)startSpanWithName:(NSString *)name operation:(NSString *)operation;
  • Parameters
ParameterTypeDescription
nameNSStringSpan name, cannot be empty, max length 1024 characters, truncated if exceeded
operationNSStringOperation name the span belongs to, e.g., websocket, cannot be empty, max length 128 characters, truncated if exceeded
  • Example
id<NBSSpan> span = [NBSAppAgent startSpanWithName:@"span_name" operation:@"span_operation"];
[span finish];

Finish Execution Unit (Span)

Note

startSpanWithName:operation: must be paired with finish or finishWithStatus:.

  • API
- (void)finish;

- (void)finishWithStatus:(NBSSpanStatus)status;
  • Description

Finishing an execution unit provides two methods: finish and finishWithStatus:. Calling finish sets the status to NBSSpanStatusSuccess by default, while finishWithStatus: allows you to set the status. Use the appropriate method as needed.

  • Parameters
ParameterTypeDescription
statusNBSSpanStatusStatus value: NBSSpanStatusUndefined, NBSSpanStatusSuccess, NBSSpanStatusFailed
  • Example
id<NBSSpan> span = [NBSAppAgent startSpanWithName:@"span_name" operation:@"span_operation"];
[span finishWithStatus:NBSSpanStatusSuccess];

Create Child Execution Unit (Span)

Note

startChildWithName:operation: must be paired with finish or finishWithStatus:.

  • API
- (id<NBSSpan>)startChildWithName:(NSString *)name operation:(NSString *)operation;

- (id<NBSSpan>)startChildWithName:(NSString *)name operation:(NSString *)operation description:(nullable NSString *)description;
  • Parameters
ParameterTypeDescription
nameNSStringName; cannot be empty, max length 1024 characters, truncated if exceeded.
operationNSStringCategory; cannot be empty, max length 128 characters, truncated if exceeded
descriptionNSStringDescription; max length 1024 characters, truncated if exceeded
  • Example
id<NBSSpan> span = [NBSAppAgent startSpanWithName:@"span_name" operation:@"span_operation"];
id<NBSSpan> sub = [span startChildWithName:@"sub_name" operation:@"sub_operation"];
[sub finishWithStatus:NBSSpanStatusSuccess];
[span finishWithStatus:NBSSpanStatusSuccess];

Set Data

  • API
- (void)setDataValue:(nullable id)value forKey:(NSString *)key;
  • Parameters
ParameterTypeDescription
valueidValue of the data
keyNSStringKey of the data; if the key is the same, the value is overwritten
  • Example
id<NBSSpan> span = [NBSAppAgent startSpanWithName:@"span_name" operation:@"span_operation"];
[span setDataValue:@"dataValue" forKey:@"dataKey"];
[span finishWithStatus:NBSSpanStatusSuccess];

Set Tag

  • API
- (void)setTagValue:(NSString *)value forKey:(NSString *)key;
  • Parameters
ParameterTypeDescription
valueNSStringValue of the tag
keyNSStringKey of the tag; if the key is the same, the value is overwritten
  • Example
id<NBSSpan> span = [NBSAppAgent startSpanWithName:@"span_name" operation:@"span_operation"];
[span setTagValue:@"tagValue" forKey:@"tagKey"];
[span finishWithStatus:NBSSpanStatusSuccess];