Skip to content

Commit

Permalink
Fix benchmarking metrics data upload request issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ambushwork committed Sep 3, 2024
1 parent 87cc448 commit 5da01c1
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.datadog.benchmark.internal.model.SpanEvent
import io.opentelemetry.sdk.metrics.data.MetricData
import okhttp3.CacheControl
import okhttp3.Call
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
Expand Down Expand Up @@ -41,7 +42,8 @@ internal class DatadogHttpClient(
operationName = OPERATION_NAME_METRICS,
url = exporterConfiguration.endPoint.metricUrl(),
exporterConfiguration = exporterConfiguration,
metricRequestBodyBuilder.build(metrics)
metricRequestBodyBuilder.build(metrics),
mediaType = CONTENT_TYPE_JSON
)
}

Expand All @@ -50,15 +52,17 @@ internal class DatadogHttpClient(
operationName = OPERATION_NAME_TRACES,
url = exporterConfiguration.endPoint.tracesUrl(),
exporterConfiguration = exporterConfiguration,
body = spanRequestBuilder.build(spanEvents)
body = spanRequestBuilder.build(spanEvents),
mediaType = CONTENT_TYPE_TEXT_UTF8
)
}

private fun postRequest(
operationName: String,
url: String,
exporterConfiguration: DatadogExporterConfiguration,
body: String
body: String,
mediaType: MediaType
) {
val headers = buildHeaders(
requestId = UUID.randomUUID().toString(),
Expand All @@ -73,7 +77,7 @@ internal class DatadogHttpClient(
}
addHeader(HEADER_USER_AGENT, getUserAgent())
}
.post(body.toRequestBody(CONTENT_TYPE_TEXT_UTF8))
.post(body.toRequestBody(mediaType))
.cacheControl(CacheControl.Builder().noCache().build())
.url(url)
.build()
Expand Down Expand Up @@ -179,5 +183,10 @@ internal class DatadogHttpClient(
* text/plain;charset=UTF-8 content type.
*/
private val CONTENT_TYPE_TEXT_UTF8 = "text/plain;charset=UTF-8".toMediaType()

/**
* application/json;charset=UTF-8 content type.
*/
private val CONTENT_TYPE_JSON = "application/json".toMediaType()
}
}

0 comments on commit 5da01c1

Please sign in to comment.