Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 2.3.0 to develop #1496

Merged
merged 17 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Unreleased

# 2.3.0 / 27-09-2023

- [IMPROVEMENT] Add UIBackgroundTask for uploading jobs. See [#1412][]
- [IMPROVEMENT] Report Build Number in Logs and RUM. See [#1465][]
- [BUGFIX] Fix wrong `view.name` reported in RUM crashes. See [#1488][]
- [BUGFIX] Fix RUM sessions state propagation in Crash Reporting. See [#1498][]

# 2.2.1 / 13-09-2023

Expand Down Expand Up @@ -531,6 +534,7 @@ Release `2.0` introduces breaking changes. Follow the [Migration Guide](MIGRATIO
[#1412]: https://github.com/DataDog/dd-sdk-ios/pull/1412
[#1488]: https://github.com/DataDog/dd-sdk-ios/pull/1488
[#1465]: https://github.com/DataDog/dd-sdk-ios/pull/1465
[#1498]: https://github.com/DataDog/dd-sdk-ios/pull/1498
[@00fa9a]: https://github.com/00FA9A
[@britton-earnin]: https://github.com/Britton-Earnin
[@hengyu]: https://github.com/Hengyu
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.2.1"
s.version = "2.3.0"
s.summary = "An Official Extensions of Datadog Swift SDK for Alamofire."

s.homepage = "https://www.datadoghq.com"
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.2.1"
s.version = "2.3.0"
s.summary = "Official Datadog Swift SDK for iOS."

s.homepage = "https://www.datadoghq.com"
Expand Down
2 changes: 1 addition & 1 deletion DatadogCore/Sources/Versioning.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// GENERATED FILE: Do not edit directly

internal let __sdkVersion = "2.2.1"
internal let __sdkVersion = "2.3.0"
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,8 @@ class DataBlockTests: XCTestCase {
do {
_ = try reader.next()
XCTFail("Expected error to be thrown")
} catch DataBlockError.readOperationFailed(_, let error) {
XCTAssertEqual(
(error as? NSError)?.localizedDescription,
"The operation couldn’t be completed. No such file or directory"
)
} catch DataBlockError.readOperationFailed(_, let error as NSError) {
XCTAssertTrue(error.localizedDescription.contains("No such file or directory"))
} catch {
XCTFail("Unexpected error: \(error)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CrashContextProviderTests: XCTestCase {
let crashContextProvider = CrashContextCoreProvider()
let core = PassthroughCoreMock(messageReceiver: crashContextProvider)

let viewEvent = AnyCodable(mockRandomAttributes())
let viewEvent: RUMViewEvent = .mockRandom()

// When
crashContextProvider.onCrashContextChange = {
Expand All @@ -86,15 +86,18 @@ class CrashContextProviderTests: XCTestCase {
let crashContextProvider = CrashContextCoreProvider()
let core = PassthroughCoreMock(messageReceiver: crashContextProvider)

var viewEvent: AnyCodable? = AnyCodable(mockRandomAttributes())
var viewEvent: AnyCodable? = nil

// When
crashContextProvider.onCrashContextChange = {
viewEvent = $0.lastRUMViewEvent
expectation.fulfill()
}

core.send(message: .baggage(key: RUMBaggageKeys.viewEvent, value: viewEvent))
core.send(message: .baggage(key: RUMBaggageKeys.viewEvent, value: RUMViewEvent.mockRandom()))
crashContextProvider.flush()
XCTAssertNotNil(viewEvent)

core.send(message: .baggage(key: RUMBaggageKeys.viewReset, value: true))

// Then
Expand All @@ -112,7 +115,7 @@ class CrashContextProviderTests: XCTestCase {
let crashContextProvider = CrashContextCoreProvider()
let core = PassthroughCoreMock(messageReceiver: crashContextProvider)

let sessionState: AnyCodable? = AnyCodable(mockRandomAttributes())
let sessionState: RUMSessionState = .mockRandom()

// When
crashContextProvider.onCrashContextChange = {
Expand Down
2 changes: 1 addition & 1 deletion DatadogCrashReporting.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DatadogCrashReporting"
s.version = "2.2.1"
s.version = "2.3.0"
s.summary = "Official Datadog Crash Reporting SDK for iOS."

s.homepage = "https://www.datadoghq.com"
Expand Down
2 changes: 1 addition & 1 deletion DatadogInternal.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DatadogInternal"
s.version = "2.2.1"
s.version = "2.3.0"
s.summary = "Datadog Internal Package. This module is not for public use."

s.homepage = "https://www.datadoghq.com"
Expand Down
2 changes: 2 additions & 0 deletions DatadogInternal/Sources/Codable/AnyDecodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ extension _AnyDecodable {
self.init(double)
} else if let string = try? container.decode(String.self) {
self.init(string)
} else if let passthrough = container.passthrough() {
self.init(passthrough)
} else if let array = try? container.decode([AnyDecodable].self) {
self.init(array.map { $0.value })
} else if let dictionary = try? container.decode([String: AnyDecodable].self) {
Expand Down
16 changes: 16 additions & 0 deletions DatadogInternal/Sources/Codable/AnyDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,19 @@ private extension DecodingError {
return .typeMismatch(type, context)
}
}

extension SingleValueDecodingContainer {
/// Decodes a passthrough value of the given type.
///
/// This method can succeed only when using `AnyDecoder`.
///
/// - returns: A passthrough value if any.
/// - throws: `DecodingError.typeMismatch` if the value was not passthrough.
func passthrough() -> PassthroughAnyCodable? {
guard let container = self as? _AnyDecoder.SingleValueContainer else {
return nil
}

return container.value as? PassthroughAnyCodable
}
}
71 changes: 65 additions & 6 deletions DatadogInternal/Tests/Codable/AnyDecodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,71 @@ class AnyDecodableTests: XCTestCase {
let decoder = JSONDecoder()
let dictionary = try decoder.decode([String: AnyDecodable].self, from: json)

XCTAssertEqual(dictionary["boolean"]?.value as! Bool, true)
XCTAssertEqual(dictionary["integer"]?.value as! Int, 42)
XCTAssertEqual(dictionary["boolean"]?.value as? Bool, true)
XCTAssertEqual(dictionary["integer"]?.value as? Int, 42)
XCTAssertEqual(dictionary["double"]?.value as! Double, 3.141592653589793, accuracy: 0.001)
XCTAssertEqual(dictionary["string"]?.value as! String, "string")
XCTAssertEqual(dictionary["array"]?.value as! [Int], [1, 2, 3])
XCTAssertEqual(dictionary["nested"]?.value as! [String: String], ["a": "alpha", "b": "bravo", "c": "charlie"])
XCTAssertEqual(dictionary["null"]?.value as! NSNull, NSNull())
XCTAssertEqual(dictionary["string"]?.value as? String, "string")
XCTAssertEqual(dictionary["array"]?.value as? [Int], [1, 2, 3])
XCTAssertEqual(dictionary["nested"]?.value as? [String: String], ["a": "alpha", "b": "bravo", "c": "charlie"])
XCTAssertEqual(dictionary["null"]?.value as? NSNull, NSNull())
}

func testAnyDecoding() throws {
class Passthrough: PassthroughAnyCodable {
init() {}
}

let passthrough = Passthrough()

let any: [String: Any?] = [
"boolean": true,
"integer": 42,
"double": 3.141592653589793,
"string": "string",
"array": [1, 2, 3],
"nested": [
"a": "alpha",
"b": "bravo",
"c": "charlie"
],
"null": nil,
"uuid": UUID(),
"url": URL(string: "https://test.com"),
"passthrough": passthrough
]

let decoder = AnyDecoder()
let dictionary = try decoder.decode([String: AnyDecodable].self, from: any)

XCTAssertEqual(dictionary["boolean"]?.value as? Bool, true)
XCTAssertEqual(dictionary["integer"]?.value as? Int, 42)
XCTAssertEqual(dictionary["double"]?.value as! Double, 3.141592653589793, accuracy: 0.001)
XCTAssertEqual(dictionary["string"]?.value as? String, "string")
XCTAssertEqual(dictionary["array"]?.value as? [Int], [1, 2, 3])
XCTAssertEqual(dictionary["nested"]?.value as? [String: String], ["a": "alpha", "b": "bravo", "c": "charlie"])
XCTAssert(dictionary["uuid"]?.value is UUID)
XCTAssertEqual(dictionary["url"]?.value as? URL, URL(string: "https://test.com"))
XCTAssert(dictionary["passthrough"]?.value as? Passthrough === passthrough)
}

func testAnyDecodingFailue() throws {
class NotPassthrough {
init() {}
}

let passthrough = NotPassthrough()

let any: [String: Any?] = [
"passthrough": passthrough
]

let decoder = AnyDecoder()
XCTAssertThrowsError(try decoder.decode(AnyDecodable.self, from: any)) { error in
guard case DecodingError.dataCorrupted(let context) = error else {
return XCTFail("Unexpected error: \(error)")
}

XCTAssertEqual(context.debugDescription, "AnyDecodable value cannot be decoded")
}
}
}
2 changes: 1 addition & 1 deletion DatadogLogs.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DatadogLogs"
s.version = "2.2.1"
s.version = "2.3.0"
s.summary = "Datadog Logs Module."

s.homepage = "https://www.datadoghq.com"
Expand Down
2 changes: 1 addition & 1 deletion DatadogObjc.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DatadogObjc"
s.version = "2.2.1"
s.version = "2.3.0"
s.summary = "Official Datadog Objective-C SDK for iOS."

s.homepage = "https://www.datadoghq.com"
Expand Down
14 changes: 7 additions & 7 deletions DatadogObjc/Sources/RUM/RUMDataModels+objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3979,16 +3979,16 @@ public class DDRUMViewEventDisplayScroll: NSObject {
root.swiftModel.display!.scroll!.maxDepth as NSNumber
}

@objc public var maxDepthScrollHeight: NSNumber {
root.swiftModel.display!.scroll!.maxDepthScrollHeight as NSNumber
}

@objc public var maxDepthScrollTop: NSNumber {
root.swiftModel.display!.scroll!.maxDepthScrollTop as NSNumber
}

@objc public var maxDepthTime: NSNumber {
root.swiftModel.display!.scroll!.maxDepthTime as NSNumber
@objc public var maxScrollHeight: NSNumber {
root.swiftModel.display!.scroll!.maxScrollHeight as NSNumber
}

@objc public var maxScrollHeightTime: NSNumber {
root.swiftModel.display!.scroll!.maxScrollHeightTime as NSNumber
}
}

Expand Down Expand Up @@ -5544,4 +5544,4 @@ public class DDTelemetryConfigurationEventView: NSObject {

// swiftlint:enable force_unwrapping

// Generated from https://github.com/DataDog/rum-events-format/tree/1c476e469d5827aa1f4e60916f42ad35bbd950ef
// Generated from https://github.com/DataDog/rum-events-format/tree/f69ca4664ed6e69c929855d02c4ce3d4b85d0bb4
2 changes: 1 addition & 1 deletion DatadogRUM.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "DatadogRUM"
s.version = "2.2.1"
s.version = "2.3.0"
s.summary = "Datadog Real User Monitoring Module."

s.homepage = "https://www.datadoghq.com"
Expand Down
16 changes: 8 additions & 8 deletions DatadogRUM/Sources/DataModels/RUMDataModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1896,20 +1896,20 @@ public struct RUMViewEvent: RUMDataModel {
/// Distance between the top and the lowest point reached on this view (in pixels)
public let maxDepth: Double

/// Page scroll height (total height) when the maximum scroll depth was reached for this view (in pixels)
public let maxDepthScrollHeight: Double

/// Page scroll top (scrolled distance) when the maximum scroll depth was reached for this view (in pixels)
public let maxDepthScrollTop: Double

/// Duration between the view start and the scroll event that reached the maximum scroll depth for this view (in nanoseconds)
public let maxDepthTime: Double
/// Maximum page scroll height (total height) for this view (in pixels)
public let maxScrollHeight: Double

/// Duration between the view start and the time the max scroll height was reached for this view (in nanoseconds)
public let maxScrollHeightTime: Double

enum CodingKeys: String, CodingKey {
case maxDepth = "max_depth"
case maxDepthScrollHeight = "max_depth_scroll_height"
case maxDepthScrollTop = "max_depth_scroll_top"
case maxDepthTime = "max_depth_time"
case maxScrollHeight = "max_scroll_height"
case maxScrollHeightTime = "max_scroll_height_time"
}
}

Expand Down Expand Up @@ -3398,4 +3398,4 @@ public enum RUMMethod: String, Codable {
case patch = "PATCH"
}

// Generated from https://github.com/DataDog/rum-events-format/tree/1c476e469d5827aa1f4e60916f42ad35bbd950ef
// Generated from https://github.com/DataDog/rum-events-format/tree/f69ca4664ed6e69c929855d02c4ce3d4b85d0bb4
8 changes: 4 additions & 4 deletions DatadogRUM/Sources/Integrations/WebViewEventReceiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal final class WebViewEventReceiver: FeatureMessageReceiver {
}
var event = event

if let date = event["date"] as? Int {
if let date = event["date"] as? Int64 {
let viewID = (event["view"] as? JSON)?["id"] as? String
let serverTimeOffsetInMs = self.getOffsetInMs(viewID: viewID, context: context)
let correctedDate = Int64(date) + serverTimeOffsetInMs
Expand All @@ -96,9 +96,9 @@ internal final class WebViewEventReceiver: FeatureMessageReceiver {
event["session"] = session
}

if var dd = event["_dd"] as? JSON, var dd_sesion = dd["session"] as? [String: Int] {
dd_sesion["plan"] = 1
dd["session"] = dd_sesion
if var dd = event["_dd"] as? JSON, var dd_session = dd["session"] as? [String: Int64] {
dd_session["plan"] = 1
dd["session"] = dd_session
event["_dd"] = dd
}

Expand Down
Loading