forked from DataDog/dd-sdk-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRUMScopeDependencies.swift
118 lines (108 loc) · 4.7 KB
/
RUMScopeDependencies.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* 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 2019-Present Datadog, Inc.
*/
import Foundation
import DatadogInternal
internal struct VitalsReaders {
let frequency: TimeInterval
var cpu: SamplingBasedVitalReader
var memory: SamplingBasedVitalReader
var refreshRate: ContinuousVitalReader
init(
frequency: TimeInterval,
telemetry: Telemetry = NOPTelemetry()
) {
self.frequency = frequency
self.cpu = VitalCPUReader(notificationCenter: .default, telemetry: telemetry)
self.memory = VitalMemoryReader()
self.refreshRate = VitalRefreshRateReader(notificationCenter: .default)
}
}
/// Dependency container for injecting components to `RUMScopes` hierarchy.
internal struct RUMScopeDependencies {
/// The RUM feature scope to interact with core.
let featureScope: FeatureScope
let rumApplicationID: String
let sessionSampler: Sampler
let trackBackgroundEvents: Bool
let trackFrustrations: Bool
let firstPartyHosts: FirstPartyHosts?
let eventBuilder: RUMEventBuilder
let rumUUIDGenerator: RUMUUIDGenerator
let backtraceReporter: BacktraceReporting?
/// Integration with CIApp tests. It contains the CIApp test context when active.
let ciTest: RUMCITest?
let syntheticsTest: RUMSyntheticsTest?
let vitalsReaders: VitalsReaders?
let onSessionStart: RUM.SessionListener?
let viewCache: ViewCache
/// The RUM context necessary for tracking fatal errors like Crashes or fatal App Hangs.
let fatalErrorContext: FatalErrorContextNotifying
/// Telemetry endpoint.
let telemetry: Telemetry
let sessionType: RUMSessionType
let sessionEndedMetric: SessionEndedMetricController
let watchdogTermination: WatchdogTerminationMonitor?
/// A factory function that creates `ViewEndedMetricController` for each new view started.
let viewEndedMetricFactory: () -> ViewEndedMetricController
/// A factory function that creates a `TNSMetric` for the given view start date.
/// - Parameters:
/// - Date: The time when the view becomes visible (device time, no NTP offset).
/// - String: The name of the view.
let networkSettledMetricFactory: (Date, String) -> TNSMetricTracking
/// A factory function that creates a `INVMetric` when session starts.
let interactionToNextViewMetricFactory: () -> INVMetricTracking?
init(
featureScope: FeatureScope,
rumApplicationID: String,
sessionSampler: Sampler,
trackBackgroundEvents: Bool,
trackFrustrations: Bool,
firstPartyHosts: FirstPartyHosts?,
eventBuilder: RUMEventBuilder,
rumUUIDGenerator: RUMUUIDGenerator,
backtraceReporter: BacktraceReporting?,
ciTest: RUMCITest?,
syntheticsTest: RUMSyntheticsTest?,
vitalsReaders: VitalsReaders?,
onSessionStart: RUM.SessionListener?,
viewCache: ViewCache,
fatalErrorContext: FatalErrorContextNotifying,
sessionEndedMetric: SessionEndedMetricController,
viewEndedMetricFactory: @escaping () -> ViewEndedMetricController,
watchdogTermination: WatchdogTerminationMonitor?,
networkSettledMetricFactory: @escaping (Date, String) -> TNSMetricTracking,
interactionToNextViewMetricFactory: @escaping () -> INVMetricTracking?
) {
self.featureScope = featureScope
self.rumApplicationID = rumApplicationID
self.sessionSampler = sessionSampler
self.trackBackgroundEvents = trackBackgroundEvents
self.trackFrustrations = trackFrustrations
self.firstPartyHosts = firstPartyHosts
self.eventBuilder = eventBuilder
self.rumUUIDGenerator = rumUUIDGenerator
self.backtraceReporter = backtraceReporter
self.ciTest = ciTest
self.syntheticsTest = syntheticsTest
self.vitalsReaders = vitalsReaders
self.onSessionStart = onSessionStart
self.viewCache = viewCache
self.fatalErrorContext = fatalErrorContext
self.telemetry = featureScope.telemetry
self.sessionEndedMetric = sessionEndedMetric
self.viewEndedMetricFactory = viewEndedMetricFactory
self.watchdogTermination = watchdogTermination
self.networkSettledMetricFactory = networkSettledMetricFactory
self.interactionToNextViewMetricFactory = interactionToNextViewMetricFactory
if ciTest != nil {
self.sessionType = .ciTest
} else if syntheticsTest != nil {
self.sessionType = .synthetics
} else {
self.sessionType = .user
}
}
}