Skip to content

RUM-2558: Let AndroidTracer.logErrorMessage() send an ERROR log#2605

Merged
aleksandr-gringauz merged 1 commit into
developfrom
aleksandr-gringauz/rum-2558/androidtracer-logerrormessage-error-log-2
Apr 17, 2025
Merged

RUM-2558: Let AndroidTracer.logErrorMessage() send an ERROR log#2605
aleksandr-gringauz merged 1 commit into
developfrom
aleksandr-gringauz/rum-2558/androidtracer-logerrormessage-error-log-2

Conversation

@aleksandr-gringauz

@aleksandr-gringauz aleksandr-gringauz commented Apr 16, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes AndroidTracer.logErrorMessage create a log with ERROR severity that is attached to the span.

demo

I discussed with Xavier that we shouldn't make the span itself have an error state, just change the log severity.

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

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)

@aleksandr-gringauz
aleksandr-gringauz force-pushed the aleksandr-gringauz/rum-2558/androidtracer-logerrormessage-error-log-2 branch from 4646b02 to 76b4133 Compare April 16, 2025 15:16
@aleksandr-gringauz
aleksandr-gringauz marked this pull request as ready for review April 16, 2025 15:21
@aleksandr-gringauz
aleksandr-gringauz requested review from a team as code owners April 16, 2025 15:21
@codecov-commenter

codecov-commenter commented Apr 16, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.02%. Comparing base (72376a1) to head (3af91fa).
⚠️ Report is 2162 commits behind head on develop.

Files with missing lines Patch % Lines
.../trace/internal/handlers/AndroidSpanLogsHandler.kt 33.33% 0 Missing and 2 partials ⚠️
...in/com/datadog/android/log/internal/LogsFeature.kt 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2605      +/-   ##
===========================================
+ Coverage    69.98%   70.02%   +0.04%     
===========================================
  Files          819      819              
  Lines        30579    30559      -20     
  Branches      5121     5120       -1     
===========================================
- Hits         21399    21397       -2     
+ Misses        7740     7738       -2     
+ Partials      1440     1424      -16     
Files with missing lines Coverage Δ
.../kotlin/com/datadog/android/trace/AndroidTracer.kt 95.74% <100.00%> (ø)
...c/main/kotlin/com/datadog/android/trace/SpanExt.kt 88.24% <ø> (ø)
...in/com/datadog/android/log/internal/LogsFeature.kt 85.34% <50.00%> (-1.61%) ⬇️
.../trace/internal/handlers/AndroidSpanLogsHandler.kt 84.31% <33.33%> (-3.44%) ⬇️

... and 33 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

/**
* Helper method to attach an error message to a specific Span.
* The error message will be added to the provided Span as a standard Error Tag.
* The error message will be logged with ERROR severity and can be seen in logs attached to the span.

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.

in facets it is called status

Suggested change
* The error message will be logged with ERROR severity and can be seen in logs attached to the span.
* The error message will be logged with ERROR status and can be seen in logs attached to the span.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

now I use "status" everywhere

/**
* Helper method to attach an error message to this [Span].
* The error message will be added to this [Span] as a standard Error Tag.
* The error message will be logged with ERROR severity and can be seen in logs attached to the span.

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
* The error message will be logged with ERROR severity and can be seen in logs attached to the span.
* The error message will be logged with ERROR status and can be seen in logs attached to the span.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

now I use "status" everywhere

@JvmStatic
fun logErrorMessage(span: Span, message: String) {
val fieldsMap = mapOf(Fields.MESSAGE to message)
val fieldsMap = mapOf(Fields.MESSAGE to message, "severity" to Log.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.

we need to call this either level (user in codebase) or status (facet name) and also extract it as a constant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

now I use "status" everywhere

timestampMicroseconds: Long? = null
) {
val logsFeature = sdkCore.getFeature(Feature.LOGS_FEATURE_NAME)
val spanLogSeverity = fields["severity"] as? Int

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.

we need to remove this from the attributes, since it is a technical property which shouldn't end in the list of the user attributes

Suggested change
val spanLogSeverity = fields["severity"] as? Int
val spanLogSeverity = fields.remove("severity") as? Int

also we need to rename it from severity

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for spotting this

  1. renamed to "status"
  2. now I remove it from the fields

verify(mockSpan).log(capture())
assertThat(firstValue)
.containsEntry(Fields.MESSAGE, anErrorMessage)
.containsOnlyKeys(Fields.MESSAGE)

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.

we need to put this assertion back as well. Basically we want to assert that there are only 2 keys.

Same for the similar tests below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for spotting it

fixed

@aleksandr-gringauz
aleksandr-gringauz force-pushed the aleksandr-gringauz/rum-2558/androidtracer-logerrormessage-error-log-2 branch from 76b4133 to 997a4c9 Compare April 17, 2025 08:13
@aleksandr-gringauz
aleksandr-gringauz force-pushed the aleksandr-gringauz/rum-2558/androidtracer-logerrormessage-error-log-2 branch from 997a4c9 to 3af91fa Compare April 17, 2025 08:42
@aleksandr-gringauz
aleksandr-gringauz merged commit 5506381 into develop Apr 17, 2025
@aleksandr-gringauz
aleksandr-gringauz deleted the aleksandr-gringauz/rum-2558/androidtracer-logerrormessage-error-log-2 branch April 17, 2025 11:11
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.

3 participants