Skip to content

Commit eebab6b

Browse files
authored
Merge pull request #3062 from DataDog/feature/cronet
Rum Resources instrumentation support for Cronet network library.
2 parents 3f25b26 + 0177dae commit eebab6b

File tree

71 files changed

+5484
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+5484
-165
lines changed

LICENSE-3rdparty.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import,com.benasher44,MIT,"Copyright (c) 2019 Ben Asher"
5050
import,com.github.bumptech.glide,"BSD 3-Clause","Copyright 2014 Google, Inc. All rights reserved, Copyright (c) 2013. Bump Technologies Inc. All Rights Reserved."
5151
import,com.facebook.fresco,MIT,"Copyright (c) Facebook, Inc. and its affiliates"
5252
import,com.github.spotbugs,"GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1","Copyright (C) 1991, 1999 Free Software Foundation, Inc."
53+
import,com.google.android.gms,Apache-2.0,Copyright 2018 The Android Open Source Project
5354
import,com.google.android.material,Apache-2.0,Copyright 2018 The Android Open Source Project
5455
import,com.google.code.gson,Apache-2.0,Copyright 2008 Google Inc
5556
import,com.google.guava,Apache-2.0,Copyright 2009 The Guava Authors
@@ -70,6 +71,7 @@ import,io.reactivex.rxjava3.android,Apache-2.0,Copyright 2015 The RxAndroid auth
7071
import,org.jetbrains,Apache-2.0,Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors
7172
import,org.jetbrains.kotlin,Apache-2.0,Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors
7273
import,org.jetbrains.kotlinx,Apache-2.0,Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors
74+
import,org.chromium.net,Apache-2.0,"Copyright 2015 The Chromium Authors"
7375
import,org.reactivestreams,CC0,Copyright 2014 Reactive Streams
7476
import(test),androidx.autofill,Apache-2.0,Copyright 2018 The Android Open Source Project
7577
import(test),androidx.concurrent,Apache-2.0,Copyright 2018 The Android Open Source Project

ci/pipelines/default-pipeline.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ analysis:detekt-custom:
115115
- ./gradlew :features:dd-sdk-android-webview:customDetektRules
116116
- ./gradlew :integrations:dd-sdk-android-coil:customDetektRules
117117
- ./gradlew :integrations:dd-sdk-android-compose:customDetektRules
118+
- ./gradlew :integrations:dd-sdk-android-cronet:customDetektRules
118119
- ./gradlew :integrations:dd-sdk-android-fresco:customDetektRules
119120
- ./gradlew :integrations:dd-sdk-android-glide:customDetektRules
120121
- ./gradlew :integrations:dd-sdk-android-okhttp:customDetektRules
@@ -788,6 +789,23 @@ publish:release-compose:
788789
paths:
789790
- integrations/dd-sdk-android-compose/verification-metadata.xml
790791

792+
publish:release-cronet:
793+
tags: [ "arch:amd64" ]
794+
only:
795+
- tags
796+
- develop
797+
image: $CI_IMAGE_DOCKER
798+
stage: publish
799+
timeout: 30m
800+
script:
801+
- !reference [.snippets, set-publishing-credentials]
802+
- ./gradlew :integrations:dd-sdk-android-cronet:publishToSonatype closeSonatypeStagingRepository --stacktrace --no-daemon
803+
artifacts:
804+
when: on_success
805+
expire_in: 7 days
806+
paths:
807+
- integrations/dd-sdk-android-cronet/verification-metadata.xml
808+
791809
publish:release-fresco:
792810
tags: [ "arch:amd64" ]
793811
only:
@@ -1089,6 +1107,7 @@ notify:merge-verification-metadata:
10891107
- publish:release-webview
10901108
- publish:release-coil
10911109
- publish:release-compose
1110+
- publish:release-cronet
10921111
- publish:release-fresco
10931112
- publish:release-glide
10941113
- publish:release-trace-coroutines

dd-sdk-android-core/api/apiSurface

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ interface com.datadog.android.api.feature.FeatureSdkCore : com.datadog.android.a
147147
interface com.datadog.android.api.feature.StorageBackedFeature : Feature
148148
val requestFactory: com.datadog.android.api.net.RequestFactory
149149
val storageConfiguration: com.datadog.android.api.storage.FeatureStorageConfiguration
150+
interface com.datadog.android.api.instrumentation.network.ExtendedRequestInfo
151+
fun <T> tag(Class<T>): T?
152+
fun <T> HttpRequestInfo.tag(Class<T>): T?
153+
interface com.datadog.android.api.instrumentation.network.HttpRequestInfo
154+
val url: String
155+
val headers: Map<String, List<String>>
156+
val contentType: String?
157+
val method: String
158+
fun contentLength(): Long?
159+
interface com.datadog.android.api.instrumentation.network.HttpResponseInfo
160+
val url: String
161+
val statusCode: Int
162+
val headers: Map<String, List<String>>
163+
val contentType: String?
164+
val contentLength: Long?
150165
data class com.datadog.android.api.net.Request
151166
constructor(String, String, String, Map<String, String>, ByteArray, String? = null)
152167
data class com.datadog.android.api.net.RequestExecutionContext
@@ -291,6 +306,29 @@ interface com.datadog.android.core.internal.net.FirstPartyHostHeaderTypeResolver
291306
fun headerTypesForUrl(okhttp3.HttpUrl): Set<com.datadog.android.trace.TracingHeaderType>
292307
fun getAllHeaderTypes(): Set<com.datadog.android.trace.TracingHeaderType>
293308
fun isEmpty(): Boolean
309+
object com.datadog.android.core.internal.net.HttpSpec
310+
object Method
311+
const val GET: String
312+
const val POST: String
313+
const val PATCH: String
314+
const val PUT: String
315+
const val HEAD: String
316+
const val DELETE: String
317+
const val TRACE: String
318+
const val OPTIONS: String
319+
const val CONNECT: String
320+
fun values()
321+
object Headers
322+
const val CONTENT_TYPE: String
323+
const val CONTENT_LENGTH: String
324+
const val WEBSOCKET_ACCEPT_HEADER: String
325+
object ContentType
326+
const val TEXT_PLAIN: String
327+
const val TEXT_EVENT_STREAM: String
328+
const val APPLICATION_GRPC: String
329+
const val APPLICATION_GRPC_PROTO: String
330+
const val APPLICATION_GRPC_JSON: String
331+
fun isStream(String?): Boolean
294332
interface com.datadog.android.core.internal.persistence.Deserializer<P: Any, R: Any>
295333
fun deserialize(P): R?
296334
fun java.io.File.canReadSafe(com.datadog.android.api.InternalLogger): Boolean

dd-sdk-android-core/api/dd-sdk-android-core.api

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,30 @@ public abstract interface class com/datadog/android/api/feature/StorageBackedFea
443443
public abstract fun getStorageConfiguration ()Lcom/datadog/android/api/storage/FeatureStorageConfiguration;
444444
}
445445

446+
public abstract interface class com/datadog/android/api/instrumentation/network/ExtendedRequestInfo {
447+
public abstract fun tag (Ljava/lang/Class;)Ljava/lang/Object;
448+
}
449+
450+
public final class com/datadog/android/api/instrumentation/network/ExtendedRequestInfoKt {
451+
public static final fun tag (Lcom/datadog/android/api/instrumentation/network/HttpRequestInfo;Ljava/lang/Class;)Ljava/lang/Object;
452+
}
453+
454+
public abstract interface class com/datadog/android/api/instrumentation/network/HttpRequestInfo {
455+
public abstract fun contentLength ()Ljava/lang/Long;
456+
public abstract fun getContentType ()Ljava/lang/String;
457+
public abstract fun getHeaders ()Ljava/util/Map;
458+
public abstract fun getMethod ()Ljava/lang/String;
459+
public abstract fun getUrl ()Ljava/lang/String;
460+
}
461+
462+
public abstract interface class com/datadog/android/api/instrumentation/network/HttpResponseInfo {
463+
public abstract fun getContentLength ()Ljava/lang/Long;
464+
public abstract fun getContentType ()Ljava/lang/String;
465+
public abstract fun getHeaders ()Ljava/util/Map;
466+
public abstract fun getStatusCode ()I
467+
public abstract fun getUrl ()Ljava/lang/String;
468+
}
469+
446470
public final class com/datadog/android/api/net/Request {
447471
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;[BLjava/lang/String;)V
448472
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;[BLjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
@@ -798,6 +822,41 @@ public abstract interface class com/datadog/android/core/internal/net/FirstParty
798822
public abstract fun isFirstPartyUrl (Lokhttp3/HttpUrl;)Z
799823
}
800824

825+
public final class com/datadog/android/core/internal/net/HttpSpec {
826+
public static final field INSTANCE Lcom/datadog/android/core/internal/net/HttpSpec;
827+
}
828+
829+
public final class com/datadog/android/core/internal/net/HttpSpec$ContentType {
830+
public static final field APPLICATION_GRPC Ljava/lang/String;
831+
public static final field APPLICATION_GRPC_JSON Ljava/lang/String;
832+
public static final field APPLICATION_GRPC_PROTO Ljava/lang/String;
833+
public static final field INSTANCE Lcom/datadog/android/core/internal/net/HttpSpec$ContentType;
834+
public static final field TEXT_EVENT_STREAM Ljava/lang/String;
835+
public static final field TEXT_PLAIN Ljava/lang/String;
836+
public final fun isStream (Ljava/lang/String;)Z
837+
}
838+
839+
public final class com/datadog/android/core/internal/net/HttpSpec$Headers {
840+
public static final field CONTENT_LENGTH Ljava/lang/String;
841+
public static final field CONTENT_TYPE Ljava/lang/String;
842+
public static final field INSTANCE Lcom/datadog/android/core/internal/net/HttpSpec$Headers;
843+
public static final field WEBSOCKET_ACCEPT_HEADER Ljava/lang/String;
844+
}
845+
846+
public final class com/datadog/android/core/internal/net/HttpSpec$Method {
847+
public static final field CONNECT Ljava/lang/String;
848+
public static final field DELETE Ljava/lang/String;
849+
public static final field GET Ljava/lang/String;
850+
public static final field HEAD Ljava/lang/String;
851+
public static final field INSTANCE Lcom/datadog/android/core/internal/net/HttpSpec$Method;
852+
public static final field OPTIONS Ljava/lang/String;
853+
public static final field PATCH Ljava/lang/String;
854+
public static final field POST Ljava/lang/String;
855+
public static final field PUT Ljava/lang/String;
856+
public static final field TRACE Ljava/lang/String;
857+
public final fun values ()Ljava/util/List;
858+
}
859+
801860
public abstract interface class com/datadog/android/core/internal/persistence/Deserializer {
802861
public abstract fun deserialize (Ljava/lang/Object;)Ljava/lang/Object;
803862
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2016-Present Datadog, Inc.
5+
*/
6+
package com.datadog.android.api.instrumentation.network
7+
8+
/**
9+
* This interface indicates that the request supports non HTTP-specified methods.
10+
*/
11+
interface ExtendedRequestInfo {
12+
13+
/**
14+
* Returns the tag attached with type as a key, or null if no tag is attached with that key.
15+
*/
16+
fun <T> tag(type: Class<out T>): T?
17+
}
18+
19+
/**
20+
* Returns the tag attached with type as a key, or null if no tag is attached with that key.
21+
*/
22+
fun <T> HttpRequestInfo.tag(type: Class<out T>): T? = if (this is ExtendedRequestInfo) this.tag(type) else null
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2016-Present Datadog, Inc.
5+
*/
6+
package com.datadog.android.api.instrumentation.network
7+
8+
/**
9+
* Represents information about an HTTP request.
10+
*/
11+
interface HttpRequestInfo {
12+
/**
13+
* The URL associated with the HTTP request.
14+
*/
15+
val url: String
16+
17+
/**
18+
* Represents the HTTP headers associated with the request.
19+
*/
20+
val headers: Map<String, List<String>>
21+
22+
/**
23+
* The MIME type of the payload associated with the HTTP request or response, represented
24+
* as a string. Can be null if the content type is unspecified.
25+
*/
26+
val contentType: String?
27+
28+
/**
29+
* Represents the HTTP method associated with the request.
30+
*/
31+
val method: String
32+
33+
/**
34+
* Retrieves the content length of the HTTP request.
35+
*
36+
* @return the length of the content in bytes, or null if the content length is unavailable.
37+
*/
38+
fun contentLength(): Long?
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2016-Present Datadog, Inc.
5+
*/
6+
package com.datadog.android.api.instrumentation.network
7+
8+
/**
9+
* Represents information about an HTTP response.
10+
*/
11+
interface HttpResponseInfo {
12+
/**
13+
* Represents the URL associated with an HTTP response.
14+
*/
15+
val url: String
16+
17+
/**
18+
* Represents the HTTP status code associated with the response.
19+
*/
20+
val statusCode: Int
21+
22+
/**
23+
* Represents the HTTP headers associated with a response.
24+
*/
25+
val headers: Map<String, List<String>>
26+
27+
/**
28+
* Represents the MIME type of the payload associated with an HTTP response.
29+
*/
30+
val contentType: String?
31+
32+
/**
33+
* Retrieves the content length from the response information.
34+
*
35+
* @return the content length as a Long if available, or null if it cannot be determined.
36+
*/
37+
val contentLength: Long?
38+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2016-Present Datadog, Inc.
5+
*/
6+
package com.datadog.android.core.internal.net
7+
8+
import com.datadog.android.lint.InternalApi
9+
10+
/**
11+
* HTTP specification constants and utilities.
12+
*/
13+
@InternalApi
14+
object HttpSpec {
15+
16+
/**
17+
* Standard HTTP request methods.
18+
*/
19+
object Method {
20+
/** HTTP GET method. */
21+
const val GET: String = "GET"
22+
23+
/** HTTP POST method. */
24+
const val POST: String = "POST"
25+
26+
/** HTTP PATCH method. */
27+
const val PATCH: String = "PATCH"
28+
29+
/** HTTP PUT method. */
30+
const val PUT: String = "PUT"
31+
32+
/** HTTP HEAD method. */
33+
const val HEAD: String = "HEAD"
34+
35+
/** HTTP DELETE method. */
36+
const val DELETE: String = "DELETE"
37+
38+
/** HTTP TRACE method. */
39+
const val TRACE: String = "TRACE"
40+
41+
/** HTTP OPTIONS method. */
42+
const val OPTIONS: String = "OPTIONS"
43+
44+
/** HTTP CONNECT method. */
45+
const val CONNECT: String = "CONNECT"
46+
47+
/**
48+
* Returns a list of all HTTP methods.
49+
*/
50+
fun values() = listOf(GET, POST, PATCH, PUT, HEAD, DELETE, TRACE, OPTIONS, CONNECT)
51+
}
52+
53+
/**
54+
* Standard HTTP header names.
55+
*/
56+
object Headers {
57+
/** Content-Type header name. */
58+
const val CONTENT_TYPE: String = "Content-Type"
59+
60+
/** Content-Length header name. */
61+
const val CONTENT_LENGTH: String = "Content-Length"
62+
63+
/** Sec-WebSocket-Accept header name. */
64+
const val WEBSOCKET_ACCEPT_HEADER: String = "Sec-WebSocket-Accept"
65+
}
66+
67+
/**
68+
* HTTP content type values and utilities.
69+
*/
70+
object ContentType {
71+
72+
/** Plain text content type. */
73+
const val TEXT_PLAIN: String = "text/plain"
74+
75+
/** Server-Sent Events content type. */
76+
const val TEXT_EVENT_STREAM: String = "text/event-stream"
77+
78+
/** gRPC content type. */
79+
const val APPLICATION_GRPC: String = "application/grpc"
80+
81+
/** gRPC with Protocol Buffers content type. */
82+
const val APPLICATION_GRPC_PROTO: String = "application/grpc+proto"
83+
84+
/** gRPC with JSON content type. */
85+
const val APPLICATION_GRPC_JSON: String = "application/grpc+json"
86+
87+
/**
88+
* Checks if the given content type represents a streaming protocol.
89+
* @param contentType the content type to check
90+
* @return true if the content type is a stream type, false otherwise
91+
*/
92+
fun isStream(contentType: String?): Boolean {
93+
return contentType != null && contentType in STREAM_CONTENT_TYPES
94+
}
95+
96+
private val STREAM_CONTENT_TYPES = setOf(
97+
TEXT_EVENT_STREAM,
98+
APPLICATION_GRPC,
99+
APPLICATION_GRPC_PROTO,
100+
APPLICATION_GRPC_JSON
101+
)
102+
}
103+
}

0 commit comments

Comments
 (0)