Skip to content

Commit 2f0f28c

Browse files
authored
fix(core): Fix/otel compat (aws#6119)
* refactor(otel): use compatibility helpers instead of duplicating entire file Address PR review feedback to avoid copying entire OTelService.kt for version compatibility. Changes: - Move OTelService.kt to common src/ directory (168 lines, shared by all versions) - Create small version-specific HttpPostCompat.kt files (18-19 lines each) - Eliminates 137 lines of code duplication - Main logic now maintained in single location The httpPost API changed between IDE versions 2024.2-2025.2 and 2025.3+: - Old API uses contentLength parameter with streaming body - New API uses body parameter with byte array Follows existing codebase pattern (see PythonModuleUtil.kt, JavascriptLanguage.kt) for handling compile-time API incompatibilities with minimal duplication. * fix: remove unused NonInjectable import * refactor(otel): use Apache HttpClient for cross-version compatibility Address PR review feedback - use Apache HttpClient instead of platform httpPost API. Changes: - Replace IntelliJ Platform httpPost with Apache HttpClient - Works consistently across all IDE versions (2024.2 - 2025.3+) - Matches existing pattern used in SigV4OtlpSpanProcessor - No version-specific compatibility wrappers needed - Single OTelService.kt in common src/ directory This approach: - Uses same HTTP library as CawsEnvironmentClient and SigV4OtlpSpanProcessor - Avoids platform API incompatibilities between IDE versions - Follows established codebase patterns for HTTP operations * 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. * Optimize telemetry export by writing directly to output stream * perf(otel): write telemetry directly to HTTP stream Address PR review feedback to avoid intermediate ByteArrayOutputStream. Instead of: 1. Write to ByteArrayOutputStream 2. Convert to byte array 3. Write byte array to HTTP connection Now: 1. Write directly to HTTP connection.outputStream This reduces memory allocation and improves performance by streaming data directly to the network without intermediate buffering.
1 parent a60c9c1 commit 2f0f28c

File tree

2 files changed

+7
-176
lines changed
  • plugins/core/jetbrains-community
    • src-253+/software/aws/toolkits/jetbrains/services/telemetry/otel
    • src/software/aws/toolkits/jetbrains/services/telemetry/otel

2 files changed

+7
-176
lines changed

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

Lines changed: 0 additions & 171 deletions
This file was deleted.

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import com.intellij.openapi.components.Service
99
import com.intellij.openapi.components.service
1010
import com.intellij.openapi.diagnostic.thisLogger
1111
import com.intellij.openapi.util.SystemInfoRt
12-
import com.intellij.platform.util.http.ContentType
13-
import com.intellij.platform.util.http.httpPost
1412
import com.intellij.serviceContainer.NonInjectable
13+
import com.intellij.util.io.HttpRequests
1514
import io.opentelemetry.api.common.AttributeKey
1615
import io.opentelemetry.api.common.Attributes
1716
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator
@@ -34,6 +33,7 @@ import software.amazon.awssdk.http.SdkHttpMethod
3433
import software.amazon.awssdk.http.SdkHttpRequest
3534
import software.amazon.awssdk.http.apache.ApacheHttpClient
3635
import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner
36+
import software.aws.toolkits.jetbrains.core.AwsClientManager
3737
import java.io.ByteArrayOutputStream
3838
import java.net.ConnectException
3939

@@ -51,9 +51,11 @@ private class BasicOtlpSpanProcessor(
5151
try {
5252
val item = TraceRequestMarshaler.create(listOf(data))
5353

54-
httpPost(traceUrl, contentLength = item.binarySerializedSize.toLong(), contentType = ContentType.XProtobuf) {
55-
item.writeBinaryTo(this)
56-
}
54+
HttpRequests.post(traceUrl, "application/x-protobuf")
55+
.userAgent(AwsClientManager.getUserAgent())
56+
.connect { request ->
57+
item.writeBinaryTo(request.connection.outputStream)
58+
}
5759
} catch (e: CancellationException) {
5860
throw e
5961
} catch (e: ConnectException) {

0 commit comments

Comments
 (0)