Skip to content

Commit 93c2b65

Browse files
committed
RUM-10191 Report resource with size 0
1 parent 0933d54 commit 93c2b65

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

integrations/dd-sdk-android-okhttp/src/main/kotlin/com/datadog/android/okhttp/DatadogInterceptor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ open class DatadogInterceptor internal constructor(
428428

429429
private fun ResponseBody.contentLengthOrNull(): Long? {
430430
return contentLength().let {
431-
if (it <= 0L) null else it
431+
if (it < 0L) null else it
432432
}
433433
}
434434

integrations/dd-sdk-android-okhttp/src/test/kotlin/com/datadog/android/okhttp/DatadogInterceptorTest.kt

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,49 @@ internal class DatadogInterceptorTest : TracingInterceptorNotSendingSpanTest() {
221221
}
222222
}
223223

224+
@Test
225+
fun `M start and stop RUM Resource W intercept() {successful request, empty response}`(
226+
@IntForgery(min = 200, max = 300) statusCode: Int
227+
) {
228+
// Given
229+
fakeResponseBody = ""
230+
stubChain(mockChain, statusCode)
231+
val expectedStartAttrs = emptyMap<String, Any?>()
232+
val expectedStopAttrs = mapOf(
233+
RumAttributes.TRACE_ID to fakeTraceIdAsString,
234+
RumAttributes.SPAN_ID to fakeSpanId,
235+
RumAttributes.RULE_PSR to fakeTracingSampleRate / 100
236+
) + fakeAttributes
237+
val mimeType = fakeMediaType?.type
238+
val kind = when {
239+
mimeType != null -> RumResourceKind.fromMimeType(mimeType)
240+
else -> RumResourceKind.NATIVE
241+
}
242+
243+
// When
244+
testedInterceptor.intercept(mockChain)
245+
246+
// Then
247+
inOrder(rumMonitor.mockInstance) {
248+
argumentCaptor<ResourceId> {
249+
verify(rumMonitor.mockInstance).startResource(
250+
capture(),
251+
eq(fakeMethod),
252+
eq(fakeUrl),
253+
eq(expectedStartAttrs)
254+
)
255+
verify(rumMonitor.mockInstance).stopResource(
256+
capture(),
257+
eq(statusCode),
258+
eq(0L),
259+
eq(kind),
260+
eq(expectedStopAttrs)
261+
)
262+
assertThat(firstValue).isEqualTo(secondValue)
263+
}
264+
}
265+
}
266+
224267
@Test
225268
fun `M start and stop RUM Resource W intercept() {successful streaming request}`(
226269
@IntForgery(min = 200, max = 300) statusCode: Int,
@@ -441,7 +484,7 @@ internal class DatadogInterceptorTest : TracingInterceptorNotSendingSpanTest() {
441484
verify(rumMonitor.mockInstance).stopResource(
442485
capture(),
443486
eq(statusCode),
444-
eq(null),
487+
eq(0L),
445488
eq(kind),
446489
eq(expectedStopAttrs)
447490
)
@@ -538,7 +581,7 @@ internal class DatadogInterceptorTest : TracingInterceptorNotSendingSpanTest() {
538581
verify(rumMonitor.mockInstance).stopResource(
539582
capture(),
540583
eq(statusCode),
541-
eq(null),
584+
eq(0L),
542585
eq(kind),
543586
eq(expectedStopAttrs)
544587
)
@@ -596,8 +639,7 @@ internal class DatadogInterceptorTest : TracingInterceptorNotSendingSpanTest() {
596639

597640
@Test
598641
fun `M start and stop RUM Resource W intercept() {successful request throwing response}`(
599-
@IntForgery(min = 200, max = 300) statusCode: Int,
600-
forge: Forge
642+
@IntForgery(min = 200, max = 300) statusCode: Int
601643
) {
602644
// Given
603645
stubChain(mockChain) {
@@ -610,7 +652,7 @@ internal class DatadogInterceptorTest : TracingInterceptorNotSendingSpanTest() {
610652
.body(object : ResponseBody() {
611653
override fun contentType(): MediaType? = fakeMediaType
612654

613-
override fun contentLength(): Long = forge.anElementFrom(0, -1)
655+
override fun contentLength(): Long = -1L
614656

615657
override fun source(): BufferedSource {
616658
val buffer = Buffer()
@@ -659,8 +701,7 @@ internal class DatadogInterceptorTest : TracingInterceptorNotSendingSpanTest() {
659701

660702
@Test
661703
fun `M start and stop RUM Resource W intercept() {success request throwing response + !smp}`(
662-
@IntForgery(min = 200, max = 300) statusCode: Int,
663-
forge: Forge
704+
@IntForgery(min = 200, max = 300) statusCode: Int
664705
) {
665706
// Given
666707
whenever(mockTraceSampler.sample(any())).thenReturn(false)
@@ -674,7 +715,7 @@ internal class DatadogInterceptorTest : TracingInterceptorNotSendingSpanTest() {
674715
.body(object : ResponseBody() {
675716
override fun contentType(): MediaType? = fakeMediaType
676717

677-
override fun contentLength(): Long = forge.anElementFrom(0, -1)
718+
override fun contentLength(): Long = -1
678719

679720
override fun source(): BufferedSource {
680721
val buffer = Buffer()

0 commit comments

Comments
 (0)