Skip to content

RUM-2907 Allow setting custom error fingerprint#1911

Merged
fuzzybinary merged 4 commits into
developfrom
jward/RUM-2907-error-fingerprint
Mar 14, 2024
Merged

RUM-2907 Allow setting custom error fingerprint#1911
fuzzybinary merged 4 commits into
developfrom
jward/RUM-2907-error-fingerprint

Conversation

@fuzzybinary

@fuzzybinary fuzzybinary commented Mar 12, 2024

Copy link
Copy Markdown
Member

What does this PR do?

This sets up attributes that are automatically transferred to the Error objects for Logs and RUM.

For logs, the attribute is LogAttributes.ERROR_FINGERPRINT and sets the fingerprint in the LogEvent.Error.

For RUM, the attribute is RumAttributes.ERROR_FINGERPRINT and sets the fingerprint member in ErrorEvent.Error

Also fixes RUM-2209 by adding the LogEvent.Error.fingerprint member

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@fuzzybinary
fuzzybinary requested review from a team as code owners March 12, 2024 19:04
This sets up an attribute, `LogAttributes.ERROR_FINGERPRINT` that is automatically transferred to the `Error` object in `LogEvent`s.

Also fixes RUM-2209 by adding the `LogEvent.Error.fingerprint` member
@fuzzybinary
fuzzybinary force-pushed the jward/RUM-2907-error-fingerprint branch from 1e3de3a to c195c9a Compare March 12, 2024 21:15
@codecov-commenter

codecov-commenter commented Mar 12, 2024

Copy link
Copy Markdown

Codecov Report

Merging #1911 (68b3fc8) into develop (f46eb76) will decrease coverage by 0.02%.
Report is 6 commits behind head on develop.
The diff coverage is 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1911      +/-   ##
===========================================
- Coverage    83.38%   83.36%   -0.02%     
===========================================
  Files          477      477              
  Lines        16922    16971      +49     
  Branches      2514     2525      +11     
===========================================
+ Hits         14109    14147      +38     
- Misses        2120     2125       +5     
- Partials       693      699       +6     
Files Coverage Δ
...in/kotlin/com/datadog/android/log/LogAttributes.kt 0.00% <ø> (ø)
...android/log/internal/domain/DatadogLogGenerator.kt 98.06% <100.00%> (+0.09%) ⬆️
...in/kotlin/com/datadog/android/rum/RumAttributes.kt 0.00% <ø> (ø)
.../main/kotlin/com/datadog/android/rum/RumMonitor.kt 28.57% <ø> (ø)
...roid/rum/internal/domain/scope/RumResourceScope.kt 94.87% <100.00%> (+0.78%) ⬆️
.../android/rum/internal/domain/scope/RumViewScope.kt 93.29% <100.00%> (+0.02%) ⬆️

... and 26 files with indirect coverage changes

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, but I think it is missing the following:

  • We need also implementation for RUM. Is it going to be added in another PR?
  • How we are going to let know the customers that they can use this attribute? Are we going to update some documentation?

@fuzzybinary

Copy link
Copy Markdown
Member Author
  • We need also implementation for RUM. Is it going to be added in another PR?

I'll go back and do it for this one.

  • How we are going to let know the customers that they can use this attribute? Are we going to update some documentation?

That was my plan. Do you think there's a better way?

@0xnm

0xnm commented Mar 13, 2024

Copy link
Copy Markdown
Member

That was my plan. Do you think there's a better way?

probably updating documentation of related API methods will be enough.

@fuzzybinary fuzzybinary changed the title RUM-2907 Allow setting error fingerprint in log calls RUM-2907 Allow setting custom error fingerprint Mar 13, 2024
@fuzzybinary
fuzzybinary requested a review from 0xnm March 13, 2024 15:18
const val ERROR_DATABASE_PATH: String = "error.database.path"

/**
* Specifies a custom error fingerprint for the supplied.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* Specifies a custom error fingerprint for the supplied.
* Specifies a custom error fingerprint for the supplied error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also let's add a reference to RumAttributes.ERROR_FINGERPRINT in the RumMonitor APIs descriptions where applicable.

val updatedAttributes = addExtraAttributes(event.attributes)
val isFatal = updatedAttributes
.remove(RumAttributes.INTERNAL_ERROR_IS_CRASH) as? Boolean == true || event.isFatal
val errorFingerprint = updatedAttributes.remove(RumAttributes.ERROR_FINGERPRINT) as? String

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we support this attribute in the RumResourceScope as well? 🤔 there is a possibility in API to stop resource with error.

I don't have an answer for that, just thinking.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's a good thought, and I don't have an answer for it either. Are resource errors considered in Error Tracking and thus would they consult the fingerprint? Maybe a question for the ET team.

Comment on lines +5072 to +5077
assertThat(firstValue)
.apply {
hasMessage(throwableMessage)
hasStackTrace(stacktrace)
hasErrorFingerprint(fingerprint)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ideally we need to assert all properties of the event as it is done in other tests.

Or at least assert that attributes send to the backend have no RumAttributes.ERROR_FINGERPRINT

put(RumAttributes.ERROR_FINGERPRINT, fingerprint)
}
val throwableMessage = throwable.message
check(!throwableMessage.isNullOrBlank()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

better to use the assumeTrue here, I don't think we want to fail the test if test setup is not good.

but anyway, is this needed here? what changes if message is null (it is never possible by looking on ThrowableForgeryFactory) or blank?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since throwable.message is Stirng?, check performs the null check that allows us to no not perform the force dereference further down. I doesn't seem like assumeTrue does that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, check is smart-cast friendly. however, we don't want test to fail if pre-condition is not satisfied, and assumeTrue will allow test to continue.

Speaking about this scenario, I think it is just easier to generate non-null message manually using @StringForgery fakeMessage: String, and then things will be simpler.

@fuzzybinary
fuzzybinary requested review from 0xnm and mariusc83 March 14, 2024 15:46
@fuzzybinary

Copy link
Copy Markdown
Member Author

@0xnm / @mariusc83 Added stopResourceWithError fingerprinting. Can I get a re-review?

writer: DataWriter<Any>
) {
attributes.putAll(GlobalRumMonitor.get(sdkCore).getAttributes())
val errorFingerprint = attributes.remove(RumAttributes.ERROR_FINGERPRINT) as? String

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

probably we need also to mention it in the related API of RumMonitor

@fuzzybinary
fuzzybinary force-pushed the jward/RUM-2907-error-fingerprint branch from 9c2fb7d to 68b3fc8 Compare March 14, 2024 18:51
@fuzzybinary
fuzzybinary merged commit 30a864b into develop Mar 14, 2024
@fuzzybinary
fuzzybinary deleted the jward/RUM-2907-error-fingerprint branch March 14, 2024 20:47
@xgouchet xgouchet added this to the 2.7.0 milestone Apr 5, 2024
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.

6 participants