From a7d2f90635122af0dafce10ecd9c7ac008e45622 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 15 Sep 2023 14:34:15 -0800 Subject: [PATCH 1/2] fix: decouple IDs used to profile concurrent spans in the client from those needed to identify profiles in the backend --- .../Profiling/SentryProfiledTracerConcurrency.mm | 4 ++-- Sources/Sentry/SentryProfiler.mm | 14 +++++++------- Sources/Sentry/include/SentryProfiler+Private.h | 5 ++--- Sources/Sentry/include/SentryProfiler.h | 2 +- Tests/SentryProfilerTests/SentryProfilerTests.mm | 7 +++---- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm b/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm index ed306b773ed..9ad5f4a6d43 100644 --- a/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm +++ b/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm @@ -37,7 +37,7 @@ void _unsafe_cleanUpProfiler(SentryProfiler *profiler, NSString *tracerKey) { - const auto profilerKey = profiler.profileId.sentryIdString; + const auto profilerKey = profiler.profilerId.sentryIdString; [_gTracersToProfilers removeObjectForKey:tracerKey]; _gProfilersToTracers[profilerKey] = @(_gProfilersToTracers[profilerKey].unsignedIntValue - 1); @@ -58,7 +58,7 @@ { std::lock_guard l(_gStateLock); - const auto profilerKey = profiler.profileId.sentryIdString; + const auto profilerKey = profiler.profilerId.sentryIdString; const auto tracerKey = traceId.sentryIdString; SENTRY_LOG_DEBUG( diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 8a8bc2ec444..788de4a209c 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -153,10 +153,10 @@ } NSMutableDictionary * -serializedProfileData(NSDictionary *profileData, uint64_t startSystemTime, - uint64_t endSystemTime, SentryId *profileID, NSString *truncationReason, - NSDictionary *serializedMetrics, NSArray *debugMeta, - SentryHub *hub +serializedProfileData( + NSDictionary *profileData, uint64_t startSystemTime, uint64_t endSystemTime, + NSString *truncationReason, NSDictionary *serializedMetrics, + NSArray *debugMeta, SentryHub *hub # if SENTRY_HAS_UIKIT , SentryScreenFrames *gpuData @@ -211,7 +211,7 @@ @"model" : isEmulated ? sentry_getSimulatorDeviceModel() : sentry_getDeviceModel() }; - payload[@"profile_id"] = profileID.sentryIdString; + payload[@"profile_id"] = [[[SentryId alloc] init] sentryIdString]; payload[@"truncation_reason"] = truncationReason; payload[@"environment"] = hub.scope.environmentString ?: hub.getClient.options.environment; payload[@"release"] = hub.getClient.options.releaseName; @@ -270,7 +270,7 @@ - (instancetype)init return nil; } - _profileId = [[SentryId alloc] init]; + _profilerId = [[SentryId alloc] init]; SENTRY_LOG_DEBUG(@"Initialized new SentryProfiler %@", self); _debugImageProvider = [SentryDependencyContainer sharedInstance].debugImageProvider; @@ -415,7 +415,7 @@ + (void)updateProfilePayload:(NSMutableDictionary *)payload onHub:(SentryHub *)hub; { return serializedProfileData([self._state copyProfilingData], startSystemTime, endSystemTime, - self.profileId, profilerTruncationReasonName(_truncationReason), + profilerTruncationReasonName(_truncationReason), [_metricProfiler serializeBetween:startSystemTime and:endSystemTime], [_debugImageProvider getDebugImagesCrashed:NO], hub # if SENTRY_HAS_UIKIT diff --git a/Sources/Sentry/include/SentryProfiler+Private.h b/Sources/Sentry/include/SentryProfiler+Private.h index 6a50e64d38e..5eaee6d21d0 100644 --- a/Sources/Sentry/include/SentryProfiler+Private.h +++ b/Sources/Sentry/include/SentryProfiler+Private.h @@ -17,9 +17,8 @@ NS_ASSUME_NONNULL_BEGIN NSMutableDictionary *serializedProfileData( NSDictionary *profileData, uint64_t startSystemTime, uint64_t endSystemTime, - SentryId *profileID, NSString *truncationReason, - NSDictionary *serializedMetrics, NSArray *debugMeta, - SentryHub *hub + NSString *truncationReason, NSDictionary *serializedMetrics, + NSArray *debugMeta, SentryHub *hub # if SENTRY_HAS_UIKIT , SentryScreenFrames *gpuData diff --git a/Sources/Sentry/include/SentryProfiler.h b/Sources/Sentry/include/SentryProfiler.h index 95f3cdbae93..a573862b38f 100644 --- a/Sources/Sentry/include/SentryProfiler.h +++ b/Sources/Sentry/include/SentryProfiler.h @@ -39,7 +39,7 @@ SENTRY_EXTERN_C_END */ @interface SentryProfiler : NSObject -@property (strong, nonatomic) SentryId *profileId; +@property (strong, nonatomic) SentryId *profilerId; /** * Start a profiler, if one isn't already running. diff --git a/Tests/SentryProfilerTests/SentryProfilerTests.mm b/Tests/SentryProfilerTests/SentryProfilerTests.mm index cf911a087b0..35a1374ec4e 100644 --- a/Tests/SentryProfilerTests/SentryProfilerTests.mm +++ b/Tests/SentryProfilerTests/SentryProfilerTests.mm @@ -174,10 +174,9 @@ - (void)testProfilerMutationDuringSerialization // serialize the data as if it were captured in a transaction envelope const auto profileData = [state copyProfilingData]; - const auto profileID = [[SentryId alloc] init]; - const auto serialization = serializedProfileData(profileData, 1, 2, profileID, - profilerTruncationReasonName(SentryProfilerTruncationReasonNormal), @{}, @[], - [[SentryHub alloc] initWithClient:nil andScope:nil] + const auto serialization = serializedProfileData( + profileData, 1, 2, profilerTruncationReasonName(SentryProfilerTruncationReasonNormal), @{}, + @[], [[SentryHub alloc] initWithClient:nil andScope:nil] # if SENTRY_HAS_UIKIT , [[SentryScreenFrames alloc] initWithTotal:5 From 595164189580e0ed433eef5ee3a32846102cb4ad Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Fri, 15 Sep 2023 14:38:18 -0800 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d06940e79..318db2528aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixes - Remove warning about non-portable path to file "SentryDsn.h" (#3270) +- Fix how profiles were identified in the backend for grouping and issue correlation purposes (#3282) ### Features