Skip to content

Commit

Permalink
Add isInitialized and stopInstance methods to ObjC API
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnm committed Apr 29, 2024
1 parent 0134ce1 commit 169d46f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [FEATURE] `DatadogTrace` now supports head-based sampling. See [#1794][]
- [FEATURE] Support WebView recording in Session Replay. See [#1776][]
- [IMPROVEMENT] Add `isInitialized` and `stopInstance` methods to ObjC API. See [#1800][]
- [IMPROVEMENT] Add `addUserExtraInfo` method to ObjC API. See [#1799][]

# 2.10.0 / 23-04-2024
Expand Down
45 changes: 44 additions & 1 deletion DatadogCore/Tests/DatadogObjc/DDDatadogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DDDatadogTests: XCTestCase {
super.tearDown()
}

// MARK: - Initializing with configuration
// MARK: - SDK initialization / stop lifecycle

func testItForwardsInitializationToSwift() throws {
let config = DDConfiguration(
Expand All @@ -50,6 +50,49 @@ class DDDatadogTests: XCTestCase {
XCTAssertNil(CoreRegistry.default.get(feature: LogsFeature.self))
}

func testItReflectsInitializationStatus() throws {
let config = DDConfiguration(
clientToken: "abcefghi",
env: "tests"
)

config.bundle = .mockWith(CFBundleExecutable: "app-name")
XCTAssertFalse(DDDatadog.isInitialized())

DDDatadog.initialize(
configuration: config,
trackingConsent: randomConsent().objc
)

XCTAssertTrue(DDDatadog.isInitialized())

Datadog.flushAndDeinitialize()

XCTAssertNil(CoreRegistry.default.get(feature: LogsFeature.self))
}

func testItForwardsStopInstanceToSwift() throws {
let config = DDConfiguration(
clientToken: "abcefghi",
env: "tests"
)

config.bundle = .mockWith(CFBundleExecutable: "app-name")

DDDatadog.initialize(
configuration: config,
trackingConsent: randomConsent().objc
)

XCTAssertTrue(Datadog.isInitialized())

DDDatadog.stopInstance()

XCTAssertFalse(Datadog.isInitialized())

XCTAssertNil(CoreRegistry.default.get(feature: LogsFeature.self))
}

// MARK: - Changing Tracking Consent

func testItForwardsTrackingConsentToSwift() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ - (void)testDDDatadog {

[DDDatadog initializeWithConfiguration:configuration trackingConsent:[DDTrackingConsent notGranted]];

[DDDatadog isInitialized];

DDSDKVerbosityLevel verbosity = [DDDatadog verbosityLevel];
[DDDatadog setVerbosityLevel:verbosity];

Expand All @@ -37,7 +39,7 @@ - (void)testDDDatadog {
[DDDatadog setTrackingConsentWithConsent:[DDTrackingConsent notGranted]];

[DDDatadog clearAllData];
[DDDatadog flushAndDeinitialize];
[DDDatadog stopInstance];
}

#pragma clang diagnostic pop
Expand Down
10 changes: 10 additions & 0 deletions DatadogObjc/Sources/Datadog+objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public class DDDatadog: NSObject {
Datadog.set(trackingConsent: consent.sdkConsent)
}

@objc
public static func isInitialized() -> Bool {
return Datadog.isInitialized()
}

@objc
public static func stopInstance() {
Datadog.stopInstance()
}

@objc
public static func clearAllData() {
Datadog.clearAllData()
Expand Down
2 changes: 2 additions & 0 deletions api-surface-objc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class DDDatadog: NSObject
public static func setUserInfo(id: String? = nil, name: String? = nil, email: String? = nil, extraInfo: [String: Any] = [:])
public static func addUserExtraInfo(_ extraInfo: [String: Any])
public static func setTrackingConsent(consent: DDTrackingConsent)
public static func isInitialized() -> Bool
public static func stopInstance()
public static func clearAllData()
public class DDSite: NSObject
public static func us1() -> DDSite
Expand Down

0 comments on commit 169d46f

Please sign in to comment.