-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add internal testing tools package #587
Merged
louiszawadzki
merged 13 commits into
develop
from
louiszawadzki/rum-2343/create-testing-package
Jan 26, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d8998bb
Add internal testing tools package
da677eb
Add wrapper to allow setting core instance
27f0664
Copy over Core Proxy from POC
c39bb62
Wrap core in internal testing
86f7ac8
Add feature listeners and expose core instance on Android
939cfdc
Proxy features after being enabled on Android
be1b0e7
Add iOS tests
7f8fbd5
Add android tests for internal testing tools
c81fd18
Refactor Android to wrap core SDK
e0230b4
Simplify core init listener
37f4582
Improve SDK Wrapper
4d3b2d2
Clean internal testing android code
66855bb
Prevent build failure for RN 0.73
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
|
||
import DatadogCore | ||
import DatadogRUM | ||
import DatadogLogs | ||
import DatadogTrace | ||
import DatadogCrashReporting | ||
import DatadogWebViewTracking | ||
import DatadogInternal | ||
import Foundation | ||
|
||
public typealias OnCoreInitializedListener = (DatadogCoreProtocol) -> Void | ||
|
||
/// Wrapper around the Datadog SDK. Use DatadogSDKWrapper.shared to access the instance. | ||
public class DatadogSDKWrapper { | ||
// Singleton | ||
public static var shared = DatadogSDKWrapper() | ||
|
||
private init() {} | ||
|
||
// Initialization callbacks | ||
internal var onCoreInitializedListeners: [OnCoreInitializedListener] = [] | ||
|
||
public func addOnCoreInitializedListener(listener:@escaping OnCoreInitializedListener) { | ||
onCoreInitializedListeners.append(listener) | ||
} | ||
|
||
// Core instance | ||
private var coreInstance: DatadogCoreProtocol? = nil | ||
|
||
/// This is intended for internal testing only. | ||
public func setCoreInstance(core: DatadogCoreProtocol?) { | ||
self.coreInstance = core | ||
} | ||
|
||
/// This is not supposed to be used in the SDK itself, rather by other SDKs like Session Replay. | ||
public func getCoreInstance() -> DatadogCoreProtocol? { | ||
return coreInstance | ||
} | ||
|
||
// SDK Wrapper | ||
internal func initialize( | ||
with configuration: Datadog.Configuration, | ||
trackingConsent: TrackingConsent | ||
) -> Void { | ||
let core = Datadog.initialize(with: configuration, trackingConsent: trackingConsent) | ||
setCoreInstance(core: core) | ||
for listener in onCoreInitializedListeners { | ||
listener(core) | ||
} | ||
} | ||
|
||
internal func isInitialized() -> Bool { | ||
return Datadog.isInitialized() | ||
} | ||
|
||
internal func enableRUM(with configuration: RUM.Configuration) { | ||
if let core = coreInstance { | ||
RUM.enable(with: configuration, in: core) | ||
} else { | ||
consolePrint("Core instance was not found when initializing RUM.") | ||
} | ||
} | ||
|
||
internal func enableLogs(with configuration: Logs.Configuration) { | ||
if let core = coreInstance { | ||
Logs.enable(with: configuration, in: core) | ||
} else { | ||
consolePrint("Core instance was not found when initializing Logs.") | ||
} | ||
} | ||
|
||
internal func enableTrace(with configuration: Trace.Configuration) { | ||
if let core = coreInstance { | ||
Trace.enable(with: configuration, in: core) | ||
} else { | ||
consolePrint("Core instance was not found when initializing Trace.") | ||
} | ||
} | ||
|
||
internal func enableCrashReporting() { | ||
if let core = coreInstance { | ||
CrashReporting.enable(in: core) | ||
} else { | ||
consolePrint("Core instance was not found when initializing CrashReporting.") | ||
} | ||
} | ||
|
||
internal func createLogger() -> LoggerProtocol { | ||
if let core = coreInstance { | ||
return Logger.create(with: Logger.Configuration(networkInfoEnabled: true, consoleLogFormat: .short), in: core) | ||
} else { | ||
consolePrint("Core instance was not found when creating Logger.") | ||
return Logger.create(with: Logger.Configuration(networkInfoEnabled: true, consoleLogFormat: .short)) | ||
} | ||
} | ||
|
||
// Telemetry | ||
internal func telemetryDebug(id: String, message: String) { | ||
return Datadog._internal.telemetry.debug(id: id, message: message) | ||
} | ||
|
||
internal func telemetryError(id: String, message: String, kind: String?, stack: String?) { | ||
return Datadog._internal.telemetry.error(id: id, message: message, kind: kind, stack: stack) | ||
} | ||
|
||
internal func overrideTelemetryConfiguration( | ||
initializationType: String? = nil, | ||
reactNativeVersion: String? = nil, | ||
reactVersion: String? = nil, | ||
trackCrossPlatformLongTasks: Bool? = nil, | ||
trackErrors: Bool? = nil, | ||
trackInteractions: Bool? = nil, | ||
trackLongTask: Bool? = nil, | ||
trackNativeErrors: Bool? = nil, | ||
trackNativeLongTasks: Bool? = nil, | ||
trackNetworkRequests: Bool? = nil | ||
) { | ||
coreInstance?.telemetry.configuration( | ||
initializationType: initializationType, | ||
reactNativeVersion: reactNativeVersion, | ||
reactVersion: reactVersion, | ||
trackCrossPlatformLongTasks: trackCrossPlatformLongTasks, | ||
trackErrors: trackErrors, | ||
trackInteractions: trackInteractions, | ||
trackLongTask: trackLongTask, | ||
trackNativeErrors: trackNativeErrors, | ||
trackNativeLongTasks: trackNativeLongTasks, | ||
trackNetworkRequests: trackNetworkRequests | ||
) | ||
} | ||
|
||
// Webview | ||
private var webviewMessageEmitter: InternalExtension<WebViewTracking>.AbstractMessageEmitter? | ||
|
||
internal func enableWebviewTracking() { | ||
if let core = coreInstance { | ||
webviewMessageEmitter = WebViewTracking._internal.messageEmitter(in: core) | ||
} else { | ||
consolePrint("Core instance was not found when initializing Webview tracking.") | ||
} | ||
} | ||
|
||
internal func sendWebviewMessage(body: NSString) throws { | ||
try self.webviewMessageEmitter?.send(body: body) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't want to make it available to the customers, we need to make this class
internal
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I make it
internal
, I cannot import it in the internal testing module.Is it possible to still import it?
And I think it can be ok to leave it available to customers. Most of them won't do anything, and maybe that can make things a little easier for some customers with hybrid applications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it public then, but if it used only for the tests, nothing in the name reflects that the intended usage is for the tests only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will also be used in Session Replay to make sure we use the same core for all features - it's one of the next tasks on the topic.
When we'll split the RN SDK in core/RUM/Logs/Trace this will also be used to get the core in the feature packages.
Let me know if you think we should still change the name to something more explicit here.