Skip to content

Commit 9cf4fba

Browse files
trasklaurit
andauthored
Fix RMI context propagation (#16979)
Co-authored-by: Lauri Tulmin <ltulmin@splunk.com>
1 parent 778754b commit 9cf4fba

File tree

11 files changed

+53
-28
lines changed

11 files changed

+53
-28
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## Version 2.26.1 (2026-03-23)
4+
5+
### 🛠️ Bug fixes
6+
7+
- Fix RMI context propagation
8+
([#16979](https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/16979))
9+
310
## Version 2.26.0 (2026-03-13)
411

512
### ⚠️ Breaking changes to non-stable APIs

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ If you are looking for documentation on using those.
3333
## Getting Started
3434

3535
Download
36-
the [latest version](https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.26.0/opentelemetry-javaagent.jar).
36+
the [latest version](https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.26.1/opentelemetry-javaagent.jar).
3737

3838
This package includes the instrumentation agent as well as
3939
instrumentations for all supported libraries and all available data exporters.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Comparing source compatibility of opentelemetry-instrumentation-annotations-2.26.0.jar against opentelemetry-instrumentation-annotations-2.25.0.jar
1+
Comparing source compatibility of opentelemetry-instrumentation-annotations-2.26.1.jar against opentelemetry-instrumentation-annotations-2.25.0.jar
22
No changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Comparing source compatibility of opentelemetry-instrumentation-api-2.26.0.jar against opentelemetry-instrumentation-api-2.25.0.jar
1+
Comparing source compatibility of opentelemetry-instrumentation-api-2.26.1.jar against opentelemetry-instrumentation-api-2.25.0.jar
22
No changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Comparing source compatibility of opentelemetry-spring-boot-autoconfigure-2.26.0.jar against opentelemetry-spring-boot-autoconfigure-2.25.0.jar
1+
Comparing source compatibility of opentelemetry-spring-boot-autoconfigure-2.26.1.jar against opentelemetry-spring-boot-autoconfigure-2.25.0.jar
22
No changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Comparing source compatibility of opentelemetry-spring-boot-starter-2.26.0.jar against opentelemetry-spring-boot-starter-2.25.0.jar
1+
Comparing source compatibility of opentelemetry-spring-boot-starter-2.26.1.jar against opentelemetry-spring-boot-starter-2.25.0.jar
22
No changes.

examples/distro/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ buildscript {
1414
dependencies {
1515
classpath "com.diffplug.spotless:spotless-plugin-gradle:8.3.0"
1616
classpath "com.gradleup.shadow:shadow-gradle-plugin:9.3.2"
17-
classpath "io.opentelemetry.instrumentation:gradle-plugins:2.26.0-alpha"
17+
classpath "io.opentelemetry.instrumentation:gradle-plugins:2.26.1-alpha"
1818
}
1919
}
2020

@@ -30,8 +30,8 @@ subprojects {
3030
opentelemetrySdk : "1.60.1",
3131

3232
// these lines are managed by .github/scripts/update-version.sh
33-
opentelemetryJavaagent : "2.26.0",
34-
opentelemetryJavaagentAlpha: "2.26.0-alpha",
33+
opentelemetryJavaagent : "2.26.1",
34+
opentelemetryJavaagentAlpha: "2.26.1-alpha",
3535

3636
autoservice : "1.1.1"
3737
]

examples/extension/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ plugins {
1313
id "com.gradleup.shadow" version "9.3.2"
1414
id "com.diffplug.spotless" version "8.3.0"
1515

16-
id "io.opentelemetry.instrumentation.muzzle-generation" version "2.26.0-alpha"
17-
id "io.opentelemetry.instrumentation.muzzle-check" version "2.26.0-alpha"
16+
id "io.opentelemetry.instrumentation.muzzle-generation" version "2.26.1-alpha"
17+
id "io.opentelemetry.instrumentation.muzzle-check" version "2.26.1-alpha"
1818
}
1919

2020
group 'io.opentelemetry.example'
@@ -26,8 +26,8 @@ ext {
2626
opentelemetrySdk : "1.60.1",
2727

2828
// these lines are managed by .github/scripts/update-version.sh
29-
opentelemetryJavaagent : "2.26.0",
30-
opentelemetryJavaagentAlpha: "2.26.0-alpha"
29+
opentelemetryJavaagent : "2.26.1",
30+
opentelemetryJavaagentAlpha: "2.26.1-alpha"
3131
]
3232

3333
deps = [

instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/ContextPayload.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
import java.util.HashMap;
1818
import java.util.Map;
1919
import java.util.logging.Logger;
20+
import javax.annotation.Nullable;
2021

2122
/** ContextPayload wraps context information shared between client and server. */
2223
public class ContextPayload {
2324

2425
private static final Logger logger = Logger.getLogger(ContextPayload.class.getName());
26+
private static final int MAX_CONTEXT_ENTRIES = 1000;
2527

2628
private final Map<String, String> context;
2729

@@ -41,24 +43,40 @@ public static ContextPayload from(Context context) {
4143
return payload;
4244
}
4345

44-
@SuppressWarnings("BanSerializableRead") // fine
46+
@Nullable
4547
public static ContextPayload read(ObjectInput oi) throws IOException {
46-
try {
47-
Object object = oi.readObject();
48-
if (object instanceof Map) {
49-
@SuppressWarnings("unchecked") // convert it back to the expected type
50-
Map<String, String> map = (Map<String, String>) object;
51-
return new ContextPayload(map);
52-
}
53-
} catch (ClassCastException | ClassNotFoundException ex) {
54-
logger.log(FINE, "Error reading object", ex);
48+
int size = oi.readInt();
49+
if (size > MAX_CONTEXT_ENTRIES) {
50+
logger.log(
51+
FINE,
52+
"RMI context propagation payload size {0} exceeds maximum allowed of {1}, skipping context propagation.",
53+
new Object[] {size, MAX_CONTEXT_ENTRIES});
54+
return null;
5555
}
56-
57-
return null;
56+
Map<String, String> map = new HashMap<>();
57+
for (int i = 0; i < size; i++) {
58+
String key = oi.readUTF();
59+
String value = oi.readUTF();
60+
map.put(key, value);
61+
}
62+
return new ContextPayload(map);
5863
}
5964

6065
public void write(ObjectOutput out) throws IOException {
61-
out.writeObject(context);
66+
int size = context.size();
67+
if (size > MAX_CONTEXT_ENTRIES) {
68+
logger.log(
69+
FINE,
70+
"RMI context propagation payload size {0} exceeds maximum allowed of {1}, skipping context propagation.",
71+
new Object[] {size, MAX_CONTEXT_ENTRIES});
72+
out.writeInt(0);
73+
return;
74+
}
75+
out.writeInt(size);
76+
for (Map.Entry<String, String> entry : context.entrySet()) {
77+
out.writeUTF(entry.getKey());
78+
out.writeUTF(entry.getValue());
79+
}
6280
}
6381

6482
public Context extract() {

instrumentation/rmi/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/rmi/context/ContextPropagator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ContextPropagator {
3232

3333
// RMI object id used to identify agent instrumentation
3434
public static final ObjID CONTEXT_CALL_ID =
35-
new ObjID("io.opentelemetry.javaagent.context-call".hashCode());
35+
new ObjID("io.opentelemetry.javaagent.context-call-v2".hashCode());
3636

3737
// Operation id used for checking context propagation is possible
3838
// RMI expects these operations to have negative identifier, as positive ones mean legacy

0 commit comments

Comments
 (0)