Skip to content

Commit

Permalink
fix: report instances of dropped profiles (#3108)
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Jun 27, 2023
1 parent 3cb68af commit c2ec420
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Sources/Sentry/SentryDiscardReasonMapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
NSString *const kSentryDiscardReasonNameQueueOverflow = @"queue_overflow";
NSString *const kSentryDiscardReasonNameCacheOverflow = @"cache_overflow";
NSString *const kSentryDiscardReasonNameRateLimitBackoff = @"ratelimit_backoff";
NSString *const kSentryDiscardReasonNameInsufficientData = @"insufficient_data";

NSString *_Nonnull nameForSentryDiscardReason(SentryDiscardReason reason)
{
Expand All @@ -25,5 +26,7 @@
return kSentryDiscardReasonNameCacheOverflow;
case kSentryDiscardReasonRateLimitBackoff:
return kSentryDiscardReasonNameRateLimitBackoff;
case kSentryDiscardReasonInsufficientData:
return kSentryDiscardReasonNameInsufficientData;
}
}
10 changes: 8 additions & 2 deletions Sources/Sentry/SentryProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,26 @@
NSDictionary<NSString *, id> *
serializedProfileData(NSDictionary<NSString *, id> *profileData, SentryTransaction *transaction,
SentryId *profileID, NSString *truncationReason, NSString *environment, NSString *release,
NSDictionary<NSString *, id> *serializedMetrics, NSArray<SentryDebugMeta *> *debugMeta)
NSDictionary<NSString *, id> *serializedMetrics, NSArray<SentryDebugMeta *> *debugMeta,
SentryHub *hub)
{
NSMutableArray<SentrySample *> *const samples = profileData[@"profile"][@"samples"];
// We need at least two samples to be able to draw a stack frame for any given function: one
// sample for the start of the frame and another for the end. Otherwise we would only have a
// stack frame with 0 duration, which wouldn't make sense.
if ([samples count] < 2) {
SENTRY_LOG_DEBUG(@"Not enough samples in profile");
[hub.getClient recordLostEvent:kSentryDataCategoryProfile
reason:kSentryDiscardReasonEventProcessor];
return nil;
}

// slice the profile data to only include the samples/metrics within the transaction
const auto slicedSamples = slicedProfileSamples(samples, transaction);
if (slicedSamples.count < 2) {
SENTRY_LOG_DEBUG(@"Not enough samples in profile during the transaction");
[hub.getClient recordLostEvent:kSentryDataCategoryProfile
reason:kSentryDiscardReasonEventProcessor];
return nil;
}
const auto payload = [NSMutableDictionary<NSString *, id> dictionary];
Expand Down Expand Up @@ -549,7 +554,8 @@ + (SentryEnvelopeItem *)createProfilingEnvelopeItemForTransaction:(SentryTransac
?: _gCurrentProfiler->_hub.getClient.options.environment,
_gCurrentProfiler->_hub.getClient.options.releaseName,
[_gCurrentProfiler->_metricProfiler serializeForTransaction:transaction],
[_gCurrentProfiler->_debugImageProvider getDebugImagesCrashed:NO]);
[_gCurrentProfiler->_debugImageProvider getDebugImagesCrashed:NO],
_gCurrentProfiler -> _hub);
}

+ (void)timeoutAbort
Expand Down
5 changes: 3 additions & 2 deletions Sources/Sentry/include/SentryDiscardReason.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ typedef NS_ENUM(NSUInteger, SentryDiscardReason) {
kSentryDiscardReasonNetworkError = 3,
kSentryDiscardReasonQueueOverflow = 4,
kSentryDiscardReasonCacheOverflow = 5,
kSentryDiscardReasonRateLimitBackoff = 6
kSentryDiscardReasonRateLimitBackoff = 6,
kSentryDiscardReasonInsufficientData = 7
};

static DEPRECATED_MSG_ATTRIBUTE(
"Use nameForSentryDiscardReason() instead.") NSString *_Nonnull const SentryDiscardReasonNames[]
= { @"before_send", @"event_processor", @"sample_rate", @"network_error", @"queue_overflow",
@"cache_overflow", @"ratelimit_backoff" };
@"cache_overflow", @"ratelimit_backoff", @"insufficient_data" };
1 change: 1 addition & 0 deletions Sources/Sentry/include/SentryDiscardReasonMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ FOUNDATION_EXPORT NSString *const kSentryDiscardReasonNameNetworkError;
FOUNDATION_EXPORT NSString *const kSentryDiscardReasonNameQueueOverflow;
FOUNDATION_EXPORT NSString *const kSentryDiscardReasonNameCacheOverflow;
FOUNDATION_EXPORT NSString *const kSentryDiscardReasonNameRateLimitBackoff;
FOUNDATION_EXPORT NSString *const kSentryDiscardReasonNameInsufficientData;

NSString *nameForSentryDiscardReason(SentryDiscardReason reason);

Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentryProfiler+Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
NSDictionary<NSString *, id> *serializedProfileData(NSDictionary<NSString *, id> *profileData,
SentryTransaction *transaction, SentryId *profileID, NSString *truncationReason,
NSString *environment, NSString *release, NSDictionary<NSString *, id> *serializedMetrics,
NSArray<SentryDebugMeta *> *debugMeta);
NSArray<SentryDebugMeta *> *debugMeta, SentryHub *hub);

NS_ASSUME_NONNULL_END

Expand Down
3 changes: 2 additions & 1 deletion Tests/SentryProfilerTests/SentryProfilerTests.mm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "SentryEvent+Private.h"
#import "SentryHub+TestInit.h"
#import "SentryId.h"
#import "SentryProfileTimeseries.h"
#import "SentryProfiler+Test.h"
Expand Down Expand Up @@ -216,7 +217,7 @@ - (void)testProfilerMutationDuringSerialization
const auto profileID = [[SentryId alloc] init];
const auto serialization = serializedProfileData(profileData, transaction, profileID,
profilerTruncationReasonName(SentryProfilerTruncationReasonNormal), @"test", @"someRelease",
@{}, @[]);
@{}, @[], [[SentryHub alloc] initWithClient:nil andScope:nil]);

// cause the data structures to be modified again: add new addresses
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class SentryDiscardReasonMapperTests: XCTestCase {
XCTAssertEqual(kSentryDiscardReasonNameQueueOverflow, nameForSentryDiscardReason(.queueOverflow))
XCTAssertEqual(kSentryDiscardReasonNameCacheOverflow, nameForSentryDiscardReason(.cacheOverflow))
XCTAssertEqual(kSentryDiscardReasonNameRateLimitBackoff, nameForSentryDiscardReason(.rateLimitBackoff))
XCTAssertEqual(kSentryDiscardReasonNameInsufficientData, nameForSentryDiscardReason(.insufficientData))
}
}
4 changes: 4 additions & 0 deletions Tests/SentryTests/State/SentryHub+TestInit.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#import <Sentry/Sentry.h>

@class SentryClient;
@class SentryCrashWrapper;
@protocol SentryCurrentDateProvider;

NS_ASSUME_NONNULL_BEGIN

/** Expose the internal test init for testing. */
Expand Down

0 comments on commit c2ec420

Please sign in to comment.