@@ -36,17 +36,20 @@ - (NSArray *)managedObjectContext:(NSManagedObjectContext *)context
3636 error : (NSError **)error
3737 originalImp : (NSArray *(NS_NOESCAPE ^)(NSFetchRequest *, NSError **))original
3838{
39- __block id <SentrySpan> fetchSpan;
40- [SentrySDK.currentHub.scope useSpan: ^(id <SentrySpan> _Nullable span) {
41- fetchSpan = [span startChildWithOperation: SentrySpanOperation.coredataFetchOperation
42- description: [self descriptionFromRequest: request]];
43- fetchSpan.origin = SentryTraceOrigin.autoDBCoreData ;
44- }];
39+ id <SentrySpan> _Nullable currentSpan = [SentrySDK.currentHub.scope span ];
40+ id <SentrySpan> _Nullable fetchSpan;
41+ if (currentSpan) {
42+ NSString *spanDescription = [self descriptionFromRequest: request];
43+ fetchSpan = [currentSpan startChildWithOperation: SentrySpanOperation.coredataFetchOperation
44+ description: spanDescription];
45+ }
4546
4647 if (fetchSpan) {
48+ fetchSpan.origin = SentryTraceOrigin.autoDBCoreData ;
49+
4750 SENTRY_LOG_DEBUG (@" SentryCoreDataTracker automatically started a new span with "
48- @" description: %@ , operation: %@ " ,
49- fetchSpan.description , fetchSpan.operation );
51+ @" description: %@ , operation: %@ , origin: %@ " ,
52+ fetchSpan.description , fetchSpan.operation , fetchSpan. origin );
5053 }
5154
5255 NSArray *result = original (request, error);
@@ -70,22 +73,26 @@ - (BOOL)managedObjectContext:(NSManagedObjectContext *)context
7073 originalImp : (BOOL (NS_NOESCAPE ^)(NSError **))original
7174{
7275
73- __block id <SentrySpan> saveSpan = nil ;
76+ __block id <SentrySpan> _Nullable saveSpan = nil ;
7477 if (context.hasChanges ) {
7578 __block NSDictionary <NSString *, NSDictionary *> *operations =
7679 [self groupEntitiesOperations: context];
7780
78- [SentrySDK.currentHub.scope useSpan: ^(id <SentrySpan> _Nullable span) {
79- saveSpan = [span startChildWithOperation: SentrySpanOperation.coredataSaveOperation
80- description: [self descriptionForOperations: operations
81- inContext: context]];
82- saveSpan.origin = SentryTraceOrigin.autoDBCoreData ;
83- }];
81+ id <SentrySpan> _Nullable currentSpan = [SentrySDK.currentHub.scope span ];
82+ if (currentSpan) {
83+ NSString *spanDescription = [self descriptionForOperations: operations
84+ inContext: context];
85+ saveSpan =
86+ [currentSpan startChildWithOperation: SentrySpanOperation.coredataSaveOperation
87+ description: spanDescription];
88+ }
8489
8590 if (saveSpan) {
91+ saveSpan.origin = SentryTraceOrigin.autoDBCoreData ;
92+
8693 SENTRY_LOG_DEBUG (@" SentryCoreDataTracker automatically started a new span with "
87- @" description: %@ , operation: %@ " ,
88- saveSpan.description , saveSpan.operation );
94+ @" description: %@ , operation: %@ , origin: %@ " ,
95+ saveSpan.description , saveSpan.operation , saveSpan. origin );
8996
9097 [saveSpan setDataValue: operations forKey: @" operations" ];
9198 } else {
0 commit comments