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

RUMM-961 DDError.title is used in RUMEvents.error.type #393

Merged
merged 4 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 25 additions & 1 deletion Sources/Datadog/RUM/DataModels/RUMDataModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ public struct RUMViewEvent: RUMDataModel {

/// Session properties
public struct Session: Codable {
/// Whether this session has a replay
public let hasReplay: Bool?

/// UUID of the session
public let id: String

/// Type of the session
public let type: SessionType

enum CodingKeys: String, CodingKey {
case hasReplay = "has_replay"
case id = "id"
case type = "type"
}
Expand Down Expand Up @@ -122,6 +126,9 @@ public struct RUMViewEvent: RUMDataModel {
/// Duration in ns of the first input event delay
public let firstInputDelay: Int64?

/// Duration in ns to the first input
public let firstInputTime: Int64?

/// UUID of the view
public let id: String

Expand Down Expand Up @@ -165,6 +172,7 @@ public struct RUMViewEvent: RUMDataModel {
case error = "error"
case firstContentfulPaint = "first_contentful_paint"
case firstInputDelay = "first_input_delay"
case firstInputTime = "first_input_time"
case id = "id"
case isActive = "is_active"
case largestContentfulPaint = "largest_contentful_paint"
Expand Down Expand Up @@ -527,13 +535,17 @@ public struct RUMResourceEvent: RUMDataModel {

/// Session properties
public struct Session: Codable {
/// Whether this session has a replay
public let hasReplay: Bool?

/// UUID of the session
public let id: String

/// Type of the session
public let type: SessionType

enum CodingKeys: String, CodingKey {
case hasReplay = "has_replay"
case id = "id"
case type = "type"
}
Expand Down Expand Up @@ -730,13 +742,17 @@ public struct RUMActionEvent: RUMDataModel {

/// Session properties
public struct Session: Codable {
/// Whether this session has a replay
public let hasReplay: Bool?

/// UUID of the session
public let id: String

/// Type of the session
public let type: SessionType

enum CodingKeys: String, CodingKey {
case hasReplay = "has_replay"
case id = "id"
case type = "type"
}
Expand Down Expand Up @@ -863,12 +879,16 @@ public struct RUMErrorEvent: RUMDataModel {
/// Stacktrace of the error
public var stack: String?

/// The type of the error
public let type: String?

enum CodingKeys: String, CodingKey {
case isCrash = "is_crash"
case message = "message"
case resource = "resource"
case source = "source"
case stack = "stack"
case type = "type"
}

/// Resource properties of the error
Expand Down Expand Up @@ -943,13 +963,17 @@ public struct RUMErrorEvent: RUMDataModel {

/// Session properties
public struct Session: Codable {
/// Whether this session has a replay
public let hasReplay: Bool?

/// UUID of the session
public let id: String

/// Type of the session
public let type: SessionType

enum CodingKeys: String, CodingKey {
case hasReplay = "has_replay"
case id = "id"
case type = "type"
}
Expand Down Expand Up @@ -1059,4 +1083,4 @@ public enum RUMMethod: String, Codable {
case patch = "PATCH"
}

// Generated from https://github.com/DataDog/rum-events-format/tree/5c673c12f2fc464ec87dcb5e3a79b0f739a311b7
// Generated from https://github.com/DataDog/rum-events-format/tree/8b955a03d0fe0b2f032a02d6800c61ef3fc9fada
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ internal class RUMResourceScope: RUMScope {
url: resourceURL
),
service: nil,
session: .init(id: context.sessionID.toRUMDataFormat, type: .user),
session: .init(hasReplay: nil, id: context.sessionID.toRUMDataFormat, type: .user),
usr: dependencies.userInfoProvider.current,
view: .init(
id: context.activeViewID.orNull.toRUMDataFormat,
Expand Down Expand Up @@ -203,10 +203,11 @@ internal class RUMResourceScope: RUMScope {
url: resourceURL
),
source: command.errorSource.toRUMDataFormat,
stack: command.stack
stack: command.stack,
type: command.errorMessage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered introducing command.errorType and setting it to dderror.title at the higher level?

// In RUMCommand

// TODO: RUMM-1042 The way of setting error.type must unified with Logging and Tracing 
self.errorType = dderror.title

This might be safer as a temporary solution, as the work of passing the value down to the scopes will be already done. Also, it limits the refactoring to single file (RUMCommands.swift).

Copy link
Contributor Author

@buranmert buranmert Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i thought about that but it makes more sense to make those changes in 1042

),
service: nil,
session: .init(id: context.sessionID.toRUMDataFormat, type: .user),
session: .init(hasReplay: nil, id: context.sessionID.toRUMDataFormat, type: .user),
usr: dependencies.userInfoProvider.current,
view: .init(
id: context.activeViewID.orNull.toRUMDataFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal class RUMUserActionScope: RUMScope, RUMContextProvider {
connectivity: dependencies.connectivityInfoProvider.current,
date: dateCorrection.applying(to: actionStartTime).timeIntervalSince1970.toInt64Milliseconds,
service: nil,
session: .init(id: context.sessionID.toRUMDataFormat, type: .user),
session: .init(hasReplay: nil, id: context.sessionID.toRUMDataFormat, type: .user),
usr: dependencies.userInfoProvider.current,
view: .init(
id: context.activeViewID.orNull.toRUMDataFormat,
Expand Down
10 changes: 6 additions & 4 deletions Sources/Datadog/RUM/RUMMonitor/Scopes/RUMViewScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ internal class RUMViewScope: RUMScope, RUMContextProvider {
connectivity: dependencies.connectivityInfoProvider.current,
date: dateCorrection.applying(to: viewStartTime).timeIntervalSince1970.toInt64Milliseconds,
service: nil,
session: .init(id: context.sessionID.toRUMDataFormat, type: .user),
session: .init(hasReplay: nil, id: context.sessionID.toRUMDataFormat, type: .user),
usr: dependencies.userInfoProvider.current,
view: .init(
id: viewUUID.toRUMDataFormat,
Expand All @@ -264,7 +264,7 @@ internal class RUMViewScope: RUMScope, RUMContextProvider {
connectivity: dependencies.connectivityInfoProvider.current,
date: dateCorrection.applying(to: viewStartTime).timeIntervalSince1970.toInt64Milliseconds,
service: nil,
session: .init(id: context.sessionID.toRUMDataFormat, type: .user),
session: .init(hasReplay: nil, id: context.sessionID.toRUMDataFormat, type: .user),
usr: dependencies.userInfoProvider.current,
view: .init(
action: .init(count: actionsCount.toInt64),
Expand All @@ -276,6 +276,7 @@ internal class RUMViewScope: RUMScope, RUMContextProvider {
error: .init(count: errorsCount.toInt64),
firstContentfulPaint: nil,
firstInputDelay: nil,
firstInputTime: nil,
id: viewUUID.toRUMDataFormat,
isActive: isActiveView,
largestContentfulPaint: nil,
Expand Down Expand Up @@ -310,10 +311,11 @@ internal class RUMViewScope: RUMScope, RUMContextProvider {
message: command.message,
resource: nil,
source: command.source.toRUMDataFormat,
stack: command.stack
stack: command.stack,
type: command.message
),
service: nil,
session: .init(id: context.sessionID.toRUMDataFormat, type: .user),
session: .init(hasReplay: nil, id: context.sessionID.toRUMDataFormat, type: .user),
usr: dependencies.userInfoProvider.current,
view: .init(
id: context.activeViewID.orNull.toRUMDataFormat,
Expand Down
26 changes: 25 additions & 1 deletion Sources/DatadogObjc/RUM/RUMDataModels+objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ public class DDRUMViewEventSession: NSObject {
self.root = root
}

@objc public var hasReplay: NSNumber? {
root.swiftModel.session.hasReplay as NSNumber?
}

@objc public var id: String {
root.swiftModel.session.id
}
Expand Down Expand Up @@ -291,6 +295,10 @@ public class DDRUMViewEventView: NSObject {
root.swiftModel.view.firstInputDelay as NSNumber?
}

@objc public var firstInputTime: NSNumber? {
root.swiftModel.view.firstInputTime as NSNumber?
}

@objc public var id: String {
root.swiftModel.view.id
}
Expand Down Expand Up @@ -982,6 +990,10 @@ public class DDRUMResourceEventSession: NSObject {
self.root = root
}

@objc public var hasReplay: NSNumber? {
root.swiftModel.session.hasReplay as NSNumber?
}

@objc public var id: String {
root.swiftModel.session.id
}
Expand Down Expand Up @@ -1383,6 +1395,10 @@ public class DDRUMActionEventSession: NSObject {
self.root = root
}

@objc public var hasReplay: NSNumber? {
root.swiftModel.session.hasReplay as NSNumber?
}

@objc public var id: String {
root.swiftModel.session.id
}
Expand Down Expand Up @@ -1680,6 +1696,10 @@ public class DDRUMErrorEventError: NSObject {
set { root.swiftModel.error.stack = newValue }
get { root.swiftModel.error.stack }
}

@objc public var type: String? {
root.swiftModel.error.type
}
}

@objc
Expand Down Expand Up @@ -1863,6 +1883,10 @@ public class DDRUMErrorEventSession: NSObject {
self.root = root
}

@objc public var hasReplay: NSNumber? {
root.swiftModel.session.hasReplay as NSNumber?
}

@objc public var id: String {
root.swiftModel.session.id
}
Expand Down Expand Up @@ -1938,4 +1962,4 @@ public class DDRUMErrorEventView: NSObject {

// swiftlint:enable force_unwrapping

// Generated from https://github.com/DataDog/rum-events-format/tree/5c673c12f2fc464ec87dcb5e3a79b0f739a311b7
// Generated from https://github.com/DataDog/rum-events-format/tree/8b955a03d0fe0b2f032a02d6800c61ef3fc9fada
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class RUMStorageBenchmarkTests: XCTestCase {
connectivity: nil,
date: Int64.random(in: Int64.min..<Int64.max),
service: .mockRandom(length: 20),
session: .init(id: UUID().uuidString, type: .user),
session: .init(hasReplay: nil, id: UUID().uuidString, type: .user),
usr: .init(
email: .mockRandom(length: 10),
id: .mockRandom(length: 10),
Expand All @@ -105,6 +105,7 @@ class RUMStorageBenchmarkTests: XCTestCase {
error: .init(count: .mockAny()),
firstContentfulPaint: nil,
firstInputDelay: nil,
firstInputTime: nil,
id: UUID().uuidString,
isActive: nil,
largestContentfulPaint: nil,
Expand Down
8 changes: 7 additions & 1 deletion Tests/DatadogTests/Datadog/Mocks/RUMDataModelMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extension RUMViewEvent {
date: .mockRandom(),
service: .mockRandom(),
session: .init(
hasReplay: nil,
id: .mockRandom(),
type: .user
),
Expand All @@ -65,6 +66,7 @@ extension RUMViewEvent {
error: .init(count: .mockRandom()),
firstContentfulPaint: .mockRandom(),
firstInputDelay: .mockRandom(),
firstInputTime: .mockRandom(),
id: .mockRandom(),
isActive: .random(),
largestContentfulPaint: .mockRandom(),
Expand Down Expand Up @@ -114,6 +116,7 @@ extension RUMResourceEvent {
),
service: .mockRandom(),
session: .init(
hasReplay: nil,
id: .mockRandom(),
type: .user
),
Expand Down Expand Up @@ -146,6 +149,7 @@ extension RUMActionEvent {
date: .mockRandom(),
service: .mockRandom(),
session: .init(
hasReplay: nil,
id: .mockRandom(),
type: .user
),
Expand Down Expand Up @@ -181,10 +185,12 @@ extension RUMErrorEvent {
url: .mockRandom()
),
source: [.source, .network, .custom].randomElement()!,
stack: .mockRandom()
stack: .mockRandom(),
type: .mockRandom()
),
service: .mockRandom(),
session: .init(
hasReplay: nil,
id: .mockRandom(),
type: .user
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class RUMResourceScopeTests: XCTestCase {
XCTAssertEqual(event.model.error.source, .network)
XCTAssertEqual(event.model.error.stack, "network issue explanation")
XCTAssertEqual(event.model.error.resource?.method, .post)
XCTAssertEqual(event.model.error.type, "ErrorMock")
XCTAssertNil(event.model.error.resource?.provider)
XCTAssertEqual(event.model.error.resource?.statusCode, 500)
XCTAssertEqual(event.model.error.resource?.url, "https://foo.com/resource/1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ class RUMViewScopeTests: XCTestCase {
XCTAssertNil(error.model.connectivity)
XCTAssertEqual(error.model.error.message, "view error")
XCTAssertEqual(error.model.error.source, .source)
XCTAssertEqual(error.model.error.type, "view error")
XCTAssertNil(error.model.error.stack)
XCTAssertNil(error.model.error.isCrash)
XCTAssertNil(error.model.error.resource)
Expand Down
2 changes: 2 additions & 0 deletions Tests/DatadogTests/Datadog/RUMMonitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class RUMMonitorTests: XCTestCase {
XCTAssertEqual(rumModel.error.message, "View error message")
XCTAssertEqual(rumModel.error.stack, "Foo.swift:100")
XCTAssertEqual(rumModel.error.source, .source)
XCTAssertEqual(rumModel.error.type, "View error message")
}
try rumEventMatchers[3].model(ofType: RUMViewEvent.self) { rumModel in
XCTAssertEqual(rumModel.view.action.count, 1)
Expand All @@ -334,6 +335,7 @@ class RUMMonitorTests: XCTestCase {
XCTAssertEqual(rumModel.error.message, "Another error message")
XCTAssertEqual(rumModel.error.stack, "Error stack")
XCTAssertEqual(rumModel.error.source, .webview)
XCTAssertEqual(rumModel.error.type, "Another error message")
}
try rumEventMatchers[5].model(ofType: RUMViewEvent.self) { rumModel in
XCTAssertEqual(rumModel.view.action.count, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SwiftPrinter: BasePrinter {
indentRight()
try printPropertiesList(swiftStruct.properties)
if swiftStruct.conforms(to: codableProtocol) {
try printCodingKeys(for: swiftStruct.properties)
printCodingKeys(for: swiftStruct.properties)
}
try printNestedTypes(in: swiftStruct)
indentLeft()
Expand Down Expand Up @@ -78,7 +78,7 @@ public class SwiftPrinter: BasePrinter {
}
}

private func printCodingKeys(for properties: [SwiftStruct.Property]) throws {
private func printCodingKeys(for properties: [SwiftStruct.Property]) {
writeEmptyLine()
writeLine("enum CodingKeys: String, CodingKey {")
indentRight()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ internal class RUMSwiftTypeTransformer: TypeTransformer<SwiftType> {

var `struct` = `struct`
`struct`.name = format(structName: `struct`.name)
`struct`.properties = try `struct`.properties.map { try transform(structProperty: $0) }
`struct`.properties = try `struct`.properties
.map { try transform(structProperty: $0) }
// TODO: RUMM-1000 should remove this filter
.filter { property in property.name != "customTimings" }
if context.parent == nil {
`struct`.conformance = [rumDataModelProtocol] // Conform root structs to `RUMDataModel`
} else {
Expand Down