Skip to content

Using deferred Analytics with Crashlytics. #2555

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

Merged
merged 9 commits into from
Apr 19, 2021
Merged

Using deferred Analytics with Crashlytics. #2555

merged 9 commits into from
Apr 19, 2021

Conversation

rlazo
Copy link
Collaborator

@rlazo rlazo commented Mar 30, 2021

No description provided.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 30, 2021

Coverage Report

Affected SDKs

  • firebase-crashlytics

    SDK overall coverage did not change between base commit (129d7e5) and head commit (ebdf28f3). However there are changes in individual files.

    Filename Base (129d7e5) Head (ebdf28f3) Diff
    AnalyticsDeferredProxy.java ? 0.00% ?

Test Logs

Notes

HTML coverage reports can be produced locally with ./gradlew <product>:checkCoverage.
Report files are located at <product-build-dir>/reports/jacoco/.

Head commit (ebdf28f3) is created by Prow via merging commits: 129d7e5 2c0c76c.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 30, 2021

Binary Size Report

Affected SDKs

  • firebase-crashlytics

    Type Base (129d7e5) Head (ebdf28f3) Diff
    aar 325 kB 328 kB +3.21 kB (+1.0%)
    apk (aggressive) 192 kB 193 kB +804 B (+0.4%)
    apk (release) 818 kB 819 kB +588 B (+0.1%)

Test Logs

Notes

Head commit (ebdf28f3) is created by Prow via merging commits: 129d7e5 2c0c76c.

import java.util.concurrent.TimeUnit;

/** @hide */
public class AnalyticsDeferredComponents {
Copy link
Member

Choose a reason for hiding this comment

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

Unless I am missing something, it looks like we have 2 classes that depend on the connector:

  1. BreadcrumbSource
  2. AnalyticsEventLogger

I wonder if it would be cleaner to have separate implementations for both of them that depend on Deferred<AnalyticsConnector> as opposed to having them exposed through getters of this class. This would achieve 2 things:

  1. reduce coupling since all dependent classes won't have to depend on this "components" class with getters[1]
  2. Would make it easier to achieve thread safety in both classes, which your current implementation does not seem to be.

[1] https://en.wikipedia.org/wiki/Law_of_Demeter

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since both objects that depend on the deferred objects are interfaces in Crashlytics , I've addressed your comment as follows:

  1. Created new "proxy" implementations of the interfaces, these implementations are inner classes to the AnalyticsDeferredComponent object.
  2. These proxy objects simply channel any calls to the actual implementing object in the AnalyticsDeferredComponent object.
  3. The AnalyticsDeferredComponent by default creates 2 objects which are the default implementations Crashlytics use when there's no AnalyticsConnector present.
  4. When the AnalyticsConnector becomes available, we switch the default implementation objects with new ones that use Analytics.

This is transparent to any other objects using BreadcrumbSource and AnalyticsEventLogger since the proxy implementations will switch to the right objects cleanly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PTAL

Comment on lines 105 to 108
// Set the breadcrumb event receiver as the breadcrumb source for Crashlytics.
breadcrumbSource = breadcrumbReceiver;
// Set the blocking analytics event logger for Crashlytics.
analyticsEventLogger = blockingAnalyticsEventLogger;
Copy link
Member

Choose a reason for hiding this comment

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

This does not look thread-safe, i.e. other threads may never see these writes

@rlazo rlazo requested a review from davidmotson March 31, 2021 17:33
@rlazo rlazo requested a review from vkryachko April 7, 2021 00:08
Copy link
Member

@vkryachko vkryachko left a comment

Choose a reason for hiding this comment

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

LGTM

@vkryachko vkryachko self-requested a review April 7, 2021 19:43
@rlazo rlazo marked this pull request as ready for review April 7, 2021 20:49
@rlazo
Copy link
Collaborator Author

rlazo commented Apr 7, 2021

/retest

@rlazo rlazo requested review from mrichards and mrober April 8, 2021 17:33
@rlazo
Copy link
Collaborator Author

rlazo commented Apr 12, 2021

/test device-check-changed

@rlazo rlazo merged commit 2cc1cc4 into master Apr 19, 2021
@rlazo rlazo deleted the rl.crash_dyn branch April 19, 2021 17:56
@firebase firebase locked and limited conversation to collaborators May 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Override cla size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants