Skip to content

Commit

Permalink
Add crosstalk API methods for creating span options and contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
yousif-bugsnag committed Dec 12, 2024
1 parent 99665ae commit 5a5bf82
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ - (BugsnagPerformanceSpan * _Nullable)startSpanV1:(NSString * _Nonnull)name opti
return (BugsnagPerformanceSpan *)[BugsnagPerformanceCrossTalkProxiedObject proxied:span];
}

- (BugsnagPerformanceSpanOptions *)newSpanOptionsV1 {
return (BugsnagPerformanceSpanOptions *)[BugsnagPerformanceCrossTalkProxiedObject proxied:[BugsnagPerformanceSpanOptions new]];
}

- (BugsnagPerformanceSpanContext *)newSpanContextV1:(uint64_t)traceIdHi traceIdLo:(uint64_t)traceIdLo spanId:(SpanId)spanId {
BugsnagPerformanceSpanContext *spanContext = [[BugsnagPerformanceSpanContext alloc] initWithTraceIdHi:traceIdHi
traceIdLo:traceIdLo spanId:spanId];
return (BugsnagPerformanceSpanContext *)[BugsnagPerformanceCrossTalkProxiedObject proxied:spanContext];
}

#pragma mark BSGPhasedStartup

- (void)earlyConfigure:(BSGEarlyConfiguration *)config {}
Expand Down
26 changes: 26 additions & 0 deletions Tests/BugsnagPerformanceTests/CrossTalkTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ + (NSError *)mapAPINamed:(NSString * _Nonnull)apiName toSelector:(SEL)toSelector
- (NSArray *) getCurrentTraceAndSpanId;
- (BugsnagPerformanceConfiguration *) getConfiguration;
- (BugsnagPerformanceSpan *) startSpan:(NSString *)name options:(BugsnagPerformanceSpanOptions *)options;
- (BugsnagPerformanceSpanOptions *) newSpanOptions;
- (BugsnagPerformanceSpanContext *) newSpanContext:(u_int64_t)traceIdHi traceIdLo:(u_int64_t)traceIdLo spanId:(u_int64_t)spanId;

@end

Expand Down Expand Up @@ -174,6 +176,30 @@ - (void)testStartSpanV1 {
[ExampleBugsnagPerformanceCrossTalkAPIClient.sharedInstance startSpan:@"test" options:spanOptions];
}

- (void)testNewSpanOptionsV1 {
NSError *err = [ExampleBugsnagPerformanceCrossTalkAPIClient mapAPINamed:@"newSpanOptionsV1" toSelector:@selector(newSpanOptions)];
XCTAssertNil(err);

BugsnagPerformanceSpanOptions *spanOptions = [ExampleBugsnagPerformanceCrossTalkAPIClient.sharedInstance newSpanOptions];
NSDate *startTime = [NSDate new];
spanOptions.startTime = startTime;
XCTAssertEqualObjects(spanOptions.startTime, startTime);
}

- (void)testNewSpanContextV1 {
NSError *err = [ExampleBugsnagPerformanceCrossTalkAPIClient mapAPINamed:@"newSpanContextV1:traceIdLo:spanId:" toSelector:@selector(newSpanContext:traceIdLo:spanId:)];
XCTAssertNil(err);

u_int64_t traceIdHi = 1;
u_int64_t traceIdLo = 2;
SpanId spanId = 3;
BugsnagPerformanceSpanContext *spanContext = [ExampleBugsnagPerformanceCrossTalkAPIClient.sharedInstance newSpanContext:traceIdHi traceIdLo:traceIdLo spanId:spanId];

XCTAssertEqual(spanContext.traceIdHi, traceIdHi);
XCTAssertEqual(spanContext.traceIdLo, traceIdLo);
XCTAssertEqual(spanContext.spanId, spanId);
}

#pragma mark Unit Tests: BugsnagPerformanceCrossTalkAPI published APIs (for unit testing support only)

- (void)testReturnStringTestV1 {
Expand Down

0 comments on commit 5a5bf82

Please sign in to comment.