Skip to content

Commit

Permalink
RUM-4632 Remove SR config in WVT
Browse files Browse the repository at this point in the history
  • Loading branch information
maxep committed Jun 4, 2024
1 parent f2f5dc1 commit c3ef65b
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class WebLogIntegrationTests: XCTestCase {
hosts: [],
hostsSanitizer: HostsSanitizer(),
logsSampleRate: 100,
sessionReplayConfiguration: nil,
in: core
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class WebEventIntegrationTests: XCTestCase {
hosts: [],
hostsSanitizer: HostsSanitizer(),
logsSampleRate: 100,
sessionReplayConfiguration: nil,
in: core
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,10 @@ - (void)testDDWebViewTrackingAPI {
[DDWebViewTracking enableWithWebView:webView
hosts:[NSSet<NSString*> setWithArray:@[@"host1.com", @"host2.com"]]
logsSampleRate:100.0
with:nil];
];
[DDWebViewTracking disableWithWebView:webView];
}

- (void)testDDWebViewTrackingSessionReplayConfigurationAPI {
DDWebViewTrackingSessionReplayConfiguration *config = [[DDWebViewTrackingSessionReplayConfiguration alloc] init];
XCTAssertEqual(config.privacyLevel, DDPrivacyLevelMask);
config.privacyLevel = DDPrivacyLevelAllow;
XCTAssertEqual(config.privacyLevel, DDPrivacyLevelAllow);
config.privacyLevel = DDPrivacyLevelMaskUserInput;
XCTAssertEqual(config.privacyLevel, DDPrivacyLevelMaskUserInput);
}

#pragma clang diagnostic pop

@end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import Foundation

public let SessionReplayFeaturneName = "session-replay"

/// Available privacy levels for content masking in Session Replay.
public enum SessionReplayPrivacyLevel: String {
/// Record all content.
Expand Down Expand Up @@ -33,3 +35,7 @@ public protocol SessionReplayConfiguration {
/// The privacy level to use for the web view replay recording.
var privacyLevel: SessionReplayPrivacyLevel { get }
}

extension DatadogFeature where Self: SessionReplayConfiguration {
public static var name: String { SessionReplayFeaturneName }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Foundation
import DatadogInternal

internal class SessionReplayFeature: SessionReplayConfiguration, DatadogRemoteFeature {
static let name: String = "session-replay"

let requestBuilder: FeatureRequestBuilder
let messageReceiver: FeatureMessageReceiver
let performanceOverride: PerformancePresetOverride?
Expand Down
65 changes: 2 additions & 63 deletions DatadogWebViewTracking/Sources/ObjC/WebViewTracking+objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,6 @@ import WebKit
public final class objc_WebViewTracking: NSObject {
override private init() { }

/// The Session Replay configuration to capture records coming from the web view.
///
/// Setting the Session Replay configuration in `WebViewTracking` will enable transmitting replay data from
/// the Datadog Browser SDK installed in the web page. Datadog will then be able to combine the native
/// and web recordings in a single replay.
@objc(DDWebViewTrackingSessionReplayConfiguration)
@_spi(objc)
public final class SessionReplayConfiguration: NSObject {
/// Available privacy levels for content masking.
@objc(DDPrivacyLevel)
@_spi(objc)
public enum PrivacyLevel: Int {
/// Record all content.
case allow
/// Mask all content.
case mask
/// Mask input elements, but record all other content.
case maskUserInput

internal var toSwift: SessionReplayPrivacyLevel {
switch self {
case .allow: return .allow
case .mask: return .mask
case .maskUserInput: return .maskUserInput
}
}
}

/// The privacy level to use for the web view replay recording.
@objc public var privacyLevel: PrivacyLevel

/// Creates Webview Session Replay configuration.
///
/// - Parameters:
/// - privacyLevel: The way sensitive content (e.g. text) should be masked. Default: `.mask`.
@objc
override public init() {
self.privacyLevel = .mask
}

/// Creates Webview Session Replay configuration.
///
/// - Parameters:
/// - privacyLevel: The way sensitive content (e.g. text) should be masked. Default: `.mask`.
@objc
public init(
privacyLevel: PrivacyLevel
) {
self.privacyLevel = privacyLevel
}

internal var toSwift: WebViewTracking.SessionReplayConfiguration {
return .init(
privacyLevel: privacyLevel.toSwift
)
}
}

/// Enables SDK to correlate Datadog RUM events and Logs from the WebView with native RUM session.
///
/// If the content loaded in WebView uses Datadog Browser SDK (`v4.2.0+`) and matches specified
Expand All @@ -86,20 +28,17 @@ public final class objc_WebViewTracking: NSObject {
/// - hosts: A set of hosts instrumented with Browser SDK to capture Datadog events from.
/// - logsSampleRate: The sampling rate for logs coming from the WebView. Must be a value between `0` and `100`,
/// where 0 means no logs will be sent and 100 means all will be uploaded. Default: `100`.
/// - sessionReplayConfiguration: Session Replay configuration to enable linking Web and Native replays.
/// - core: Datadog SDK core to use for tracking.
@objc
public static func enable(
webView: WKWebView,
hosts: Set<String> = [],
logsSampleRate: Float = 100,
with configuration: SessionReplayConfiguration? = nil
logsSampleRate: Float = 100
) {
WebViewTracking.enable(
webView: webView,
hosts: hosts,
logsSampleRate: logsSampleRate,
sessionReplayConfiguration: configuration?.toSwift
logsSampleRate: logsSampleRate
)
}

Expand Down
28 changes: 3 additions & 25 deletions DatadogWebViewTracking/Sources/WebViewTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@ import WebKit
/// - Support users that have difficulty loading web pages on mobile devices
public enum WebViewTracking {
#if !os(tvOS)
/// The Session Replay configuration to capture records coming from the web view.
///
/// Setting the Session Replay configuration in `WebViewTracking` will enable transmitting replay data from
/// the Datadog Browser SDK installed in the web page. Datadog will then be able to combine the native
/// and web recordings in a single replay.
public struct SessionReplayConfiguration: DatadogInternal.SessionReplayConfiguration {
/// The privacy level to use for the web view replay recording.
public var privacyLevel: SessionReplayPrivacyLevel

/// Creates Webview Session Replay configuration.
///
/// - Parameters:
/// - privacyLevel: The way sensitive content (e.g. text) should be masked. Default: `.mask`.
public init(privacyLevel: SessionReplayPrivacyLevel = .mask) {
self.privacyLevel = privacyLevel
}
}

/// Enables SDK to correlate Datadog RUM events and Logs from the WebView with native RUM session.
///
/// If the content loaded in WebView uses Datadog Browser SDK (`v4.2.0+`) and matches specified
Expand All @@ -53,21 +35,18 @@ public enum WebViewTracking {
/// - hosts: A set of hosts instrumented with Browser SDK to capture Datadog events from.
/// - logsSampleRate: The sampling rate for logs coming from the WebView. Must be a value between `0` and `100`,
/// where 0 means no logs will be sent and 100 means all will be uploaded. Default: `100`.
/// - sessionReplayConfiguration: Session Replay configuration to enable linking Web and Native replays.
/// - core: Datadog SDK core to use for tracking.
public static func enable(
webView: WKWebView,
hosts: Set<String> = [],
logsSampleRate: Float = 100,
sessionReplayConfiguration: SessionReplayConfiguration? = nil,
in core: DatadogCoreProtocol = CoreRegistry.default
) {
enable(
tracking: webView.configuration.userContentController,
hosts: hosts,
hostsSanitizer: HostsSanitizer(),
logsSampleRate: logsSampleRate,
sessionReplayConfiguration: sessionReplayConfiguration,
in: core
)
}
Expand Down Expand Up @@ -95,7 +74,6 @@ public enum WebViewTracking {
hosts: Set<String>,
hostsSanitizer: HostsSanitizing,
logsSampleRate: Float,
sessionReplayConfiguration: SessionReplayConfiguration?,
in core: DatadogCoreProtocol
) {
let isTracking = controller.userScripts.contains { $0.source.starts(with: Self.jsCodePrefix) }
Expand Down Expand Up @@ -128,9 +106,9 @@ public enum WebViewTracking {
.map { return "\"\($0)\"" }
.joined(separator: ",")

let sessionReplay = sessionReplayConfiguration ?? core.feature(
named: "session-replay",
type: DatadogInternal.SessionReplayConfiguration.self
let sessionReplay = core.feature(
named: SessionReplayFeaturneName,
type: SessionReplayConfiguration.self
)

let privacyLevel = sessionReplay?.privacyLevel ?? .mask
Expand Down
19 changes: 9 additions & 10 deletions DatadogWebViewTracking/Tests/WebViewTrackingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class WebViewTrackingTests: XCTestCase {
hosts: [host],
hostsSanitizer: mockSanitizer,
logsSampleRate: 30,
sessionReplayConfiguration: nil,
in: PassthroughCoreMock()
)

Expand All @@ -49,11 +48,17 @@ class WebViewTrackingTests: XCTestCase {
}

func testItAddsUserScriptWithSessionReplay() throws {
struct SessionReplayFeature: DatadogFeature, SessionReplayConfiguration {
static let name = "session-replay"
let messageReceiver: FeatureMessageReceiver = NOPFeatureMessageReceiver()
let privacyLevel: SessionReplayPrivacyLevel
}

let mockSanitizer = HostsSanitizerMock()
let controller = DDUserContentController()

let host: String = .mockRandom()
let sessionReplayConfiguration = WebViewTracking.SessionReplayConfiguration(
let sr = SessionReplayFeature(
privacyLevel: .mockRandom()
)

Expand All @@ -62,8 +67,7 @@ class WebViewTrackingTests: XCTestCase {
hosts: [host],
hostsSanitizer: mockSanitizer,
logsSampleRate: 30,
sessionReplayConfiguration: sessionReplayConfiguration,
in: PassthroughCoreMock()
in: SingleFeatureCoreMock(feature: sr)
)

let script = try XCTUnwrap(controller.userScripts.last)
Expand All @@ -80,7 +84,7 @@ class WebViewTrackingTests: XCTestCase {
return '["records"]'
},
getPrivacyLevel() {
return '\(sessionReplayConfiguration.privacyLevel.rawValue)'
return '\(sr.privacyLevel.rawValue)'
}
}
""")
Expand All @@ -97,7 +101,6 @@ class WebViewTrackingTests: XCTestCase {
hosts: ["datadoghq.com"],
hostsSanitizer: mockSanitizer,
logsSampleRate: 30,
sessionReplayConfiguration: nil,
in: PassthroughCoreMock()
)

Expand Down Expand Up @@ -129,7 +132,6 @@ class WebViewTrackingTests: XCTestCase {
hosts: ["datadoghq.com"],
hostsSanitizer: mockSanitizer,
logsSampleRate: 100,
sessionReplayConfiguration: nil,
in: PassthroughCoreMock()
)
}
Expand Down Expand Up @@ -208,7 +210,6 @@ class WebViewTrackingTests: XCTestCase {
hosts: ["datadoghq.com"],
hostsSanitizer: HostsSanitizerMock(),
logsSampleRate: 100,
sessionReplayConfiguration: nil,
in: core
)

Expand Down Expand Up @@ -261,7 +262,6 @@ class WebViewTrackingTests: XCTestCase {
hosts: ["datadoghq.com"],
hostsSanitizer: HostsSanitizerMock(),
logsSampleRate: 100,
sessionReplayConfiguration: nil,
in: core
)

Expand Down Expand Up @@ -354,7 +354,6 @@ class WebViewTrackingTests: XCTestCase {
hosts: ["datadoghq.com"],
hostsSanitizer: HostsSanitizerMock(),
logsSampleRate: 100,
sessionReplayConfiguration: nil,
in: core
)

Expand Down
36 changes: 36 additions & 0 deletions IntegrationTests/IntegrationTests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@
61441C0024616DE9003D8BB8 /* Resources */,
D240687A27CF982B00C04F44 /* Embed Frameworks */,
5DAD8F2510CB09A5BA7723B9 /* [CP] Copy Pods Resources */,
5FC520EDF6AC52CE770441C8 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -848,6 +849,7 @@
61441C2724616F1D003D8BB8 /* Frameworks */,
61441C2824616F1D003D8BB8 /* Resources */,
7F6DA13A8C70117DE98BAFD7 /* [CP] Copy Pods Resources */,
FF0828D858AD2E214162EA0C /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -978,6 +980,23 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner iOS/Pods-Runner iOS-resources.sh\"\n";
showEnvVarsInLog = 0;
};
5FC520EDF6AC52CE770441C8 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner iOS/Pods-Runner iOS-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner iOS/Pods-Runner iOS-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner iOS/Pods-Runner iOS-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
7F6DA13A8C70117DE98BAFD7 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1017,6 +1036,23 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
FF0828D858AD2E214162EA0C /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner iOS-IntegrationScenarios/Pods-Runner iOS-IntegrationScenarios-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner iOS-IntegrationScenarios/Pods-Runner iOS-IntegrationScenarios-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner iOS-IntegrationScenarios/Pods-Runner iOS-IntegrationScenarios-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down

0 comments on commit c3ef65b

Please sign in to comment.