Skip to content

Commit

Permalink
Merge pull request #2109 from DataDog/release/2.20.0
Browse files Browse the repository at this point in the history
Release 2.20.0
  • Loading branch information
ncreated authored Nov 14, 2024
2 parents a9a1b28 + abf5174 commit 2881108
Show file tree
Hide file tree
Showing 160 changed files with 2,228 additions and 1,124 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ A brief description of implementation details of this PR.
- [ ] Feature or bugfix MUST have appropriate tests (unit, integration)
- [ ] Make sure each commit and the PR mention the Issue number or JIRA reference
- [ ] Add CHANGELOG entry for user facing changes
- [ ] Add Objective-C interface for public APIs (see our [guidelines](https://datadoghq.atlassian.net/wiki/spaces/RUMP/pages/3157787243/RFC+-+Modular+Objective-C+Interface#Recommended-solution) (internal)) and run `make api-surface`
- [ ] Add Objective-C interface for public APIs (see our [guidelines](https://datadoghq.atlassian.net/wiki/spaces/RUMP/pages/3157787243/RFC+-+Modular+Objective-C+Interface#Recommended-solution) [internal]) and run `make api-surface`)
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# Unreleased

# 2.20.0 / 14-11-2024

- [FIX] Fix race condition during consent change, preventing loss of events recorded on the current thread. See [#2063][]
- [IMPROVEMENT] Support mutation of events' attributes. See [#2099][]
- [IMPROVEMENT] Add 'os' and 'device' info to Span events. See [#2104][]
- [FIX] Fix bug in SR that was enforcing full snapshot more often than needed. See [#2092][]

# 2.19.0 / 28-10-2024

- [FEATURE] Add Privacy Overrides in Session Replay. See [#2088][]
- [IMPROVEMENT] Add ObjC API for the internal logging/telemetry. See [#2073][]
- [IMPROVEMENT] Support `clipsToBounds` in Session Replay. See [#2083][]

# 2.18.0 / 25-09-2024
- [IMPROVEMENT] Add overwrite required (breaking) param to addViewLoadingTime & usage telemetry. See [#2040][]
Expand Down Expand Up @@ -781,6 +789,11 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
[#2050]: https://github.com/DataDog/dd-sdk-ios/pull/2050
[#2073]: https://github.com/DataDog/dd-sdk-ios/pull/2073
[#2088]: https://github.com/DataDog/dd-sdk-ios/pull/2088
[#2083]: https://github.com/DataDog/dd-sdk-ios/pull/2083
[#2104]: https://github.com/DataDog/dd-sdk-ios/pull/2104
[#2099]: https://github.com/DataDog/dd-sdk-ios/pull/2099
[#2063]: https://github.com/DataDog/dd-sdk-ios/pull/2063
[#2092]: https://github.com/DataDog/dd-sdk-ios/pull/2092
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
[@hengyu]: https://github.com/Hengyu
Expand Down
36 changes: 18 additions & 18 deletions Datadog/Datadog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ class NetworkInstrumentationIntegrationTests: XCTestCase {
applicationID: .mockAny(),
urlSessionTracking: .init(
resourceAttributesProvider: { req, resp, data, err in
XCTAssertNotNil(data)
XCTAssertTrue(data!.count > 0)
providerDataCount = data!.count
providerDataCount = data?.count ?? 0
providerExpectation.fulfill()
return [:]
})
Expand Down Expand Up @@ -149,17 +147,14 @@ class NetworkInstrumentationIntegrationTests: XCTestCase {
)

let providerExpectation = expectation(description: "provider called")
var providerDataCount = 0
var providerData: Data?
var providerInfo: (resp: URLResponse?, data: Data?, err: Error?)?

RUM.enable(
with: .init(
applicationID: .mockAny(),
urlSessionTracking: .init(
resourceAttributesProvider: { req, resp, data, err in
XCTAssertNotNil(data)
XCTAssertTrue(data!.count > 0)
providerDataCount = data!.count
data.map { providerData = $0 }
resourceAttributesProvider: { _, resp, data, err in
providerInfo = (resp, data, err)
providerExpectation.fulfill()
return [:]
})
Expand All @@ -182,20 +177,18 @@ class NetworkInstrumentationIntegrationTests: XCTestCase {
let request = URLRequest(url: URL(string: "https://www.datadoghq.com/")!)

let taskExpectation = self.expectation(description: "task completed")
var taskDataCount = 0
var taskData: Data?
let task = session.dataTask(with: request) { data, _, _ in
XCTAssertNotNil(data)
XCTAssertTrue(data!.count > 0)
taskDataCount = data!.count
data.map { taskData = $0 }
var taskInfo: (resp: URLResponse?, data: Data?, err: Error?)?

let task = session.dataTask(with: request) { resp, data, err in
taskInfo = (data, resp, err)
taskExpectation.fulfill()
}
task.resume()

wait(for: [providerExpectation, taskExpectation], timeout: 10)
XCTAssertEqual(providerDataCount, taskDataCount)
XCTAssertEqual(providerData, taskData)
XCTAssertEqual(providerInfo?.resp, taskInfo?.resp)
XCTAssertEqual(providerInfo?.data, taskInfo?.data)
XCTAssertEqual(providerInfo?.err as? NSError, taskInfo?.err as? NSError)
}

class InstrumentedSessionDelegate: NSObject, URLSessionDataDelegate {
Expand Down
2 changes: 1 addition & 1 deletion DatadogAlamofireExtension.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DatadogAlamofireExtension"
s.version = "2.19.0"
s.version = "2.20.0"
s.summary = "An Official Extensions of Datadog Swift SDK for Alamofire."
s.description = <<-DESC
The DatadogAlamofireExtension pod is deprecated and will no longer be maintained.
Expand Down
2 changes: 1 addition & 1 deletion DatadogCore.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DatadogCore"
s.version = "2.19.0"
s.version = "2.20.0"
s.summary = "Official Datadog Swift SDK for iOS."

s.homepage = "https://www.datadoghq.com"
Expand Down
50 changes: 10 additions & 40 deletions DatadogCore/Sources/Core/Context/ApplicationStatePublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ import WatchKit
internal final class ApplicationStatePublisher: ContextValuePublisher {
typealias Snapshot = AppStateHistory.Snapshot

private static var currentApplicationState: ApplicationState {
#if canImport(WatchKit)
WKExtension.dd.shared.applicationState
#else
UIApplication.dd.managedShared?.applicationState ?? .active // fallback to most expected state
#endif
}

/// The default publisher queue.
private static let defaultQueue = DispatchQueue(
label: "com.datadoghq.app-state-publisher",
Expand Down Expand Up @@ -58,19 +50,21 @@ internal final class ApplicationStatePublisher: ContextValuePublisher {
/// Creates a Application state publisher for publishing application state
/// history.
///
/// **Note**: It must be called on the main thread.
///
/// - Parameters:
/// - initialState: The initial application state.
/// - queue: The queue for publishing the history.
/// - dateProvider: The date provider for the Application state snapshot timestamp.
/// - appStateProvider: The provider to access the current application state.
/// - notificationCenter: The notification center where this publisher observes `UIApplication` notifications.
/// - dateProvider: The date provider for the Application state snapshot timestamp.
/// - queue: The queue for publishing the history.
init(
initialState: AppState,
queue: DispatchQueue = ApplicationStatePublisher.defaultQueue,
dateProvider: DateProvider = SystemDateProvider(),
notificationCenter: NotificationCenter = .default
appStateProvider: AppStateProvider,
notificationCenter: NotificationCenter,
dateProvider: DateProvider,
queue: DispatchQueue = ApplicationStatePublisher.defaultQueue
) {
let initialValue = AppStateHistory(
initialState: initialState,
initialState: appStateProvider.current,
date: dateProvider.now
)

Expand All @@ -81,30 +75,6 @@ internal final class ApplicationStatePublisher: ContextValuePublisher {
self.notificationCenter = notificationCenter
}

/// Creates a Application state publisher for publishing application state
/// history.
///
/// **Note**: It must be called on the main thread.
///
/// - Parameters:
/// - applicationState: The current shared `UIApplication` state.
/// - queue: The queue for publishing the history.
/// - dateProvider: The date provider for the Application state snapshot timestamp.
/// - notificationCenter: The notification center where this publisher observes `UIApplication` notifications.
convenience init(
applicationState: ApplicationState = ApplicationStatePublisher.currentApplicationState,
queue: DispatchQueue = ApplicationStatePublisher.defaultQueue,
dateProvider: DateProvider = SystemDateProvider(),
notificationCenter: NotificationCenter = .default
) {
self.init(
initialState: AppState(applicationState),
queue: queue,
dateProvider: dateProvider,
notificationCenter: notificationCenter
)
}

func publish(to receiver: @escaping ContextValueReceiver<AppStateHistory>) {
queue.async { self.receiver = receiver }
notificationCenter.addObserver(self, selector: #selector(applicationDidBecomeActive), name: ApplicationNotifications.didBecomeActive, object: nil)
Expand Down
6 changes: 3 additions & 3 deletions DatadogCore/Sources/Core/Context/BatteryStatusPublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ internal final class BatteryStatusPublisher: ContextValuePublisher {
/// Creates a battery status publisher from the given device.
///
/// - Parameters:
/// - device: The `UIDevice` instance. `.current` by default.
/// - notificationCenter: The notification center for observing the `UIDevice` battery changes,
/// - device: The `UIDevice` instance.
init(
device: UIDevice = .current,
notificationCenter: NotificationCenter = .default
notificationCenter: NotificationCenter,
device: UIDevice
) {
self.device = device
self.notificationCenter = notificationCenter
Expand Down
6 changes: 3 additions & 3 deletions DatadogCore/Sources/Core/Context/LowPowerModePublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ internal final class LowPowerModePublisher: ContextValuePublisher {
/// Creates a low power mode publisher.
///
/// - Parameters:
/// - processInfo: The process for reading the initial `isLowPowerModeEnabled`.
/// - notificationCenter: The notification center for observing the `NSProcessInfoPowerStateDidChange`,
/// - processInfo: The process for reading the initial `isLowPowerModeEnabled`.
init(
processInfo: ProcessInfo = .processInfo,
notificationCenter: NotificationCenter = .default
notificationCenter: NotificationCenter,
processInfo: ProcessInfo
) {
self.initialValue = processInfo.isLowPowerModeEnabled
self.notificationCenter = notificationCenter
Expand Down
22 changes: 17 additions & 5 deletions DatadogCore/Sources/Core/DatadogCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ internal final class DatadogCore {
/// - Parameter trackingConsent: new consent value, which will be applied for all data collected from now on
func set(trackingConsent: TrackingConsent) {
if trackingConsent != consentPublisher.consent {
allStorages.forEach { $0.migrateUnauthorizedData(toConsent: trackingConsent) }
contextProvider.queue.async { [allStorages] in
// RUM-3175: To prevent race conditions with ongoing "event write" operations,
// data migration must be synchronized on the context queue. This guarantees that
// all latest events have been written before migration occurs.
allStorages.forEach { $0.migrateUnauthorizedData(toConsent: trackingConsent) }
}
consentPublisher.consent = trackingConsent
}
}
Expand Down Expand Up @@ -400,8 +405,11 @@ extension DatadogContextProvider {
applicationVersion: String,
sdkInitDate: Date,
device: DeviceInfo,
processInfo: ProcessInfo,
dateProvider: DateProvider,
serverDateProvider: ServerDateProvider
serverDateProvider: ServerDateProvider,
notificationCenter: NotificationCenter,
appStateProvider: AppStateProvider
) {
let context = DatadogContext(
site: site,
Expand Down Expand Up @@ -442,14 +450,18 @@ extension DatadogContextProvider {
#endif

#if os(iOS) && !targetEnvironment(simulator)
subscribe(\.batteryStatus, to: BatteryStatusPublisher())
subscribe(\.isLowPowerModeEnabled, to: LowPowerModePublisher())
subscribe(\.batteryStatus, to: BatteryStatusPublisher(notificationCenter: notificationCenter, device: .current))
subscribe(\.isLowPowerModeEnabled, to: LowPowerModePublisher(notificationCenter: notificationCenter, processInfo: processInfo))
#endif

#if os(iOS) || os(tvOS)
DispatchQueue.main.async {
// must be call on the main thread to read `UIApplication.State`
let applicationStatePublisher = ApplicationStatePublisher(dateProvider: dateProvider)
let applicationStatePublisher = ApplicationStatePublisher(
appStateProvider: appStateProvider,
notificationCenter: notificationCenter,
dateProvider: dateProvider
)
self.subscribe(\.applicationStateHistory, to: applicationStatePublisher)
}
#endif
Expand Down
Loading

0 comments on commit 2881108

Please sign in to comment.