Skip to content

Commit e172fae

Browse files
committed
fix: Type check SentrySpan
1 parent 5db87fa commit e172fae

12 files changed

+122
-39
lines changed

CHANGELOG-v9.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Removes deprecated useSpan function (#5591)
99
Removes deprecated SentryDebugImageProvider class (#5598)
1010
Makes app hang tracking V2 the default and removes the option to enable/disable it (#5615)
1111
Removes segment property on SentryUser, SentryBaggage, and SentryTraceContext (#5638)
12-
Removes public SentrySerializable conformance from many public models (#5636, #5840)
12+
Removes public SentrySerializable conformance from many public models (#5636, #5840, #5982)
1313
Removes Decodable conformances from the public API of model classes (#5691)
1414
Removes enableTracing property from SentryOptions (#5694)
1515
Removes deprecated `setExtraValue` from SentrySpan (#5864)

Sources/Sentry/Public/SentrySpanProtocol.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#else
66
# import <SentryDefines.h>
77
#endif
8-
#import SENTRY_HEADER(SentrySerializable)
8+
#if !SDK_V9
9+
# import SENTRY_HEADER(SentrySerializable)
10+
#endif // SDK_V9
911
#import SENTRY_HEADER(SentrySpanContext)
1012

1113
NS_ASSUME_NONNULL_BEGIN
@@ -17,7 +19,11 @@ NS_ASSUME_NONNULL_BEGIN
1719
@class SentryTraceHeader;
1820

1921
NS_SWIFT_NAME(Span)
22+
#if SDK_V9
23+
@protocol SentrySpan <NSObject>
24+
#else
2025
@protocol SentrySpan <SentrySerializable>
26+
#endif
2127

2228
/**
2329
* Determines which trace the Span belongs to.
@@ -190,6 +196,8 @@ NS_SWIFT_NAME(Span)
190196
*/
191197
- (nullable NSString *)baggageHttpHeader;
192198

199+
- (NSDictionary<NSString *, id> *)serialize;
200+
193201
@end
194202

195203
NS_ASSUME_NONNULL_END

Sources/Sentry/SentryBuildAppStartSpans.m

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,40 +55,41 @@
5555
NSDate *appStartEndTimestamp = [appStartMeasurement.appStartTimestamp
5656
dateByAddingTimeInterval:appStartMeasurement.duration];
5757

58-
SentrySpan *appStartSpan = sentryBuildAppStartSpan(tracer, tracer.spanId, operation, type);
58+
SentrySpan *appStartSpan
59+
= (SentrySpan *)sentryBuildAppStartSpan(tracer, tracer.spanId, operation, type);
5960
[appStartSpan setStartTimestamp:appStartMeasurement.appStartTimestamp];
6061
[appStartSpan setTimestamp:appStartEndTimestamp];
6162

6263
[appStartSpans addObject:appStartSpan];
6364

6465
if (!appStartMeasurement.isPreWarmed) {
65-
SentrySpan *premainSpan
66-
= sentryBuildAppStartSpan(tracer, appStartSpan.spanId, operation, @"Pre Runtime Init");
66+
SentrySpan *premainSpan = (SentrySpan *)sentryBuildAppStartSpan(
67+
tracer, appStartSpan.spanId, operation, @"Pre Runtime Init");
6768
[premainSpan setStartTimestamp:appStartMeasurement.appStartTimestamp];
6869
[premainSpan setTimestamp:appStartMeasurement.runtimeInitTimestamp];
6970
[appStartSpans addObject:premainSpan];
7071

71-
SentrySpan *runtimeInitSpan = sentryBuildAppStartSpan(
72+
SentrySpan *runtimeInitSpan = (SentrySpan *)sentryBuildAppStartSpan(
7273
tracer, appStartSpan.spanId, operation, @"Runtime Init to Pre Main Initializers");
7374
[runtimeInitSpan setStartTimestamp:appStartMeasurement.runtimeInitTimestamp];
7475
[runtimeInitSpan setTimestamp:appStartMeasurement.moduleInitializationTimestamp];
7576
[appStartSpans addObject:runtimeInitSpan];
7677
}
7778

78-
SentrySpan *appInitSpan
79-
= sentryBuildAppStartSpan(tracer, appStartSpan.spanId, operation, @"UIKit Init");
79+
SentrySpan *appInitSpan = (SentrySpan *)sentryBuildAppStartSpan(
80+
tracer, appStartSpan.spanId, operation, @"UIKit Init");
8081
[appInitSpan setStartTimestamp:appStartMeasurement.moduleInitializationTimestamp];
8182
[appInitSpan setTimestamp:appStartMeasurement.sdkStartTimestamp];
8283
[appStartSpans addObject:appInitSpan];
8384

84-
SentrySpan *didFinishLaunching
85-
= sentryBuildAppStartSpan(tracer, appStartSpan.spanId, operation, @"Application Init");
85+
SentrySpan *didFinishLaunching = (SentrySpan *)sentryBuildAppStartSpan(
86+
tracer, appStartSpan.spanId, operation, @"Application Init");
8687
[didFinishLaunching setStartTimestamp:appStartMeasurement.sdkStartTimestamp];
8788
[didFinishLaunching setTimestamp:appStartMeasurement.didFinishLaunchingTimestamp];
8889
[appStartSpans addObject:didFinishLaunching];
8990

90-
SentrySpan *frameRenderSpan
91-
= sentryBuildAppStartSpan(tracer, appStartSpan.spanId, operation, @"Initial Frame Render");
91+
SentrySpan *frameRenderSpan = (SentrySpan *)sentryBuildAppStartSpan(
92+
tracer, appStartSpan.spanId, operation, @"Initial Frame Render");
9293
[frameRenderSpan setStartTimestamp:appStartMeasurement.didFinishLaunchingTimestamp];
9394
[frameRenderSpan setTimestamp:appStartEndTimestamp];
9495
[appStartSpans addObject:frameRenderSpan];

Sources/Sentry/SentryCoreDataTracker.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ - (NSArray *)managedObjectContext:(NSManagedObjectContext *)context
5757
NSArray *result = original(request, error);
5858

5959
if (fetchSpan) {
60-
[self addExtraInfoToSpan:fetchSpan withContext:context];
60+
[self addExtraInfoToSpan:(SentrySpan *)fetchSpan withContext:context];
6161

6262
[fetchSpan setDataValue:[NSNumber numberWithInteger:result.count] forKey:@"read_count"];
6363
[fetchSpan
@@ -104,7 +104,7 @@ - (BOOL)managedObjectContext:(NSManagedObjectContext *)context
104104
BOOL result = original(error);
105105

106106
if (saveSpan) {
107-
[self addExtraInfoToSpan:saveSpan withContext:context];
107+
[self addExtraInfoToSpan:(SentrySpan *)saveSpan withContext:context];
108108
[saveSpan finishWithStatus:result ? kSentrySpanStatusOk : kSentrySpanStatusInternalError];
109109

110110
SENTRY_LOG_DEBUG(@"SentryCoreDataTracker automatically finished span with status: %@",

Sources/Sentry/SentryCrashIntegration.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
void
4242
sentry_finishAndSaveTransaction(void)
4343
{
44-
SentrySpan *span = SentrySDKInternal.currentHub.scope.span;
44+
SentrySpan *span = (SentrySpan *)SentrySDKInternal.currentHub.scope.span;
4545

4646
if (span != nil) {
4747
SentryTracer *tracer = [span tracer];

Sources/Sentry/SentryTimeToDisplayTracker.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ - (BOOL)startForTracer:(SentryTracer *)tracer
6262
}
6363

6464
SENTRY_LOG_DEBUG(@"Starting initial display span");
65-
self.initialDisplaySpan =
66-
[tracer startChildWithOperation:SentrySpanOperationUiLoadInitialDisplay
67-
description:[NSString stringWithFormat:@"%@ initial display", _name]];
65+
self.initialDisplaySpan = (SentrySpan *)[tracer
66+
startChildWithOperation:SentrySpanOperationUiLoadInitialDisplay
67+
description:[NSString stringWithFormat:@"%@ initial display", _name]];
6868
self.initialDisplaySpan.origin = SentryTraceOriginAutoUITimeToDisplay;
6969

7070
if (self.waitForFullDisplay) {
7171
SENTRY_LOG_DEBUG(@"Starting full display span");
72-
self.fullDisplaySpan =
73-
[tracer startChildWithOperation:SentrySpanOperationUiLoadFullDisplay
74-
description:[NSString stringWithFormat:@"%@ full display", _name]];
72+
self.fullDisplaySpan = (SentrySpan *)[tracer
73+
startChildWithOperation:SentrySpanOperationUiLoadFullDisplay
74+
description:[NSString stringWithFormat:@"%@ full display", _name]];
7575
self.fullDisplaySpan.origin = SentryTraceOriginManualUITimeToDisplay;
7676

7777
// By concept TTID and TTFD spans should have the same beginning,

Sources/Sentry/SentryTracer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ + (nullable SentryTracer *)getTracer:(id<SentrySpan> _Nullable)span
926926
}
927927

928928
if ([span isKindOfClass:[SentryTracer class]]) {
929-
return span;
929+
return (SentryTracer *)span;
930930
} else if ([span isKindOfClass:[SentrySpan class]]) {
931931
return [(SentrySpan *)span tracer];
932932
}

Sources/Sentry/SentryUIViewControllerPerformanceTracker.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ - (void)startRootSpanFor:(UIViewController *)controller
179179
}
180180

181181
spanId = [self getSpanIdForViewController:controller];
182-
SentrySpan *_Nullable vcSpan =
183-
[self.tracker getSpan:SENTRY_UNWRAP_NULLABLE(SentrySpanId, spanId)];
182+
SentrySpan *_Nullable vcSpan
183+
= (SentrySpan *)[self.tracker getSpan:SENTRY_UNWRAP_NULLABLE(SentrySpanId, spanId)];
184184

185185
if (![vcSpan isKindOfClass:[SentryTracer self]]) {
186186
// Since TTID and TTFD are meant to the whole screen

Tests/SentryTests/Integrations/Performance/IO/SentryFileIOTrackingIntegrationObjCTests.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@ - (void)assertDataWritten
204204

205205
- (void)assertTransactionForOperation:(NSString *)operation block:(void (^)(void))block
206206
{
207-
SentryTracer *parentTransaction = [SentrySDK startTransactionWithName:@"Transaction"
208-
operation:@"Test"
209-
bindToScope:YES];
207+
SentryTracer *parentTransaction
208+
= (SentryTracer *)[SentrySDK startTransactionWithName:@"Transaction"
209+
operation:@"Test"
210+
bindToScope:YES];
210211

211212
block();
212213

213-
SentrySpan *ioSpan = parentTransaction.children.firstObject;
214+
SentrySpan *ioSpan = (SentrySpan *)parentTransaction.children.firstObject;
214215

215216
XCTAssertEqual(parentTransaction.children.count, 1);
216217
XCTAssertEqual([ioSpan.data[@"file.size"] unsignedIntValue], someData.length);

Tests/SentryTests/Integrations/Performance/IO/SentryNSFileManagerSwizzlingTests.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,16 @@ - (void)assertTransactionForOperation:(NSString *)operation
162162
spanCount:(NSUInteger)spanCount
163163
block:(void (^)(void))block
164164
{
165-
SentryTracer *parentTransaction = [SentrySDK startTransactionWithName:@"Transaction"
166-
operation:@"Test"
167-
bindToScope:YES];
165+
SentryTracer *parentTransaction
166+
= (SentryTracer *)[SentrySDK startTransactionWithName:@"Transaction"
167+
operation:@"Test"
168+
bindToScope:YES];
168169

169170
block();
170171

171172
XCTAssertEqual(parentTransaction.children.count, spanCount);
172173

173-
SentrySpan *ioSpan = parentTransaction.children.firstObject;
174+
SentrySpan *ioSpan = (SentrySpan *)parentTransaction.children.firstObject;
174175
if (spanCount > 0) {
175176
XCTAssertEqual([ioSpan.data[@"file.size"] unsignedIntValue], someData.length);
176177
XCTAssertEqualObjects(ioSpan.data[@"file.path"], filePath);

0 commit comments

Comments
 (0)