Skip to content

Commit

Permalink
RUMM-1615 SwiftUI View Instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep committed Oct 27, 2021
1 parent 0d6ef03 commit 8c28680
Show file tree
Hide file tree
Showing 24 changed files with 1,004 additions and 26 deletions.
86 changes: 71 additions & 15 deletions Datadog/Datadog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,19 @@
B3FC3C0926526F0000DEED9E /* VitalInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3FC3C0626526EFF00DEED9E /* VitalInfo.swift */; };
B3FC3C3C2653A97700DEED9E /* VitalInfoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3FC3C3B2653A97700DEED9E /* VitalInfoTests.swift */; };
D2135330270CA722000315AD /* DataCompressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D213532F270CA722000315AD /* DataCompressionTests.swift */; };
D24C27EA270C8BEE005DE596 /* DataCompression.swift in Sources */ = {isa = PBXBuildFile; fileRef = D24C27E9270C8BEE005DE596 /* DataCompression.swift */; };
D22C1F5C271484B400922024 /* LogEventMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22C1F5B271484B400922024 /* LogEventMapper.swift */; };
D244B3A3271EDACD003E1B29 /* SwiftUIExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D244B3A2271EDACD003E1B29 /* SwiftUIExtensionsTests.swift */; };
D24985A22728048B00B4F72D /* SwiftUIRUMViewsHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D24985A12728048B00B4F72D /* SwiftUIRUMViewsHandler.swift */; };
D24985A327280FD100B4F72D /* SwiftUIViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = D249859F2728042200B4F72D /* SwiftUIViewModifier.swift */; };
D24985A727292FCC00B4F72D /* SwiftUIRUMViewsHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D24985A627292FCC00B4F72D /* SwiftUIRUMViewsHandlerTests.swift */; };
D24C27EA270C8BEE005DE596 /* DataCompression.swift in Sources */ = {isa = PBXBuildFile; fileRef = D24C27E9270C8BEE005DE596 /* DataCompression.swift */; };
D2791EF927170A760046E07A /* RUMSwiftUIScenarioTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2791EF827170A760046E07A /* RUMSwiftUIScenarioTests.swift */; };
D2F1B81126D795F3009F3293 /* DDNoopRUMMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2F1B81026D795F3009F3293 /* DDNoopRUMMonitor.swift */; };
D2F1B81326D8DA68009F3293 /* DDNoopRUMMonitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2F1B81226D8DA68009F3293 /* DDNoopRUMMonitorTests.swift */; };
D2F1B81526D8E5FF009F3293 /* DDNoopTracerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2F1B81426D8E5FF009F3293 /* DDNoopTracerTests.swift */; };
D2F5BB36271831C200BDE2A4 /* RUMSwiftUIInstrumentationScenario.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D2F5BB35271831C200BDE2A4 /* RUMSwiftUIInstrumentationScenario.storyboard */; };
D2F5BB382718331800BDE2A4 /* SwiftUIRootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2F5BB372718331800BDE2A4 /* SwiftUIRootViewController.swift */; };
D2FCA239271D896E0020286F /* SwiftUIExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FCA238271D896E0020286F /* SwiftUIExtensions.swift */; };
E132727B24B333C700952F8B /* TracingBenchmarkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E132727A24B333C700952F8B /* TracingBenchmarkTests.swift */; };
E132727D24B35B5F00952F8B /* TracingStorageBenchmarkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E132727C24B35B5F00952F8B /* TracingStorageBenchmarkTests.swift */; };
E13A880C257922EC004FB174 /* EnvironmentSpanIntegration.swift in Sources */ = {isa = PBXBuildFile; fileRef = E13A880B257922EC004FB174 /* EnvironmentSpanIntegration.swift */; };
Expand Down Expand Up @@ -1157,11 +1165,19 @@
B3FC3C0626526EFF00DEED9E /* VitalInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VitalInfo.swift; sourceTree = "<group>"; };
B3FC3C3B2653A97700DEED9E /* VitalInfoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VitalInfoTests.swift; sourceTree = "<group>"; };
D213532F270CA722000315AD /* DataCompressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataCompressionTests.swift; sourceTree = "<group>"; };
D24C27E9270C8BEE005DE596 /* DataCompression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataCompression.swift; sourceTree = "<group>"; };
D22C1F5B271484B400922024 /* LogEventMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogEventMapper.swift; sourceTree = "<group>"; };
D244B3A2271EDACD003E1B29 /* SwiftUIExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIExtensionsTests.swift; sourceTree = "<group>"; };
D249859F2728042200B4F72D /* SwiftUIViewModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftUIViewModifier.swift; sourceTree = "<group>"; };
D24985A12728048B00B4F72D /* SwiftUIRUMViewsHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftUIRUMViewsHandler.swift; sourceTree = "<group>"; };
D24985A627292FCC00B4F72D /* SwiftUIRUMViewsHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIRUMViewsHandlerTests.swift; sourceTree = "<group>"; };
D24C27E9270C8BEE005DE596 /* DataCompression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataCompression.swift; sourceTree = "<group>"; };
D2791EF827170A760046E07A /* RUMSwiftUIScenarioTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RUMSwiftUIScenarioTests.swift; sourceTree = "<group>"; };
D2F1B81026D795F3009F3293 /* DDNoopRUMMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDNoopRUMMonitor.swift; sourceTree = "<group>"; };
D2F1B81226D8DA68009F3293 /* DDNoopRUMMonitorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDNoopRUMMonitorTests.swift; sourceTree = "<group>"; };
D2F1B81426D8E5FF009F3293 /* DDNoopTracerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDNoopTracerTests.swift; sourceTree = "<group>"; };
D2F5BB35271831C200BDE2A4 /* RUMSwiftUIInstrumentationScenario.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = RUMSwiftUIInstrumentationScenario.storyboard; sourceTree = "<group>"; };
D2F5BB372718331800BDE2A4 /* SwiftUIRootViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIRootViewController.swift; sourceTree = "<group>"; };
D2FCA238271D896E0020286F /* SwiftUIExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIExtensions.swift; sourceTree = "<group>"; };
E132727A24B333C700952F8B /* TracingBenchmarkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracingBenchmarkTests.swift; sourceTree = "<group>"; };
E132727C24B35B5F00952F8B /* TracingStorageBenchmarkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracingStorageBenchmarkTests.swift; sourceTree = "<group>"; };
E13A880B257922EC004FB174 /* EnvironmentSpanIntegration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentSpanIntegration.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1485,6 +1501,7 @@
61133BB82423979B00786299 /* InternalLoggers.swift */,
61133BBA2423979B00786299 /* SwiftExtensions.swift */,
615F197B25B5A64B00BE14B5 /* UIKitExtensions.swift */,
D2FCA238271D896E0020286F /* SwiftUIExtensions.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1738,6 +1755,7 @@
61133C362423990D00786299 /* InternalLoggersTests.swift */,
9E36D92124373EA700BFBDB7 /* SwiftExtensionsTests.swift */,
6115299625E3BEF9004F740E /* UIKitExtensionsTests.swift */,
D244B3A2271EDACD003E1B29 /* SwiftUIExtensionsTests.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1971,13 +1989,14 @@
61337036250F84F100236D58 /* RUM */ = {
isa = PBXGroup;
children = (
9EC2835C26CFF56B00FACF1C /* MobileVitals */,
61D50C532580EF41006038A3 /* RUMScenarios.swift */,
9EC2835C26CFF56B00FACF1C /* MobileVitals */,
61337037250F84FD00236D58 /* ManualInstrumentation */,
61F9CA7725125918000A5E61 /* NavigationControllerAutoInstrumentation */,
615AAC34251E34EF00C89EE9 /* TabBarAutoInstrumentation */,
6137E647252DD85400720485 /* ModalViewsAutoInstrumentation */,
6193DCA2251B5669009B8011 /* TapActionAutoInstrumentation */,
D2791EF32716F16E0046E07A /* SwiftUIInstrumentation */,
612D8F6725AEE65F000E2E09 /* Scrubbing */,
);
path = RUM;
Expand Down Expand Up @@ -2346,14 +2365,6 @@
path = URLSessionAutoInstrumentation;
sourceTree = "<group>";
};
616A9CD02535D36A00DB83CF /* UIKitHierarchyInspection */ = {
isa = PBXGroup;
children = (
616A9CD12535D38200DB83CF /* UIKitHierarchyInspectorTests.swift */,
);
path = UIKitHierarchyInspection;
sourceTree = "<group>";
};
616CCE11250A181C009FED46 /* AutoInstrumentation */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3061,6 +3072,7 @@
6164AF2D252C9C51000D78C4 /* RUMResourcesScenarioTests.swift */,
612D8F8025AF1C74000E2E09 /* RUMScrubbingScenarioTests.swift */,
9EC2835926CFEE0B00FACF1C /* RUMMobileVitalsScenarioTests.swift */,
D2791EF827170A760046E07A /* RUMSwiftUIScenarioTests.swift */,
);
path = RUM;
sourceTree = "<group>";
Expand All @@ -3069,6 +3081,7 @@
isa = PBXGroup;
children = (
D249859B2727FF1D00B4F72D /* UIKit */,
D249859E2728042200B4F72D /* SwiftUI */,
);
path = Views;
sourceTree = "<group>";
Expand All @@ -3087,10 +3100,8 @@
61F3CDA925121FA100C816E5 /* Views */ = {
isa = PBXGroup;
children = (
616A9CD02535D36A00DB83CF /* UIKitHierarchyInspection */,
61F3CDAA25121FB500C816E5 /* UIViewControllerSwizzlerTests.swift */,
61F3CDAC25122C9200C816E5 /* UIKitRUMViewsHandlerTests.swift */,
611F82022563C66100CB9BDB /* UIKitRUMViewsPredicateTests.swift */,
D24985A427292F5600B4F72D /* UIKit */,
D24985A527292F7300B4F72D /* SwiftUI */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -3260,6 +3271,43 @@
path = UIKit;
sourceTree = "<group>";
};
D249859E2728042200B4F72D /* SwiftUI */ = {
isa = PBXGroup;
children = (
D249859F2728042200B4F72D /* SwiftUIViewModifier.swift */,
D24985A12728048B00B4F72D /* SwiftUIRUMViewsHandler.swift */,
);
path = SwiftUI;
sourceTree = "<group>";
};
D24985A427292F5600B4F72D /* UIKit */ = {
isa = PBXGroup;
children = (
61F3CDAA25121FB500C816E5 /* UIViewControllerSwizzlerTests.swift */,
61F3CDAC25122C9200C816E5 /* UIKitRUMViewsHandlerTests.swift */,
611F82022563C66100CB9BDB /* UIKitRUMViewsPredicateTests.swift */,
616A9CD12535D38200DB83CF /* UIKitHierarchyInspectorTests.swift */,
);
path = UIKit;
sourceTree = "<group>";
};
D24985A527292F7300B4F72D /* SwiftUI */ = {
isa = PBXGroup;
children = (
D24985A627292FCC00B4F72D /* SwiftUIRUMViewsHandlerTests.swift */,
);
path = SwiftUI;
sourceTree = "<group>";
};
D2791EF32716F16E0046E07A /* SwiftUIInstrumentation */ = {
isa = PBXGroup;
children = (
D2F5BB35271831C200BDE2A4 /* RUMSwiftUIInstrumentationScenario.storyboard */,
D2F5BB372718331800BDE2A4 /* SwiftUIRootViewController.swift */,
);
path = SwiftUIInstrumentation;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -3622,6 +3670,7 @@
files = (
61337032250F82AE00236D58 /* LoggingManualInstrumentationScenario.storyboard in Resources */,
612D8F6925AEE68F000E2E09 /* RUMScrubbingScenario.storyboard in Resources */,
D2F5BB36271831C200BDE2A4 /* RUMSwiftUIInstrumentationScenario.storyboard in Resources */,
611EA13C2580F77400BC0E56 /* TrackingConsentScenario.storyboard in Resources */,
61441C1124616DEC003D8BB8 /* LaunchScreen.storyboard in Resources */,
61337039250F852E00236D58 /* RUMManualInstrumentationScenario.storyboard in Resources */,
Expand Down Expand Up @@ -3816,6 +3865,9 @@
files = (
6112B10B25C849C000B37771 /* CrashReportingWithRUMIntegration.swift in Sources */,
61E917D12465423600E6C631 /* TracerConfiguration.swift in Sources */,
D24985A22728048B00B4F72D /* SwiftUIRUMViewsHandler.swift in Sources */,
D24985A327280FD100B4F72D /* SwiftUIViewModifier.swift in Sources */,
D2FCA239271D896E0020286F /* SwiftUIExtensions.swift in Sources */,
61C576C6256E65BD00295F7C /* DateCorrector.swift in Sources */,
61FC5F4525CC23C9006BB4DE /* RUMWithCrashContextIntegration.swift in Sources */,
61E909ED24A24DD3005EA2DE /* OTSpan.swift in Sources */,
Expand Down Expand Up @@ -4118,6 +4170,7 @@
6114FE3B25768AA90084E372 /* ConsentProviderTests.swift in Sources */,
61133C642423990D00786299 /* LoggerTests.swift in Sources */,
617B953D24BF4D8F00E6F443 /* RUMMonitorTests.swift in Sources */,
D244B3A3271EDACD003E1B29 /* SwiftUIExtensionsTests.swift in Sources */,
61F187FC25FA7DD60022CE9A /* InternalMonitoringFeatureTests.swift in Sources */,
61B5E42126DF85C7000B0A5F /* DDRUMMonitor+apiTests.m in Sources */,
61786F7724FCDE05009E6BAB /* RUMDebuggingTests.swift in Sources */,
Expand All @@ -4137,6 +4190,7 @@
61F3CDAB25121FB500C816E5 /* UIViewControllerSwizzlerTests.swift in Sources */,
9E989A4225F640D100235FC3 /* AppStateListenerTests.swift in Sources */,
617B954024BF4DB300E6F443 /* RUMApplicationScopeTests.swift in Sources */,
D24985A727292FCC00B4F72D /* SwiftUIRUMViewsHandlerTests.swift in Sources */,
61F2724925C943C500D54BF8 /* CrashReporterTests.swift in Sources */,
6172472725D673D7007085B3 /* CrashContextTests.swift in Sources */,
61BAD46A26415FCE001886CA /* OTSpanTests.swift in Sources */,
Expand Down Expand Up @@ -4179,6 +4233,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D2F5BB382718331800BDE2A4 /* SwiftUIRootViewController.swift in Sources */,
618DCFE124C766F500589570 /* SendRUMFixture2ViewController.swift in Sources */,
61441C982461A649003D8BB8 /* DebugTracingViewController.swift in Sources */,
61F9CA8025125C01000A5E61 /* RUMNCSScreen3ViewController.swift in Sources */,
Expand Down Expand Up @@ -4230,6 +4285,7 @@
files = (
61DC6D922539E3E300FFAA22 /* LoggingCommonAsserts.swift in Sources */,
61441C4024617013003D8BB8 /* IntegrationTests.swift in Sources */,
D2791EF927170A760046E07A /* RUMSwiftUIScenarioTests.swift in Sources */,
61163C4A252E03D6007DD5BF /* RUMModalViewsScenarioTests.swift in Sources */,
61B9ED212462089600C0DCFF /* TracingManualInstrumentationScenarioTests.swift in Sources */,
61B6811F25F0EA860015B4AF /* CrashReportingWithLoggingScenarioTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
value = "LoggingManualInstrumentationScenario"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "DD_TEST_SCENARIO_CLASS_NAME"
value = "RUMSwiftUIInstrumentationScenario"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "DD_TEST_SCENARIO_CLASS_NAME"
value = "RUMMobileVitalsScenario"
Expand Down
26 changes: 26 additions & 0 deletions Datadog/Example/Scenarios/RUM/RUMScenarios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,32 @@ final class RUMScrubbingScenario: TestScenario {
}
}

@available(iOS 13, *)
/// Scenario which presents `SwiftUI`-based hierarchy and navigates through
/// its views and view controllers.
final class RUMSwiftUIInstrumentationScenario: TestScenario {
static var storyboardName: String = "RUMSwiftUIInstrumentationScenario"

private class Predicate: UIKitRUMViewsPredicate {
let `default` = DefaultUIKitRUMViewsPredicate()

func rumView(for viewController: UIViewController) -> RUMView? {
if viewController is SwiftUIRootViewController {
return nil
}

return `default`.rumView(for: viewController)
}
}

func configureSDK(builder: Datadog.Configuration.Builder) {
_ = builder
.trackUIKitRUMViews(using: Predicate())
.enableLogging(false)
.enableTracing(false)
}
}

// MARK: - Helpers

private func rumResourceAttributesProvider(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y6W-OH-hqX">
<device id="retina6_1" orientation="portrait" appearance="dark"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--SwiftUI Root View Controller-->
<scene sceneID="s0d-6b-0kx">
<objects>
<viewController id="Y6W-OH-hqX" customClass="SwiftUIRootViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="139" y="125"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
Loading

0 comments on commit 8c28680

Please sign in to comment.