Skip to content

Commit

Permalink
Add 'trackWatchdogTerminations' config parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-saia-datadog committed Jan 30, 2025
1 parent e3f8f42 commit 7253fa6
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 8 deletions.
6 changes: 5 additions & 1 deletion packages/core/ios/Sources/DdSdkConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import DatadogRUM
- bundleLogsWithRum: Correlates logs with RUM.
- bundleLogsWithTraces: Correlates logs with traces.
- appHangThreshold: The threshold for non-fatal app hangs reporting in seconds.
- trackWatchdogTerminations: Whether the SDK should track application termination by the watchdog
*/
@objc(DdSdkConfiguration)
public class DdSdkConfiguration: NSObject {
Expand Down Expand Up @@ -70,6 +71,7 @@ public class DdSdkConfiguration: NSObject {
public var bundleLogsWithRum: Bool
public var bundleLogsWithTraces: Bool
public var appHangThreshold: Double? = nil
public var trackWatchdogTerminations: Bool

public init(
clientToken: String,
Expand Down Expand Up @@ -99,7 +101,8 @@ public class DdSdkConfiguration: NSObject {
resourceTracingSamplingRate: Double?,
bundleLogsWithRum: Bool,
bundleLogsWithTraces: Bool,
appHangThreshold: Double?
appHangThreshold: Double?,
trackWatchdogTerminations: Bool
) {
self.clientToken = clientToken
self.env = env
Expand Down Expand Up @@ -129,6 +132,7 @@ public class DdSdkConfiguration: NSObject {
self.bundleLogsWithRum = bundleLogsWithRum
self.bundleLogsWithTraces = bundleLogsWithTraces
self.appHangThreshold = appHangThreshold
self.trackWatchdogTerminations = trackWatchdogTerminations
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/ios/Sources/DdSdkNativeInitialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public class DdSdkNativeInitialization: NSObject {
trackBackgroundEvents: configuration.trackBackgroundEvents ?? false,
longTaskThreshold: longTaskThreshold,
appHangThreshold: configuration.appHangThreshold,
trackWatchdogTerminations: configuration.trackWatchdogTerminations,
vitalsUpdateFrequency: configuration.vitalsUpdateFrequency,
resourceEventMapper: { resourceEvent in
if resourceEvent.context?.contextInfo[InternalConfigurationAttributes.dropResource] != nil {
Expand Down
9 changes: 7 additions & 2 deletions packages/core/ios/Sources/RNDdSdkConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extension NSDictionary {
let bundleLogsWithRum = object(forKey: "bundleLogsWithRum") as? Bool
let bundleLogsWithTraces = object(forKey: "bundleLogsWithTraces") as? Bool
let appHangThreshold = object(forKey: "appHangThreshold") as? Double
let trackWatchdogTerminations = object(forKey: "trackWatchdogTerminations") as? Bool

return DdSdkConfiguration(
clientToken: (clientToken != nil) ? clientToken! : String(),
Expand Down Expand Up @@ -69,7 +70,8 @@ extension NSDictionary {
resourceTracingSamplingRate: resourceTracingSamplingRate,
bundleLogsWithRum: bundleLogsWithRum ?? DefaultConfiguration.bundleLogsWithRum,
bundleLogsWithTraces: bundleLogsWithTraces ?? DefaultConfiguration.bundleLogsWithTraces,
appHangThreshold: appHangThreshold
appHangThreshold: appHangThreshold,
trackWatchdogTerminations: trackWatchdogTerminations ?? DefaultConfiguration.trackWatchdogTerminations
)
}

Expand Down Expand Up @@ -199,6 +201,7 @@ internal struct DefaultConfiguration {
static let trackBackgroundEvents = false
static let bundleLogsWithRum = true
static let bundleLogsWithTraces = true
static let trackWatchdogTerminations = false
}

extension Dictionary where Key == String, Value == AnyObject {
Expand Down Expand Up @@ -234,6 +237,7 @@ extension Dictionary where Key == String, Value == AnyObject {
let bundleLogsWithRum = configuration["bundleLogsWithRum"] as? Bool
let bundleLogsWithTraces = configuration["bundleLogsWithTraces"] as? Bool
let appHangThreshold = configuration["appHangThreshold"] as? Double
let trackWatchdogTerminations = configuration["trackWatchdogTerminations"] as? Bool

return DdSdkConfiguration(
clientToken: clientToken ?? String(),
Expand Down Expand Up @@ -266,7 +270,8 @@ extension Dictionary where Key == String, Value == AnyObject {
resourceTracingSamplingRate: resourceTracingSamplingRate ?? DefaultConfiguration.resourceTracingSamplingRate,
bundleLogsWithRum: bundleLogsWithRum ?? DefaultConfiguration.bundleLogsWithRum,
bundleLogsWithTraces: bundleLogsWithTraces ?? DefaultConfiguration.bundleLogsWithTraces,
appHangThreshold: appHangThreshold
appHangThreshold: appHangThreshold,
trackWatchdogTerminations: trackWatchdogTerminations ?? DefaultConfiguration.trackWatchdogTerminations
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions packages/core/ios/Tests/DdSdkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,8 @@ extension DdSdkConfiguration {
resourceTracingSamplingRate: Double? = nil,
bundleLogsWithRum: Bool = true,
bundleLogsWithTraces: Bool = true,
appHangThreshold: Double? = nil
appHangThreshold: Double? = nil,
trackWatchdogTerminations: Bool = false
) -> DdSdkConfiguration {
DdSdkConfiguration(
clientToken: clientToken as String,
Expand Down Expand Up @@ -1021,7 +1022,8 @@ extension DdSdkConfiguration {
resourceTracingSamplingRate: resourceTracingSamplingRate,
bundleLogsWithRum: bundleLogsWithRum,
bundleLogsWithTraces: bundleLogsWithTraces,
appHangThreshold: appHangThreshold
appHangThreshold: appHangThreshold,
trackWatchdogTerminations: trackWatchdogTerminations
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/DdSdkReactNative.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ export class DdSdkReactNative {
configuration.bundleLogsWithTraces,
configuration.trackNonFatalAnrs,
configuration.appHangThreshold,
configuration.resourceTracingSamplingRate
configuration.resourceTracingSamplingRate,
configuration.trackWatchdogTerminations
);
};

Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/DdSdkReactNativeConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export const DEFAULTS = {
getCustomEndpoints: () => ({}),
bundleLogsWithRum: true,
bundleLogsWithTraces: true,
useAccessibilityLabel: true
useAccessibilityLabel: true,
trackWatchdogTerminations: false
};

/**
Expand Down Expand Up @@ -291,6 +292,12 @@ export class DdSdkReactNativeConfiguration {
*/
public appHangThreshold?: number;

/**
* Determines whether the SDK should track application termination by the watchdog on iOS. Default: `false`.
*/
public trackWatchdogTerminations: boolean =
DEFAULTS.trackWatchdogTerminations;

/**
* Specifies a custom prop to name RUM actions on elements having an `onPress` prop.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('DdSdkReactNativeConfiguration', () => {
"trackFrustrations": true,
"trackInteractions": false,
"trackResources": false,
"trackWatchdogTerminations": false,
"trackingConsent": "granted",
"uploadFrequency": "AVERAGE",
"useAccessibilityLabel": true,
Expand Down Expand Up @@ -166,6 +167,7 @@ describe('DdSdkReactNativeConfiguration', () => {
"trackFrustrations": true,
"trackInteractions": true,
"trackResources": true,
"trackWatchdogTerminations": false,
"trackingConsent": "pending",
"uploadFrequency": "FREQUENT",
"useAccessibilityLabel": true,
Expand Down Expand Up @@ -240,6 +242,7 @@ describe('DdSdkReactNativeConfiguration', () => {
"trackFrustrations": false,
"trackInteractions": false,
"trackResources": false,
"trackWatchdogTerminations": false,
"trackingConsent": "granted",
"uploadFrequency": "AVERAGE",
"useAccessibilityLabel": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe('DatadogProvider', () => {
"trackBackgroundEvents": false,
"trackFrustrations": true,
"trackNonFatalAnrs": undefined,
"trackWatchdogTerminations": false,
"trackingConsent": "granted",
"uploadFrequency": "AVERAGE",
"verbosity": undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe('FileBasedConfiguration', () => {
"trackFrustrations": true,
"trackInteractions": true,
"trackResources": true,
"trackWatchdogTerminations": false,
"trackingConsent": "not_granted",
"uploadFrequency": "AVERAGE",
"useAccessibilityLabel": true,
Expand Down Expand Up @@ -140,6 +141,7 @@ describe('FileBasedConfiguration', () => {
"trackFrustrations": true,
"trackInteractions": false,
"trackResources": false,
"trackWatchdogTerminations": false,
"trackingConsent": "granted",
"uploadFrequency": "AVERAGE",
"useAccessibilityLabel": true,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export class DdSdkConfiguration {
readonly bundleLogsWithTraces: boolean,
readonly trackNonFatalAnrs: boolean | undefined,
readonly appHangThreshold: number | undefined,
readonly resourceTracingSamplingRate: number | undefined
readonly resourceTracingSamplingRate: number | undefined,
readonly trackWatchdogTerminations: boolean | undefined
) {}
}

Expand Down

0 comments on commit 7253fa6

Please sign in to comment.