From 013fc5f1aff30c714aaeb3b322cd58d8593ac8a5 Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Wed, 4 Feb 2026 10:08:31 +0100 Subject: [PATCH] Propagate trace context in RESTAPI runner() - the runner() method is used in the aai-resources service to run the aai-core logic within a dedicated thread - wrap this thread in a callable to propagate otel trace context to the thread Issue-ID: AAI-4224 Change-Id: Ib94d614de0483577a1f895187a5e9d824711e99b Signed-off-by: Fiete Ostkamp --- aai-core/pom.xml | 6 ++++++ .../src/main/java/org/onap/aai/restcore/RESTAPI.java | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/aai-core/pom.xml b/aai-core/pom.xml index 3058693f..e5a73999 100644 --- a/aai-core/pom.xml +++ b/aai-core/pom.xml @@ -262,6 +262,12 @@ limitations under the License. micrometer-observation + io.opentelemetry + opentelemetry-context + + compile + + org.slf4j slf4j-api diff --git a/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java b/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java index f4da0175..3334e261 100644 --- a/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java +++ b/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java @@ -33,6 +33,8 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.Scope; import jakarta.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; @@ -350,9 +352,21 @@ public class RESTAPI { String timeoutByApp = AAIConfig.get(tba); String timeoutDefaultLimit = AAIConfig.get(tdl); String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); + if (isTimeoutEnabled(sourceOfTruth, timeoutEnabled, timeoutByApp, timeoutDefaultLimit)) { executor = Executors.newSingleThreadExecutor(); - handler = executor.submit(c); + + // Capture current context + Context context = Context.current(); + + // Wrap the callable to propagate context + Callable wrappedCallable = () -> { + try (Scope scope = context.makeCurrent()) { + return c.call(); + } + }; + + handler = executor.submit(wrappedCallable); response = executeProcess(handler, sourceOfTruth, timeoutByApp, timeoutDefaultLimit, httpMethod, headers, info); } else { -- 2.16.6