Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Datadog/Datadog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
116506182E9535A500FD815C /* WatchdogTerminationMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116506162E9535A500FD815C /* WatchdogTerminationMocks.swift */; };
116F84062CFDD06700705755 /* SampleRateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116F84052CFDD06700705755 /* SampleRateTests.swift */; };
116F84072CFDD06700705755 /* SampleRateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116F84052CFDD06700705755 /* SampleRateTests.swift */; };
117ADDD92EAA8A90008BD9D8 /* StartupTypeHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 117ADDD82EAA8A90008BD9D8 /* StartupTypeHandlerTests.swift */; };
117ADDDA2EAA8A90008BD9D8 /* StartupTypeHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 117ADDD82EAA8A90008BD9D8 /* StartupTypeHandlerTests.swift */; };
117E52222D91A61A00A8E930 /* DatadogSessionReplay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6133D1F52A6ED9E100384BEF /* DatadogSessionReplay.framework */; };
118246782D90416A00E3D16F /* DirectoriesStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118246772D90416A00E3D16F /* DirectoriesStub.swift */; };
1182467A2D90416A00E3D16F /* DirectoriesStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 118246772D90416A00E3D16F /* DirectoriesStub.swift */; };
Expand Down Expand Up @@ -2467,6 +2469,7 @@
116506132E95339B00FD815C /* AppStateManagerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStateManagerMock.swift; sourceTree = "<group>"; };
116506162E9535A500FD815C /* WatchdogTerminationMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchdogTerminationMocks.swift; sourceTree = "<group>"; };
116F84052CFDD06700705755 /* SampleRateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleRateTests.swift; sourceTree = "<group>"; };
117ADDD82EAA8A90008BD9D8 /* StartupTypeHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartupTypeHandlerTests.swift; sourceTree = "<group>"; };
118246772D90416A00E3D16F /* DirectoriesStub.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoriesStub.swift; sourceTree = "<group>"; };
118248612D908BEF00E3D16F /* DatadogIntegrationTests iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "DatadogIntegrationTests iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
118249122D9094EA00E3D16F /* DatadogIntegrationTests tvOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "DatadogIntegrationTests tvOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -5465,10 +5468,11 @@
6141CE652806B3F200EBB879 /* Utils */ = {
isa = PBXGroup;
children = (
61C1510C25AC8C1B00362D4B /* ViewIdentifierTests.swift */,
619F1A262DEF0B3F003954BD /* LaunchReasonResolverTests.swift */,
61A614E9276B9D4C00A06CE7 /* RUMOffViewEventsHandlingRuleTests.swift */,
117ADDD82EAA8A90008BD9D8 /* StartupTypeHandlerTests.swift */,
D253EE982B98B3690010B589 /* ViewCacheTests.swift */,
619F1A262DEF0B3F003954BD /* LaunchReasonResolverTests.swift */,
61C1510C25AC8C1B00362D4B /* ViewIdentifierTests.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -9787,6 +9791,7 @@
96F70D582DDE253F00D3736B /* SwiftUIComponentDetectorTests.swift in Sources */,
D23F8EBE29DDCD38001CFAE8 /* WebViewEventReceiverTests.swift in Sources */,
D23F8EBF29DDCD38001CFAE8 /* URLSessionRUMResourcesHandlerTests.swift in Sources */,
117ADDDA2EAA8A90008BD9D8 /* StartupTypeHandlerTests.swift in Sources */,
D23F8EC029DDCD38001CFAE8 /* RUMEventSanitizerTests.swift in Sources */,
D253EE9C2B98B37C0010B589 /* ViewCacheTests.swift in Sources */,
6176C1732ABDBA2E00131A70 /* MonitorTests.swift in Sources */,
Expand Down Expand Up @@ -10273,6 +10278,7 @@
D29A9FA429DDB483005C54A4 /* WebViewEventReceiverTests.swift in Sources */,
61536AC02DF21A0500B06D7D /* LaunchReasonResolverTests.swift in Sources */,
D29A9F9A29DDB483005C54A4 /* URLSessionRUMResourcesHandlerTests.swift in Sources */,
117ADDD92EAA8A90008BD9D8 /* StartupTypeHandlerTests.swift in Sources */,
D29A9FA229DDB483005C54A4 /* RUMEventSanitizerTests.swift in Sources */,
D253EE9B2B98B37B0010B589 /* ViewCacheTests.swift in Sources */,
6176C1722ABDBA2E00131A70 /* MonitorTests.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions DatadogCore/Tests/Objc/DDRUMMonitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class DDRUMMonitorTests: XCTestCase {
objcRUMMonitor.stopView(viewController: mockView, attributes: ["event-attribute2": "foo2"])
objcRUMMonitor.startView(key: "view2", name: "SecondView", attributes: ["event-attribute1": "bar1"])
objcRUMMonitor.addViewLoadingTime(overwrite: true)
objcRUMMonitor.reportAppFullyDisplayed()
objcRUMMonitor.stopView(key: "view2", attributes: ["event-attribute2": "bar2"])

let rumEventMatchers = try core.waitAndReturnRUMEventMatchers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ - (void)testDDRUMMonitorAPI {
DDRUMMonitor *monitor = [DDRUMMonitor shared];
[monitor currentSessionIDWithCompletion:^(NSString * _Nullable sessionID) {}];
[monitor stopSession];
[monitor reportAppFullyDisplayed];

[monitor addViewAttributeForKey:@"key" value: @"value"];
[monitor addViewAttributes:@{@"string": @"value", @"integer": @1, @"boolean": @true}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ internal protocol AppStateManaging {
/// Builds the current app state.
func currentAppStateInfo(completion: @escaping (AppStateInfo) -> Void)
/// Builds the current app state and stores it in the data store.
func storeCurrentAppState() throws
func storeCurrentAppState()
}

/// Manages the app state changes observed during application lifecycle events such as application start, resume and termination.
internal final class AppStateManager: AppStateManaging {
enum ErrorMessage: String {
case failedToStoreAppState = "Failed to store App State information"
}

let featureScope: FeatureScope

/// The last app state observed during application lifecycle events.
Expand Down Expand Up @@ -57,13 +53,7 @@ internal final class AppStateManager: AppStateManaging {
private func start() {
self.readAppState { [weak self] in
self?.previousAppStateInfo = $0

do {
try self?.storeCurrentAppState()
} catch {
DD.logger.error(ErrorMessage.failedToStoreAppState.rawValue, error: error)
self?.featureScope.telemetry.error(ErrorMessage.failedToStoreAppState.rawValue, error: error)
}
self?.storeCurrentAppState()
}
}

Expand Down Expand Up @@ -136,7 +126,7 @@ internal final class AppStateManager: AppStateManaging {
}

/// Builds the current app state and stores it in the data store.
func storeCurrentAppState() throws {
func storeCurrentAppState() {
currentAppStateInfo { [self] appState in
featureScope.rumDataStore.setValue(appState, forKey: .appStateKey)
}
Expand Down
4 changes: 4 additions & 0 deletions DatadogRUM/Sources/RUM+objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ public class objc_RUMMonitor: NSObject {
swiftRUMMonitor.stopSession()
}

public func reportAppFullyDisplayed() {
swiftRUMMonitor.reportAppFullyDisplayed()
}

public func addViewAttribute(forKey key: String, value: Any) {
swiftRUMMonitor.addViewAttribute(forKey: key, value: AnyEncodable(value))
}
Expand Down
24 changes: 13 additions & 11 deletions DatadogRUM/Sources/RUMMonitor/Monitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,8 @@ extension Monitor: RUMMonitorProtocol {
process(command: RUMStopSessionCommand(time: dateProvider.now))
}

// MARK: - custom timings

func addTiming(name: String) {
process(
command: RUMAddViewTimingCommand(
time: dateProvider.now,
globalAttributes: self.attributes,
attributes: [:],
timingName: name
)
)
func reportAppFullyDisplayed() {
process(command: RUMTimeToFullDisplayCommand(time: dateProvider.now))
}

// MARK: - errors
Expand Down Expand Up @@ -664,6 +655,17 @@ extension Monitor: RUMMonitorViewProtocol {
)
}

func addTiming(name: String) {
process(
command: RUMAddViewTimingCommand(
time: dateProvider.now,
globalAttributes: self.attributes,
attributes: [:],
timingName: name
)
)
}

func addViewLoadingTime(overwrite: Bool) {
process(
command: RUMAddViewLoadingTime(
Expand Down
13 changes: 13 additions & 0 deletions DatadogRUM/Sources/RUMMonitor/RUMCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ internal struct RUMTimeToInitialDisplayCommand: RUMCommand {
let missedEventType: SessionEndedMetric.MissedEventType? = nil
}

internal struct RUMTimeToFullDisplayCommand: RUMCommand {
var time: Date
var globalAttributes: [AttributeKey: AttributeValue] = [:]
var attributes: [AttributeKey: AttributeValue] = [:]
var canStartApplicationLaunchView = false
var canStartBackgroundView = false
let shouldRestartLastViewAfterSessionExpiration = false
let shouldRestartLastViewAfterSessionStop = false
let canStartBackgroundViewAfterSessionStop = false
let isUserInteraction = false
let missedEventType: SessionEndedMetric.MissedEventType? = nil
}

// MARK: - RUM View related commands

internal struct RUMAddViewAttributesCommand: RUMCommand {
Expand Down
Loading