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-1113 Pass logged error to RUM integration #423

Merged

Conversation

buranmert
Copy link
Contributor

What and why?

When logger.error(...) is called, LoggingWithRUMIntegration creates an equivalent RUM error.
However, this integration is not fully up to date: when it was written logger.error(...) could only take message: String as parameter but now it also takes error: Error? as parameter.

How?

This PR passes logged error to RUM integration. That way, RUM error is created out of the logged error instead of logged message. This gives more accurate information in RUM Explorer as can be seen in screenshots below.

log.error("an error message occurred")

log-without-error

log.error("some message", error: NSError(...))

log-with-error

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference

Now Log has its own Error property
Integration use Error property and pass it to RUM
Also, Scopes take error.type instead of using error.message for type
@buranmert buranmert added this to the next-version milestone Feb 24, 2021
@buranmert buranmert requested a review from a team as a code owner February 24, 2021 17:35
@buranmert buranmert self-assigned this Feb 24, 2021
Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

Looks very good 👌, but I left few notes on how we can make DDError definition & usage better for what's required in crash reporting.

Comment on lines 10 to 13
internal struct DDError: Equatable {
let title: String
let message: String
let details: String
Copy link
Member

Choose a reason for hiding this comment

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

Today we know much more on the unified "Datadog error format". Error Tracking team uses error.type, error.message and error.stackTrace consistently and those values are commonly present in Logging, APM and RUM. This is a new knowledge comparing to what we knew when introducing this DDError.

How about improving DDError to act as a unified Datadog Error format? Can be done with simple renaming:

/// Datadog Error format
internal struct DDError: Equatable {
   let type: String
   let message: String
   let stack: String
}

This should make the work with DDError much easier, as all the downstream mappings will be more straightforward, e.g.:

  • in Log encoding: error stack = dderror.details will become error stack = dderror.stack
  • in Logging to RUM integration, error type = dderror.title will become error type = dderror.type

Also, this would help a lot with upcoming RUMM-1050 (Send crash reports as Logs), where type, message and stack are read separately from DDCrashReport. With this change, we could simply build DDError(type: ddcrash.type, message: ddcrash.message, stack: ddcrash.stack) and pass it to the LogBuilder using new logic added in this PR 👌.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, done ✅

@@ -15,5 +15,5 @@ internal struct LogAttributes {

/// Type writting logs to some destination.
internal protocol LogOutput {
func writeLogWith(level: LogLevel, message: String, date: Date, attributes: LogAttributes, tags: Set<String>)
func writeLogWith(level: LogLevel, message: String, error: Error?, date: Date, attributes: LogAttributes, tags: Set<String>)
Copy link
Member

Choose a reason for hiding this comment

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

If we change error: Error? to dderror: DDError? here, we won't need to play with the vague Error representation downstream (it will be mapped to DDError early in the Logger). This will also enable seamless integration of crash reporting (RUMM-1050), as the DDError() for crash report can be easily constructed.

recordedLog = RecordedLog(
level: level,
message: message,
error: error.flatMap { DDError(error: $0) },
Copy link
Member

Choose a reason for hiding this comment

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

⚠️ Another reason for using DDError in LogOutput signature. Now we need to make this mock smarter (by using part of the real output logic), to make it work. Mapping to DDError as soon as possible (in Logger) would fix this.

@@ -307,11 +307,13 @@ public class RUMMonitor: DDRUMMonitor, RUMCommandSubscriber {
}
return nil
}()
addError(message: message, stack: stack, source: RUMInternalErrorSource(source), attributes: attributes)
// Note for CR: should `type` be nil?
Copy link
Member

@ncreated ncreated Feb 25, 2021

Choose a reason for hiding this comment

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

I think this is what we concluded with the Android SDK team, right?

Suggested change
// Note for CR: should `type` be nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, removed ✅

Copy link
Member

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

Nice 🚀! Should help a lot with crash reporting as well.

@@ -491,6 +494,8 @@ public class RUMMonitor: DDRUMMonitor, RUMCommandSubscriber {
resourceKey: resourceKey,
time: dateProvider.currentDate(),
message: errorMessage,
// Note for CR: should we leave it nil?
Copy link
Member

Choose a reason for hiding this comment

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

Same - concluded with the Android SDK team.

Suggested change
// Note for CR: should we leave it nil?

@buranmert buranmert force-pushed the buranmert/RUMM-1113-pass-log-error-to-rum-integration branch from 01a6f60 to c32ee1d Compare February 25, 2021 10:39
@buranmert buranmert merged commit 842ebec into master Feb 25, 2021
@buranmert buranmert deleted the buranmert/RUMM-1113-pass-log-error-to-rum-integration branch February 25, 2021 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants