Skip to content

Commit 1ead856

Browse files
committed
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.
1 parent bf1a830 commit 1ead856

File tree

4 files changed

+38
-175
lines changed

4 files changed

+38
-175
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.telemetry.otel
5+
6+
import com.intellij.platform.util.http.ContentType
7+
import com.intellij.platform.util.http.httpPost
8+
import io.opentelemetry.exporter.internal.otlp.traces.TraceRequestMarshaler
9+
10+
/**
11+
* Version-specific compatibility wrapper for httpPost (2024.2-2025.2)
12+
* In these versions, httpPost uses contentLength parameter with streaming body
13+
*/
14+
internal suspend fun sendOtelTrace(url: String, marshaler: TraceRequestMarshaler) {
15+
httpPost(url, contentLength = marshaler.binarySerializedSize.toLong(), contentType = ContentType.XProtobuf) {
16+
marshaler.writeBinaryTo(this)
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.telemetry.otel
5+
6+
import com.intellij.platform.util.http.ContentType
7+
import com.intellij.platform.util.http.httpPost
8+
import io.opentelemetry.exporter.internal.otlp.traces.TraceRequestMarshaler
9+
import java.io.ByteArrayOutputStream
10+
11+
/**
12+
* Version-specific compatibility wrapper for httpPost (2025.3+)
13+
* In this version, httpPost uses body parameter with byte array
14+
*/
15+
internal suspend fun sendOtelTrace(url: String, marshaler: TraceRequestMarshaler) {
16+
val output = ByteArrayOutputStream()
17+
marshaler.writeBinaryTo(output)
18+
httpPost(url, contentType = ContentType.XProtobuf, body = output.toByteArray())
19+
}

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.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ private class BasicOtlpSpanProcessor(
5050
coroutineScope.launch {
5151
try {
5252
val item = TraceRequestMarshaler.create(listOf(data))
53-
54-
httpPost(traceUrl, contentLength = item.binarySerializedSize.toLong(), contentType = ContentType.XProtobuf) {
55-
item.writeBinaryTo(this)
56-
}
53+
sendOtelTrace(traceUrl, item)
5754
} catch (e: CancellationException) {
5855
throw e
5956
} catch (e: ConnectException) {

0 commit comments

Comments
 (0)