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
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@

@property (nonatomic, strong) DdInternalTestingImplementation* ddInternalTestingImplementation;

+ (void)enableFromNative;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ + (BOOL)requiresMainQueueSetup {
return NO;
}

+ (void)enableFromNative {
DdInternalTestingNativeInitialization *internalTesting = [[DdInternalTestingNativeInitialization alloc] init];
[internalTesting enableFromNative];
}

- (void)clearData:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
[self.ddInternalTestingImplementation clearDataWithResolve:resolve reject:reject];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import DatadogInternal

@objc
public class DdInternalTestingImplementation: NSObject {
private var coreProxy: DatadogCoreProxy? = nil

@objc
public func clearData(resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
self.coreProxy?.waitAndDeleteEvents(ofFeature: "rum")
self.coreProxy?.waitAndDeleteEvents(ofFeature: "logging")
self.coreProxy?.waitAndDeleteEvents(ofFeature: "tracing")
self.coreProxy?.waitAndDeleteEvents(ofFeature: "session-replay")
let coreProxy = (DatadogSDKWrapper.shared.getCoreInstance() as! DatadogCoreProxy)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw another potential solution to create a singleton to hold the proxied core instance, but I felt there was no point in adding another singleton to the one we already had that will return the proxied core given enable was called before.

coreProxy.waitAndDeleteEvents(ofFeature: "rum")
coreProxy.waitAndDeleteEvents(ofFeature: "logging")
coreProxy.waitAndDeleteEvents(ofFeature: "tracing")
coreProxy.waitAndDeleteEvents(ofFeature: "session-replay")

resolve(nil)
}

@objc
public func getAllEvents(feature: String, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
do {
let events = coreProxy?.waitAndReturnEventsData(ofFeature: feature) ?? []
let coreProxy = (DatadogSDKWrapper.shared.getCoreInstance() as! DatadogCoreProxy)
let events = coreProxy.waitAndReturnEventsData(ofFeature: feature)
let data = try JSONSerialization.data(withJSONObject: events, options: .prettyPrinted)
resolve(String(data: data, encoding: String.Encoding.utf8) ?? "")
} catch {
Expand All @@ -42,8 +42,18 @@ public class DdInternalTestingImplementation: NSObject {
DatadogSDKWrapper.shared.addOnCoreInitializedListener(listener: {core in
let proxiedCore = DatadogCoreProxy(core: core)
DatadogSDKWrapper.shared.setCoreInstance(core: proxiedCore)
self.coreProxy = proxiedCore
})
resolve(nil)
}
}

// This is to be used for native initialization
public class DdInternalTestingNativeInitialization: NSObject {
@objc
public func enableFromNative() -> Void {
DatadogSDKWrapper.shared.addOnCoreInitializedListener(listener: {core in
let proxiedCore = DatadogCoreProxy(core: core)
DatadogSDKWrapper.shared.setCoreInstance(core: proxiedCore)
})
}
}