Skip to content

Commit

Permalink
feat: Send trace origin (#2957)
Browse files Browse the repository at this point in the history
Start sending trace origin for all transactions and spans.

Co-authored-by: Dhiogo Brustolin <[email protected]>
Co-authored-by: Sentry Github Bot <[email protected]>
  • Loading branch information
3 people authored Apr 26, 2023
1 parent 53a8885 commit 7a7de19
Show file tree
Hide file tree
Showing 38 changed files with 461 additions and 113 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

### Features

- Send trace origin (#2957)

[Trace origin](https://develop.sentry.dev/sdk/performance/trace-origin/) indicates what created a trace or a span. Not all transactions and spans contain enough information to tell whether the user or what precisely in the SDK created it. Origin solves this problem. The SDK now sends origin for transactions and spans.

- Create User and Breadcrumb from map (#2820)


### Fixes

- Improved performance serializing profiling data (#2863)
Expand Down
2 changes: 2 additions & 0 deletions Samples/iOS-SwiftUI/iOS-SwiftUI-UITests/LaunchUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class LaunchUITests: XCTestCase {
XCTAssertEqual(childName.label, "Child Span")
XCTAssertEqual(transactionName.label, "Content View Body")
XCTAssertEqual(childParentId.label, transactionId.label)
XCTAssertEqual("auto.ui.swift_ui", app.staticTexts["TRACE_ORIGIN"].label)
XCTAssertEqual("auto.ui.swift_ui", app.staticTexts["CHILD_TRACE_ORIGIN"].label)
}

func testNoNewTransactionForSecondCallToBody() {
Expand Down
116 changes: 62 additions & 54 deletions Samples/iOS-SwiftUI/iOS-SwiftUI/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,77 +123,85 @@ struct ContentView: View {
Text(getCurrentTracer()?.transactionContext.spanId.sentrySpanIdString ?? "NO ID")
.accessibilityIdentifier("TRANSACTION_ID")

Text(getCurrentTracer()?.transactionContext.origin ?? "NO ORIGIN")
.accessibilityIdentifier("TRACE_ORIGIN")

SentryTracedView("Child Span") {
VStack {
Text(getCurrentSpan()?.spanDescription ?? "NO SPAN")
.accessibilityIdentifier("CHILD_NAME")
Text(getCurrentSpan()?.parentSpanId?.sentrySpanIdString ?? "NO SPAN")
.accessibilityIdentifier("CHILD_PARENT_SPANID")

Text(getCurrentSpan()?.origin ?? "NO CHILD ORIGIN")
.accessibilityIdentifier("CHILD_TRACE_ORIGIN")
}
}
HStack (spacing: 30) {
VStack(spacing: 16) {

Button(action: addBreadcrumbAction) {
Text("Add Breadcrumb")
}

Button(action: captureMessageAction) {
Text("Capture Message")
}

Button(action: captureUserFeedbackAction) {
Text("Capture User Feedback")
}

Button(action: captureErrorAction) {
Text("Capture Error")
}

Button(action: captureNSExceptionAction) {
Text("Capture NSException")
}
Button(action: addBreadcrumbAction) {
Text("Add Breadcrumb")
}

VStack(spacing: 16) {
Button(action: captureMessageAction) {
Text("Capture Message")
}

Button(action: captureTransactionAction) {
Text("Capture Transaction")
}
Button(action: captureUserFeedbackAction) {
Text("Capture User Feedback")
}

Button(action: {
SentrySDK.crash()
}) {
Text("Crash")
}

Button(action: {
DispatchQueue.main.async {
self.asyncCrash1()
Button(action: captureErrorAction) {
Text("Capture Error")
}
}) {
Text("Async Crash")
}

Button(action: oomCrashAction) {
Text("OOM Crash")
}

NavigationLink(destination: SecondView()) {
Text("Show Detail View 1")
}

NavigationLink(destination: LoremIpsumView()) {
Text("Lorem Ipsum")
}

NavigationLink(destination: UIKitScreen()) {
Text("UIKit Screen")
}
Button(action: captureNSExceptionAction) {
Text("Capture NSException")
}

NavigationLink(destination: FormScreen()) {
Text("Form Screen")
}
Button(action: captureTransactionAction) {
Text("Capture Transaction")
}

SecondView()
}
VStack(spacing: 16) {
Button(action: {
SentrySDK.crash()
}) {
Text("Crash")
}

Button(action: {
DispatchQueue.main.async {
self.asyncCrash1()
}
}) {
Text("Async Crash")
}

Button(action: oomCrashAction) {
Text("OOM Crash")
}

NavigationLink(destination: SecondView()) {
Text("Show Detail View 1")
}

NavigationLink(destination: LoremIpsumView()) {
Text("Lorem Ipsum")
}

NavigationLink(destination: UIKitScreen()) {
Text("UIKit Screen")
}

NavigationLink(destination: FormScreen()) {
Text("Form Screen")
}
}
}
SecondView()
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@
15E0A8F22411A45A00F044E3 /* SentrySession.m in Sources */ = {isa = PBXBuildFile; fileRef = 15E0A8F12411A45A00F044E3 /* SentrySession.m */; };
33042A0D29DAF79A00C60085 /* SentryExtraContextProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 33042A0C29DAF79A00C60085 /* SentryExtraContextProvider.m */; };
33042A1729DC2C4300C60085 /* SentryExtraContextProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33042A1629DC2C4300C60085 /* SentryExtraContextProviderTests.swift */; };
622C08D829E546F4002571D4 /* SentryTraceOrigins.h in Headers */ = {isa = PBXBuildFile; fileRef = 622C08D729E546F4002571D4 /* SentryTraceOrigins.h */; };
622C08DB29E554B9002571D4 /* SentrySpanContext+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 622C08D929E554B9002571D4 /* SentrySpanContext+Private.h */; };
627E7589299F6FE40085504D /* SentryInternalDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 627E7588299F6FE40085504D /* SentryInternalDefines.h */; };
62885DA729E946B100554F38 /* TestConncurrentModifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62885DA629E946B100554F38 /* TestConncurrentModifications.swift */; };
62950F1029E7FE0100A42624 /* SentryTransactionContextTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62950F0F29E7FE0100A42624 /* SentryTransactionContextTests.swift */; };
62B86CFC29F052BB008F3947 /* SentryTestLogConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 62B86CFB29F052BB008F3947 /* SentryTestLogConfig.m */; };
62E081A929ED4260000F69FC /* SentryBreadcrumbDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 62E081A829ED4260000F69FC /* SentryBreadcrumbDelegate.h */; };
62E081AB29ED4322000F69FC /* SentryBreadcrumbTestDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E081AA29ED4322000F69FC /* SentryBreadcrumbTestDelegate.swift */; };
Expand Down Expand Up @@ -933,8 +936,11 @@
33042A0B29DAF5F400C60085 /* SentryExtraContextProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryExtraContextProvider.h; sourceTree = "<group>"; };
33042A0C29DAF79A00C60085 /* SentryExtraContextProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryExtraContextProvider.m; sourceTree = "<group>"; };
33042A1629DC2C4300C60085 /* SentryExtraContextProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryExtraContextProviderTests.swift; sourceTree = "<group>"; };
622C08D729E546F4002571D4 /* SentryTraceOrigins.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTraceOrigins.h; path = include/SentryTraceOrigins.h; sourceTree = "<group>"; };
622C08D929E554B9002571D4 /* SentrySpanContext+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentrySpanContext+Private.h"; path = "include/SentrySpanContext+Private.h"; sourceTree = "<group>"; };
627E7588299F6FE40085504D /* SentryInternalDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryInternalDefines.h; path = include/SentryInternalDefines.h; sourceTree = "<group>"; };
62885DA629E946B100554F38 /* TestConncurrentModifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestConncurrentModifications.swift; sourceTree = "<group>"; };
62950F0F29E7FE0100A42624 /* SentryTransactionContextTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTransactionContextTests.swift; sourceTree = "<group>"; };
62B86CFB29F052BB008F3947 /* SentryTestLogConfig.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryTestLogConfig.m; sourceTree = "<group>"; };
62E081A829ED4260000F69FC /* SentryBreadcrumbDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryBreadcrumbDelegate.h; path = include/SentryBreadcrumbDelegate.h; sourceTree = "<group>"; };
62E081AA29ED4322000F69FC /* SentryBreadcrumbTestDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBreadcrumbTestDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2612,6 +2618,7 @@
7BEFB043270B0F630025F808 /* SentryTracerObjCTests.m */,
D8137D52272B53070082656C /* TestSentrySpan.h */,
D8137D53272B53070082656C /* TestSentrySpan.m */,
62950F0F29E7FE0100A42624 /* SentryTransactionContextTests.swift */,
);
path = Transaction;
sourceTree = "<group>";
Expand Down Expand Up @@ -3146,8 +3153,10 @@
children = (
8ECC673925C23996000E2BF6 /* SentrySpanContext.h */,
8ECC674325C23A1F000E2BF6 /* SentrySpanContext.m */,
622C08D929E554B9002571D4 /* SentrySpanContext+Private.h */,
8E4E7C7325DAAB49006AB9E2 /* SentrySpanProtocol.h */,
7B3B83712833832B0001FDEB /* SentrySpanOperations.h */,
622C08D729E546F4002571D4 /* SentryTraceOrigins.h */,
8E4E7C6C25DAAAFE006AB9E2 /* SentrySpan.h */,
8EC3AE7925CA23B600E7591A /* SentrySpan.m */,
7BE912AA272162AF00E49E62 /* SentryNoOpSpan.h */,
Expand Down Expand Up @@ -3370,6 +3379,7 @@
8E4E7C6D25DAAAFE006AB9E2 /* SentryTransaction.h in Headers */,
63FE715D20DA4C1100CDBAE8 /* SentryCrashSymbolicator.h in Headers */,
D8ACE3CF2762187D00F5A213 /* SentryFileIOTrackingIntegration.h in Headers */,
622C08D829E546F4002571D4 /* SentryTraceOrigins.h in Headers */,
7BECF42226145C5D00D9826E /* SentryMechanismMeta.h in Headers */,
63FE718920DA4C1100CDBAE8 /* SentryCrash.h in Headers */,
63AA769A1EB9C1C200D153DE /* SentryLog.h in Headers */,
Expand Down Expand Up @@ -3545,6 +3555,7 @@
63FE716D20DA4C1100CDBAE8 /* SentryCrashSysCtl.h in Headers */,
639889BB1EDED18400EA7442 /* SentrySwizzle.h in Headers */,
7BD4BD4127EB0F0D0071F4FF /* SentryDiscardReason.h in Headers */,
622C08DB29E554B9002571D4 /* SentrySpanContext+Private.h in Headers */,
D8AB40DB2806EC1900E5E9F7 /* SentryScreenshotIntegration.h in Headers */,
7B3B83722833832B0001FDEB /* SentrySpanOperations.h in Headers */,
7BF9EF722722A84800B5BBEF /* SentryClassRegistrator.h in Headers */,
Expand Down Expand Up @@ -4230,6 +4241,7 @@
7BD86ECD264A78A6005439DB /* SentryAppStartTrackerTests.swift in Sources */,
7BB6550D253EEB3900887E87 /* SentryUserFeedbackTests.swift in Sources */,
7BBD18B7245180FF00427C76 /* SentryDsnTests.m in Sources */,
62950F1029E7FE0100A42624 /* SentryTransactionContextTests.swift in Sources */,
0A2D7BBA29152CBF008727AF /* SentryWatchdogTerminationsScopeObserverTests.swift in Sources */,
7BD4BD4B27EB2DC20071F4FF /* SentryDiscardedEventTests.swift in Sources */,
63FE721A20DA66EC00CDBAE8 /* SentryCrashSysCtl_Tests.m in Sources */,
Expand Down
11 changes: 10 additions & 1 deletion Sources/Sentry/Public/SentrySpanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ SENTRY_NO_INIT
*/
@property (nullable, nonatomic, copy, readonly) NSString *spanDescription;

/**
* The origin of the span indicates what created the span.
*
* @note Gets set by the SDK. It is not expected to be set manually by users. Although the protocol
* allows this value to be optional, we make it nonnullable as we always send the value.
*
* @see <https://develop.sentry.dev/sdk/performance/trace-origin>
*/
@property (nonatomic, copy) NSString *origin;

/**
* Init a @c SentryContext with an operation code.
* @note @c traceId and @c spanId with be randomly created; @c sampled by default is
Expand All @@ -57,7 +67,6 @@ SENTRY_NO_INIT
* @param operation The operation this span is measuring.
* @param sampled Determines whether the trace should be sampled.
*/

- (instancetype)initWithOperation:(NSString *)operation sampled:(SentrySampleDecision)sampled;

/**
Expand Down
10 changes: 10 additions & 0 deletions Sources/Sentry/Public/SentrySpanProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ NS_SWIFT_NAME(Span)
*/
@property (nonatomic, copy) NSString *operation;

/**
* The origin of the span indicates what created the span.
*
* @note Gets set by the SDK. It is not expected to be set manually by users. Although the protocol
* allows this value to be optional, we make it nonnullable as we always send the value.
*
* @see <https://develop.sentry.dev/sdk/performance/trace-origin>
*/
@property (nonatomic, copy) NSString *origin;

/**
* Longer description of the span's operation, which uniquely identifies the span but is
* consistent across instances of the span.
Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/SentryCoreDataTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@import SentryPrivate;
#import "SentryStacktrace.h"
#import "SentryThreadInspector.h"
#import "SentryTraceOrigins.h"

@implementation SentryCoreDataTracker {
SentryPredicateDescriptor *predicateDescriptor;
Expand Down Expand Up @@ -39,6 +40,7 @@ - (NSArray *)managedObjectContext:(NSManagedObjectContext *)context
[SentrySDK.currentHub.scope useSpan:^(id<SentrySpan> _Nullable span) {
fetchSpan = [span startChildWithOperation:SENTRY_COREDATA_FETCH_OPERATION
description:[self descriptionFromRequest:request]];
fetchSpan.origin = SentryTraceOriginAutoDBCoreData;
}];

if (fetchSpan) {
Expand Down Expand Up @@ -85,7 +87,7 @@ - (BOOL)managedObjectContext:(NSManagedObjectContext *)context
fetchSpan = [span startChildWithOperation:SENTRY_COREDATA_SAVE_OPERATION
description:[self descriptionForOperations:operations
inContext:context]];

fetchSpan.origin = SentryTraceOriginAutoDBCoreData;
if (fetchSpan) {
[SentryLog
logWithMessage:[NSString
Expand Down
8 changes: 6 additions & 2 deletions Sources/Sentry/SentryHub.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "SentryScope+Private.h"
#import "SentrySerialization.h"
#import "SentrySession+Private.h"
#import "SentryTraceOrigins.h"
#import "SentryTracer.h"
#import "SentryTracesSampler.h"
#import "SentryTransaction.h"
Expand Down Expand Up @@ -306,7 +307,8 @@ - (SentryId *)captureEvent:(SentryEvent *)event
return [self startTransactionWithContext:[[SentryTransactionContext alloc]
initWithName:name
nameSource:kSentryTransactionNameSourceCustom
operation:operation]];
operation:operation
origin:SentryTraceOriginManual]];
}

- (id<SentrySpan>)startTransactionWithName:(NSString *)name
Expand All @@ -316,7 +318,8 @@ - (SentryId *)captureEvent:(SentryEvent *)event
return [self startTransactionWithContext:[[SentryTransactionContext alloc]
initWithName:name
nameSource:kSentryTransactionNameSourceCustom
operation:operation]
operation:operation
origin:SentryTraceOriginManual]
bindToScope:bindToScope];
}

Expand Down Expand Up @@ -358,6 +361,7 @@ - (SentryTransactionContext *)transactionContext:(SentryTransactionContext *)con
return [[SentryTransactionContext alloc] initWithName:context.name
nameSource:context.nameSource
operation:context.operation
origin:context.origin
traceId:context.traceId
spanId:context.spanId
parentSpanId:context.parentSpanId
Expand Down
2 changes: 2 additions & 0 deletions Sources/Sentry/SentryNSDataTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "SentryStacktrace.h"
#import "SentryThread.h"
#import "SentryThreadInspector.h"
#import "SentryTraceOrigins.h"
#import "SentryTracer.h"

const NSString *SENTRY_TRACKING_COUNTER_KEY = @"SENTRY_TRACKING_COUNTER_KEY";
Expand Down Expand Up @@ -166,6 +167,7 @@ - (NSData *)measureNSDataFromURL:(NSURL *)url
ioSpan = [span startChildWithOperation:operation
description:[self transactionDescriptionForFile:path
fileSize:size]];
ioSpan.origin = SentryTraceOriginAutoNSData;
}];

if (ioSpan == nil) {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Sentry/SentryNetworkTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "SentryThreadInspector.h"
#import "SentryTraceContext.h"
#import "SentryTraceHeader.h"
#import "SentryTraceOrigins.h"
#import "SentryTracer.h"
#import <objc/runtime.h>

Expand Down Expand Up @@ -162,6 +163,7 @@ - (void)urlSessionTaskResume:(NSURLSessionTask *)sessionTask
startChildWithOperation:SENTRY_NETWORK_REQUEST_OPERATION
description:[NSString stringWithFormat:@"%@ %@",
sessionTask.currentRequest.HTTPMethod, url]];
netSpan.origin = SentryTraceOriginAutoHttpNSURLSession;
}
}];

Expand Down
Loading

0 comments on commit 7a7de19

Please sign in to comment.