Skip to content

Commit

Permalink
Merge pull request #149 from DataDog/xgouchet/RUMM-255_traces_content…
Browse files Browse the repository at this point in the history
…_type

RUMM-255 traces content type
  • Loading branch information
xgouchet authored Feb 25, 2020
2 parents 61855a6 + 7e13ab7 commit 78962f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import okhttp3.RequestBody

internal abstract class DataOkHttpUploader(
private var url: String,
private val client: OkHttpClient
private val client: OkHttpClient,
internal val contentType: String = CONTENT_TYPE_JSON
) : DataUploader {

// region LogUploader
Expand Down Expand Up @@ -51,7 +52,7 @@ internal abstract class DataOkHttpUploader(
private fun headers(): MutableMap<String, String> {
return mutableMapOf(
HEADER_UA to userAgent,
HEADER_CT to CONTENT_TYPE
HEADER_CT to contentType
)
}

Expand All @@ -66,12 +67,13 @@ internal abstract class DataOkHttpUploader(
}

private fun buildRequest(data: ByteArray): Request {
sdkLogger.d("$TAG: Sending data to $url")
sdkLogger.d("$TAG: Sending data to POST $url")
val builder = Request.Builder()
.url(url)
.post(RequestBody.create(null, data))
headers().forEach {
builder.addHeader(it.key, it.value)
sdkLogger.d("$TAG: ${it.key}: ${it.value}")
}
return builder.build()
}
Expand All @@ -90,10 +92,13 @@ internal abstract class DataOkHttpUploader(
// endregion

companion object {
internal const val CONTENT_TYPE_JSON = "application/json"
internal const val CONTENT_TYPE_TEXT_UTF8 = "text/plain;charset=UTF-8"

private const val HEADER_CT = "Content-Type"
private const val CONTENT_TYPE = "application/json"
private const val HEADER_UA = "User-Agent"
const val SYSTEM_UA = "http.agent"

private const val TAG = "DataOkHttpUploader"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class SpanSerializer(
jsonObject.addProperty(TAG_DURATION, model.durationNano)
jsonObject.addProperty(TAG_START_TIMESTAMP, model.startTime + serverOffset)
jsonObject.addProperty(TAG_ERROR, if (model.isError) 1 else 0)
jsonObject.addProperty(TAG_TYPE, "object") // do not know yet what should be here
jsonObject.addProperty(TAG_TYPE, "custom")
addMeta(jsonObject, model)
addMetrics(jsonObject, model)
return jsonObject.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal open class TracesOkHttpUploader(
endpoint: String,
private val token: String,
client: OkHttpClient
) : DataOkHttpUploader(buildUrl(endpoint, token), client) {
) : DataOkHttpUploader(buildUrl(endpoint, token), client, CONTENT_TYPE_TEXT_UTF8) {

// region DataOkHttpUploader

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ internal abstract class DataOkHttpUploaderTest<T : DataOkHttpUploader> {

fun assertHeaders(request: RecordedRequest) {
assertThat(request.getHeader("Content-Type"))
.isEqualTo("application/json")
.isEqualTo(testedUploader.contentType)
val expectedUserAgent = if (fakeUserAgent.isBlank()) {
"Datadog/${BuildConfig.VERSION_NAME} " +
"(Linux; U; Android ${Build.VERSION.RELEASE}; " +
Expand Down

0 comments on commit 78962f7

Please sign in to comment.