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 Oct 11, 2024
1 parent 226434b commit c598321
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 6 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
3 changes: 2 additions & 1 deletion packages/core/src/DdSdkReactNative.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ export class DdSdkReactNative {
configuration.bundleLogsWithRum,
configuration.bundleLogsWithTraces,
configuration.trackNonFatalAnrs,
configuration.appHangThreshold
configuration.appHangThreshold,
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 @@ -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 @@ -58,7 +58,8 @@ export class DdSdkConfiguration {
readonly bundleLogsWithRum: boolean,
readonly bundleLogsWithTraces: boolean,
readonly trackNonFatalAnrs: boolean | undefined,
readonly appHangThreshold: number | undefined
readonly appHangThreshold: number | undefined,
readonly trackWatchdogTerminations: boolean | undefined
) {}
}

Expand Down

0 comments on commit c598321

Please sign in to comment.