From d6ff48121fd77987b91a999bdb240d4b0f061b5f Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Mon, 12 Dec 2022 20:22:41 +0200 Subject: [PATCH] Agent context storage wrapper should not override other wrappers (#7355) Resolves https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/7344 Co-authored-by: Trask Stalnaker --- .../ContextStorageWrappersInstrumentation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/ContextStorageWrappersInstrumentation.java b/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/ContextStorageWrappersInstrumentation.java index 280cc192dffd..9f958249a392 100644 --- a/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/ContextStorageWrappersInstrumentation.java +++ b/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/ContextStorageWrappersInstrumentation.java @@ -46,7 +46,8 @@ public static void methodExit( @Advice.Return(readOnly = false) List> wrappers) { wrappers = new ArrayList<>(wrappers); - wrappers.add(AgentContextStorage.wrap()); + // AgentContextStorage wrapper doesn't delegate, so needs to be the innermost wrapper + wrappers.add(0, AgentContextStorage.wrap()); } } }