From 3f2ce8dcbcb6c24197fa637e5c12891525fca07a Mon Sep 17 00:00:00 2001 From: tmckeon Date: Mon, 4 May 2026 10:46:05 -0700 Subject: [PATCH 1/2] Add OpenTelemetry tracing instrumentation to API layer Add OTel annotations and API dependencies to enable distributed tracing of CloudStack API requests. The @WithSpan annotation on handleRequest() tags each trace with the API command name (e.g. listVirtualMachines), making it possible to filter and analyze per-command latency. The OTel agent auto-instruments JDBC and HTTP calls, providing full request waterfalls with no additional code changes. All instrumentation is inert without the OTel Java agent attached: @WithSpan is ignored, Span.current() returns a no-op, and the opentelemetry-api calls return immediately with zero overhead. Co-Authored-By: Claude Opus 4.6 (1M context) --- api/pom.xml | 5 +++++ server/pom.xml | 10 ++++++++++ server/src/main/java/com/cloud/api/ApiServer.java | 8 ++++++++ tools/docker/supervisord.conf | 1 + 4 files changed, 24 insertions(+) diff --git a/api/pom.xml b/api/pom.xml index 405365451c6f..25a0d82e2025 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -71,6 +71,11 @@ cloud-framework-direct-download ${project.version} + + io.opentelemetry.instrumentation + opentelemetry-instrumentation-annotations + 2.16.0 + diff --git a/server/pom.xml b/server/pom.xml index 3324cdb2e619..a208f0987ee1 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -197,6 +197,16 @@ 4.22.1.0-SNAPSHOT compile + + io.opentelemetry.instrumentation + opentelemetry-instrumentation-annotations + 2.16.0 + + + io.opentelemetry + opentelemetry-api + 1.51.0 + diff --git a/server/src/main/java/com/cloud/api/ApiServer.java b/server/src/main/java/com/cloud/api/ApiServer.java index 05ea166e13b2..e3a64649078f 100644 --- a/server/src/main/java/com/cloud/api/ApiServer.java +++ b/server/src/main/java/com/cloud/api/ApiServer.java @@ -58,6 +58,9 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.instrumentation.annotations.WithSpan; + import com.cloud.cluster.ManagementServerHostVO; import com.cloud.cluster.dao.ManagementServerHostDao; import com.cloud.user.Account; @@ -619,6 +622,7 @@ public void checkCharacterInkParams(final Map params) { } @Override + @WithSpan("ApiServer.handleRequest") @SuppressWarnings("rawtypes") public String handleRequest(final Map params, final String responseType, final StringBuilder auditTrailSb) throws ServerApiException { checkCharacterInkParams(params); @@ -628,6 +632,10 @@ public String handleRequest(final Map params, final String responseType, final S try { command = (String[])params.get("command"); + if (command != null && command.length > 0) { + Span.current().updateName("ApiServer.handleRequest " + command[0]); + Span.current().setAttribute("api.command", command[0]); + } if (command == null) { logger.error("invalid request, no command sent"); if (logger.isTraceEnabled()) { diff --git a/tools/docker/supervisord.conf b/tools/docker/supervisord.conf index 93f01387575c..1c14578c4cf3 100644 --- a/tools/docker/supervisord.conf +++ b/tools/docker/supervisord.conf @@ -12,6 +12,7 @@ command=/bin/bash -c "mvn -pl client jetty:run -Dsimulator -Dorg.eclipse.jetty.a directory=/root stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 +redirect_stderr=true user=root [program:cloudstack-ui] From bd73ccfae1eb61f1277435537fad51e532e26206 Mon Sep 17 00:00:00 2001 From: tmckeon Date: Wed, 6 May 2026 14:02:02 -0700 Subject: [PATCH 2/2] Move OpenTelemetry dependency versions to root pom.xml dependencyManagement Centralizes OTel version definitions to avoid version skew across modules and removes unused OTel dependency from api module. Co-Authored-By: Claude Opus 4.6 (1M context) --- api/pom.xml | 5 ----- pom.xml | 12 ++++++++++++ server/pom.xml | 2 -- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 25a0d82e2025..405365451c6f 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -71,11 +71,6 @@ cloud-framework-direct-download ${project.version} - - io.opentelemetry.instrumentation - opentelemetry-instrumentation-annotations - 2.16.0 - diff --git a/pom.xml b/pom.xml index b4e2ec57f81b..c01c45116f03 100644 --- a/pom.xml +++ b/pom.xml @@ -189,6 +189,8 @@ 0.5.4 3.1.7 3.25.5 + 1.51.0 + 2.16.0 @@ -427,6 +429,16 @@ commons-validator ${cs.commons-validator.version} + + io.opentelemetry + opentelemetry-api + ${cs.opentelemetry.version} + + + io.opentelemetry.instrumentation + opentelemetry-instrumentation-annotations + ${cs.opentelemetry-instrumentation.version} + javax.annotation javax.annotation-api diff --git a/server/pom.xml b/server/pom.xml index a208f0987ee1..c6b725993ab6 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -200,12 +200,10 @@ io.opentelemetry.instrumentation opentelemetry-instrumentation-annotations - 2.16.0 io.opentelemetry opentelemetry-api - 1.51.0