Skip to content

Commit

Permalink
fix(profiling): set profile id in each serialized transaction (#4030)
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Jun 5, 2024
1 parent 14f9505 commit bfe78f6
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 57 deletions.
4 changes: 4 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@
84A305572BC9EF8C00D84283 /* SentryTraceProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A305552BC9EF8C00D84283 /* SentryTraceProfiler.h */; };
84A305582BC9EF8C00D84283 /* SentryTraceProfiler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A305562BC9EF8C00D84283 /* SentryTraceProfiler.mm */; };
84A5D75B29D5170700388BFA /* TimeInterval+Sentry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */; };
84A7890A2C0E9F6400FF0803 /* SentrySpan+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A789092C0E9F5800FF0803 /* SentrySpan+Private.h */; };
84A8891C28DBD28900C51DFD /* SentryDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A8891A28DBD28900C51DFD /* SentryDevice.h */; };
84A8891D28DBD28900C51DFD /* SentryDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8891B28DBD28900C51DFD /* SentryDevice.mm */; };
84A8892128DBD8D600C51DFD /* SentryDeviceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */; };
Expand Down Expand Up @@ -1747,6 +1748,7 @@
84A305562BC9EF8C00D84283 /* SentryTraceProfiler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryTraceProfiler.mm; sourceTree = "<group>"; };
84A305592BC9FD1600D84283 /* SentryTraceProfiler+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryTraceProfiler+Test.h"; sourceTree = "<group>"; };
84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeInterval+Sentry.swift"; sourceTree = "<group>"; };
84A789092C0E9F5800FF0803 /* SentrySpan+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentrySpan+Private.h"; path = "include/SentrySpan+Private.h"; sourceTree = "<group>"; };
84A8891A28DBD28900C51DFD /* SentryDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDevice.h; path = include/SentryDevice.h; sourceTree = "<group>"; };
84A8891B28DBD28900C51DFD /* SentryDevice.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDevice.mm; sourceTree = "<group>"; };
84A8892028DBD8D600C51DFD /* SentryDeviceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryDeviceTests.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3539,6 +3541,7 @@
7B3B83712833832B0001FDEB /* SentrySpanOperations.h */,
622C08D729E546F4002571D4 /* SentryTraceOrigins.h */,
8E4E7C6C25DAAAFE006AB9E2 /* SentrySpan.h */,
84A789092C0E9F5800FF0803 /* SentrySpan+Private.h */,
8EC3AE7925CA23B600E7591A /* SentrySpan.m */,
7BE912AA272162AF00E49E62 /* SentryNoOpSpan.h */,
7BE912AC272162D900E49E62 /* SentryNoOpSpan.m */,
Expand Down Expand Up @@ -4194,6 +4197,7 @@
7BC852392458830A005A70F0 /* SentryEnvelopeItemType.h in Headers */,
63AA769D1EB9C57A00D153DE /* SentryError.h in Headers */,
63FE714F20DA4C1100CDBAE8 /* SentryCrashNSErrorUtil.h in Headers */,
84A7890A2C0E9F6400FF0803 /* SentrySpan+Private.h in Headers */,
7BC5B6FA290BCDE500D99477 /* SentryHttpStatusCodeRange+Private.h in Headers */,
7B04A9AF24EAC02C00E710B1 /* SentryRetryAfterHeaderParser.h in Headers */,
9286059529A5096600F96038 /* SentryGeo.h in Headers */,
Expand Down
5 changes: 2 additions & 3 deletions Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#import "SentrySpan.h"
#import "SentryCrashThread.h"
#import "SentryDependencyContainer.h"
#import "SentryFrame.h"
Expand All @@ -8,6 +7,7 @@
#import "SentryNSDictionarySanitize.h"
#import "SentryNoOpSpan.h"
#import "SentrySampleDecision+Private.h"
#import "SentrySpan+Private.h"
#import "SentrySpanContext.h"
#import "SentrySpanId.h"
#import "SentrySwift.h"
Expand Down Expand Up @@ -50,7 +50,6 @@ @implementation SentrySpan {
#endif // SENTRY_HAS_UIKIT

#if SENTRY_TARGET_PROFILING_SUPPORTED
NSString *_Nullable _profileSessionID;
BOOL _isContinuousProfiling;
#endif // SENTRY_TARGET_PROFILING_SUPPORTED
}
Expand Down Expand Up @@ -376,7 +375,7 @@ - (NSDictionary *)serialize

#if SENTRY_TARGET_PROFILING_SUPPORTED
if (_profileSessionID != nil) {
mutableDictionary[@"profile_id"] = _profileSessionID;
mutableDictionary[@"profiler_id"] = _profileSessionID;
}
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

Expand Down
8 changes: 8 additions & 0 deletions Sources/Sentry/SentryTransaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#import "SentryEnvelopeItemType.h"
#import "SentryMeasurementValue.h"
#import "SentryNSDictionarySanitize.h"
#import "SentryProfilingConditionals.h"
#import "SentrySpan+Private.h"
#import "SentrySwift.h"
#import "SentryTransactionContext.h"

Expand Down Expand Up @@ -54,6 +56,12 @@ - (instancetype)initWithTrace:(SentryTracer *)trace children:(NSArray<id<SentryS
serializedData[@"_metrics_summary"] = metricsSummary;
[serializedTrace removeObjectForKey:@"_metrics_summary"];
}
#if SENTRY_TARGET_PROFILING_SUPPORTED
NSMutableDictionary *traceDataEntry =
[serializedTrace[@"data"] mutableCopy] ?: [NSMutableDictionary dictionary];
traceDataEntry[@"profiler_id"] = self.trace.profileSessionID;
serializedTrace[@"data"] = traceDataEntry;
#endif // SENTRY_TARGET_PROFILING_SUPPORTED
mutableContext[@"trace"] = serializedTrace;

[serializedData setValue:mutableContext forKey:@"contexts"];
Expand Down
12 changes: 12 additions & 0 deletions Sources/Sentry/include/SentrySpan+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import "SentrySpan.h"

#import "SentryProfilingConditionals.h"

@interface
SentrySpan ()

#if SENTRY_TARGET_PROFILING_SUPPORTED
@property (copy, nonatomic) NSString *_Nullable profileSessionID;
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

@end
Loading

0 comments on commit bfe78f6

Please sign in to comment.