Skip to content

Commit a8ebd09

Browse files
committed
refactor(otel): use HttpRequests for proxy and user agent support
Use IntelliJ's HttpRequests API instead of Apache HttpClient to respect IDE proxy settings and use AWS Toolkit user agent.
1 parent c6b8e05 commit a8ebd09

File tree

1 file changed

+6
-12
lines changed
  • plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/otel

1 file changed

+6
-12
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/otel/OTelService.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.intellij.openapi.components.service
1010
import com.intellij.openapi.diagnostic.thisLogger
1111
import com.intellij.openapi.util.SystemInfoRt
1212
import com.intellij.serviceContainer.NonInjectable
13+
import com.intellij.util.io.HttpRequests
1314
import io.opentelemetry.api.common.AttributeKey
1415
import io.opentelemetry.api.common.Attributes
1516
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator
@@ -25,16 +26,14 @@ import io.opentelemetry.sdk.trace.SpanProcessor
2526
import kotlinx.coroutines.CancellationException
2627
import kotlinx.coroutines.CoroutineScope
2728
import kotlinx.coroutines.launch
28-
import org.apache.http.client.methods.HttpPost
29-
import org.apache.http.entity.ByteArrayEntity
30-
import org.apache.http.impl.client.HttpClients
3129
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider
3230
import software.amazon.awssdk.http.ContentStreamProvider
3331
import software.amazon.awssdk.http.HttpExecuteRequest
3432
import software.amazon.awssdk.http.SdkHttpMethod
3533
import software.amazon.awssdk.http.SdkHttpRequest
3634
import software.amazon.awssdk.http.apache.ApacheHttpClient
3735
import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner
36+
import software.aws.toolkits.jetbrains.core.AwsClientManager
3837
import java.io.ByteArrayOutputStream
3938
import java.net.ConnectException
4039

@@ -54,16 +53,11 @@ private class BasicOtlpSpanProcessor(
5453
val baos = ByteArrayOutputStream()
5554
item.writeBinaryTo(baos)
5655

57-
HttpClients.createDefault().use { client ->
58-
val request = HttpPost(traceUrl).apply {
59-
entity = ByteArrayEntity(baos.toByteArray()).apply {
60-
setContentType("application/x-protobuf")
61-
}
62-
}
63-
client.execute(request).use {
64-
// Response consumed and closed
56+
HttpRequests.post(traceUrl, "application/x-protobuf")
57+
.userAgent(AwsClientManager.getUserAgent())
58+
.connect { request ->
59+
request.write(baos.toByteArray())
6560
}
66-
}
6761
} catch (e: CancellationException) {
6862
throw e
6963
} catch (e: ConnectException) {

0 commit comments

Comments
 (0)