Expose Telemetry and addLongTask for internal use#983
Conversation
0041f01 to
121e55e
Compare
| var stack: String? = null | ||
| var kind: String? = null | ||
| throwable?.let { | ||
| stack = it.loggableStackTrace() | ||
| kind = it.javaClass.canonicalName ?: it.javaClass.simpleName | ||
| } | ||
| handleEvent(RumRawEvent.SendTelemetry(TelemetryType.ERROR, message, stack, kind)) |
There was a problem hiding this comment.
| var stack: String? = null | |
| var kind: String? = null | |
| throwable?.let { | |
| stack = it.loggableStackTrace() | |
| kind = it.javaClass.canonicalName ?: it.javaClass.simpleName | |
| } | |
| handleEvent(RumRawEvent.SendTelemetry(TelemetryType.ERROR, message, stack, kind)) | |
| val stack: String? = throwable?.loggableStackTrace() | |
| var kind: String? = throwable?.javaClass?.canonicalName ?: throwable?.javaClass?.simpleName | |
| handleEvent(RumRawEvent.SendTelemetry(TelemetryType.ERROR, message, stack, kind)) |
| @StringForgery kind: String | ||
| ) { | ||
| // Given | ||
| val proxy = _InternalProxy(GlobalRum.get() as? AdvancedRumMonitor) |
There was a problem hiding this comment.
| val proxy = _InternalProxy(GlobalRum.get() as? AdvancedRumMonitor) | |
| val proxy = _InternalProxy(rumMonitor.mockInstance) |
| @StringForgery message: String | ||
| ) { | ||
| // Given | ||
| val proxy = _InternalProxy(GlobalRum.get() as? AdvancedRumMonitor) |
There was a problem hiding this comment.
| val proxy = _InternalProxy(GlobalRum.get() as? AdvancedRumMonitor) | |
| val proxy = _InternalProxy(rumMonitor.mockInstance) |
| @StringForgery target: String | ||
| ) { | ||
| // Given | ||
| val proxy = _InternalProxy(GlobalRum.get() as? AdvancedRumMonitor) |
There was a problem hiding this comment.
You shouldn't rely on static/global states in your tests.
| val proxy = _InternalProxy(GlobalRum.get() as? AdvancedRumMonitor) | |
| val proxy = _InternalProxy(rumMonitor.mockInstance) |
| ) | ||
| class _InternalProxy { | ||
| class _TelemetryProxy { | ||
| private val telemetry: Telemetry = Telemetry() |
There was a problem hiding this comment.
we can also directly reference com.datadog.android.core.internal.utils.telemetry property I think (but in both cases the question of mocking for unit-tests arise).
There was a problem hiding this comment.
Do you think we should inject Telemetry instead?
There was a problem hiding this comment.
you can use default arguments in the constructor and provide them explicitly in the test.
| * | ||
| * @see _InternalProxy | ||
| */ | ||
| @JvmStatic |
There was a problem hiding this comment.
I don't think we need this annotation here, because this property is supposed to be called only by us, so no interop with Java is needed (both Flutter and RN use Kotlin for the native modules).
|
Given some things we found in the iOS PR, I've restructured this to separate the "core" internals (only telemetry at the moment) and RUM Internals. This simplifies testing as well as avoids some issues with lazy initializers having unwelcome side affects. |
660ef06 to
02e4afb
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #983 +/- ##
===========================================
- Coverage 83.08% 82.98% -0.10%
===========================================
Files 268 270 +2
Lines 9218 9241 +23
Branches 1485 1486 +1
===========================================
+ Hits 7658 7668 +10
- Misses 1152 1162 +10
- Partials 408 411 +3
🚀 New features to boost your workflow:
|
| @StringForgery message: String | ||
| ) { | ||
| // Given | ||
| val mockTelemetry = Mockito.mock(Telemetry::class.java) |
There was a problem hiding this comment.
nit: we can do import org.mockito.Mockito.mock and just use mock call directly without Mockito. prefix as it is done in the codebase.
| @StringForgery target: String | ||
| ) { | ||
| // Given | ||
| val proxy = _RumInternalProxy(rumMonitor.mockInstance) |
There was a problem hiding this comment.
we can simply mock<AdvancedRumMonitor>() here, don't think we need to use GlobalRumMonitorTestConfiguration.
We expose internal methods through the _InternalProxy class, which is documented for internal use, and the `_internal` static member on the Datadog object. We keep Telemetry and RUM as separate proxies, in case we have to split them as v2 takes shape. Exposing Telemetry requires adding a way for reporting errors that are not Throwable (for use in cross platform frameworks), so I modified the event to take `stack` and `kind` as strings instead.
043616a to
2242bdb
Compare
|
@0xnm updated and rebased on develop for a final review. |
What does this PR do?
This exposes some internal Datadog classes and methods for use by cross platform frameworks.
We expose internal methods through the _InternalProxy class, which is documented for internal use, and the
_internalstatic member on the Datadog object. We keep Telemetry and RUM as separate proxies, in case we have to split them as v2 takes shape.As part of exposing telemetry I also needed a way to report errors that are not Throwable, so I modified the event to replace the
throwablemember withstackandkind, and moved the creation of those strings farther up the chain (they were created on event write prior).Additional Notes
Please double check all my logic on the switch from
throwabletostackandkindReview checklist (to be filled by reviewers)