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

RUM-5176 [CP] Allow reporting RUM error in sync #2180

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

maxep
Copy link
Member

@maxep maxep commented Jan 24, 2025

What and why?

Cross-platform SDKs can report fatal errors before the native process crashes. However, RUM and the Core execute processing and write asynchronously, and the crash can suspend these executions, leading to the loss of the cross-platform error information.

We should let cross-platform SDKs to report error in sync, blocking the caller-thread.

How?

The change involve changes at different layers:

Core module

Add completion argument to Writer interface. The completion callback is called when the data is written to disk.

RUM Module

Add completionHandler property to RUMErrorCommand. The RUMViewScope calls the completion handler after writing the error event and the view update.

The RUM Monitor now expose a method to report an error with a completion handler, The method is exposed using the @_spi(Internal) attribute.

/// Adds RUM error to current RUM view.
/// 
/// - Parameters:
///   - error: the `Error` object. It will be used to infer error details.
///   - source: the origin of the error.
///   - attributes: custom attributes to attach to this error.
///   - completionHandler: A completion closure called when reporting the error is completed.
@_spi(Internal)
func addError(
    error: Error,
    source: RUMErrorSource,
    attributes: [AttributeKey: AttributeValue],
    completionHandler: @escaping CompletionHandler
)

Objc Module

The DDRUMMonitor now expose a _internal_sync_addError to report an error in sync. This method will wait for the underlying completion handler to be called before returning.

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
  • Add CHANGELOG entry for user facing changes
  • Add Objective-C interface for public APIs (see our guidelines [internal]) and run make api-surface)

@maxep maxep force-pushed the maxep/RUM-5176/sync-error branch from 9f9f963 to ab9a5a4 Compare January 24, 2025 15:25
@maxep maxep requested a review from 0xnm January 24, 2025 15:26
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jan 24, 2025

Datadog Report

Branch report: maxep/RUM-5176/sync-error
Commit report: 9c35df9
Test service: dd-sdk-ios

✅ 0 Failed, 930 Passed, 2819 Skipped, 53.72s Total duration (1m 37.66s time saved)

@maxep maxep force-pushed the maxep/RUM-5176/sync-error branch from ab9a5a4 to 4cc5952 Compare January 24, 2025 16:19
@maxep maxep marked this pull request as ready for review January 24, 2025 16:48
@maxep maxep requested review from a team as code owners January 24, 2025 16:48
@maxep maxep changed the title RUM-5176 [CP] Allow reporting error in sync RUM-5176 [CP] Allow reporting RUM error in sync Jan 24, 2025
@maxep maxep force-pushed the maxep/RUM-5176/sync-error branch from 4cc5952 to cdd9251 Compare January 24, 2025 17:23
simaoseica-dd
simaoseica-dd previously approved these changes Jan 27, 2025
Copy link
Contributor

@simaoseica-dd simaoseica-dd left a comment

Choose a reason for hiding this comment

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

Great job. Just some questions

@@ -78,6 +78,9 @@ - (void)testDDRUMMonitorAPI {
[monitor addAttributeForKey:@"" value:@""];
[monitor addFeatureFlagEvaluationWithName: @"name" value: @"value"];

[monitor _internal_sync_addError:[NSError errorWithDomain:NSCocoaErrorDomain code:-100 userInfo:nil]
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Can you create a mock out of this error? It will also adds meaning to it

/// No-op completion function.
///
/// Using a function prevent allocating a closure when applying a placeholder.
public func NOPCompletionHandler() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Why is a NOP completion handler needed to avoid optionality? It’s common to encounter optional completion handlers

mariedm
mariedm previously approved these changes Feb 3, 2025
Copy link
Member

@mariedm mariedm left a comment

Choose a reason for hiding this comment

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

Well done! 🙌 And nice PR description.

DatadogInternal/Sources/Storage/Writer.swift Outdated Show resolved Hide resolved
}

extension RUMMonitorProtocol {
/// It cannot be declared '@_spi' without a default implementation in a protocol extension
func addViewLoadingTime(overwrite: Bool) {
// no-op
}

/// It cannot be declared '@_spi' without a default implementation in a protocol extension
Copy link
Member

Choose a reason for hiding this comment

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

😮

@maxep maxep dismissed stale reviews from mariedm and simaoseica-dd via 9c35df9 February 3, 2025 09:23
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