Skip to content

Commit aef91ae

Browse files
sureshanapartitmckeonclaude
authored
Add OpenTelemetry tracing instrumentation to API layer (#13132)
Co-authored-by: tmckeon <tmckeon@apple.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e689c02 commit aef91ae

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@
189189
<cs.ini.version>0.5.4</cs.ini.version>
190190
<cs.caffeine.version>3.1.7</cs.caffeine.version>
191191
<cs.protobuf.version>3.25.5</cs.protobuf.version>
192+
<cs.opentelemetry.version>1.51.0</cs.opentelemetry.version>
193+
<cs.opentelemetry-instrumentation.version>2.16.0</cs.opentelemetry-instrumentation.version>
192194
</properties>
193195

194196
<distributionManagement>
@@ -427,6 +429,16 @@
427429
<artifactId>commons-validator</artifactId>
428430
<version>${cs.commons-validator.version}</version>
429431
</dependency>
432+
<dependency>
433+
<groupId>io.opentelemetry</groupId>
434+
<artifactId>opentelemetry-api</artifactId>
435+
<version>${cs.opentelemetry.version}</version>
436+
</dependency>
437+
<dependency>
438+
<groupId>io.opentelemetry.instrumentation</groupId>
439+
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
440+
<version>${cs.opentelemetry-instrumentation.version}</version>
441+
</dependency>
430442
<dependency>
431443
<groupId>javax.annotation</groupId>
432444
<artifactId>javax.annotation-api</artifactId>

server/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@
197197
<version>4.22.2.0-SNAPSHOT</version>
198198
<scope>compile</scope>
199199
</dependency>
200+
<dependency>
201+
<groupId>io.opentelemetry.instrumentation</groupId>
202+
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
203+
</dependency>
204+
<dependency>
205+
<groupId>io.opentelemetry</groupId>
206+
<artifactId>opentelemetry-api</artifactId>
207+
</dependency>
200208
</dependencies>
201209
<build>
202210
<plugins>

server/src/main/java/com/cloud/api/ApiServer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
import javax.servlet.http.HttpServletResponse;
5959
import javax.servlet.http.HttpSession;
6060

61+
import io.opentelemetry.api.trace.Span;
62+
import io.opentelemetry.instrumentation.annotations.WithSpan;
63+
6164
import com.cloud.cluster.ManagementServerHostVO;
6265
import com.cloud.cluster.dao.ManagementServerHostDao;
6366
import com.cloud.user.Account;
@@ -619,6 +622,7 @@ public void checkCharacterInkParams(final Map params) {
619622
}
620623

621624
@Override
625+
@WithSpan("ApiServer.handleRequest")
622626
@SuppressWarnings("rawtypes")
623627
public String handleRequest(final Map params, final String responseType, final StringBuilder auditTrailSb) throws ServerApiException {
624628
checkCharacterInkParams(params);
@@ -628,6 +632,10 @@ public String handleRequest(final Map params, final String responseType, final S
628632

629633
try {
630634
command = (String[])params.get("command");
635+
if (command != null && command.length > 0) {
636+
Span.current().updateName("ApiServer.handleRequest " + command[0]);
637+
Span.current().setAttribute("api.command", command[0]);
638+
}
631639
if (command == null) {
632640
logger.error("invalid request, no command sent");
633641
if (logger.isTraceEnabled()) {

tools/docker/supervisord.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ command=/bin/bash -c "mvn -pl client jetty:run -Dsimulator -Dorg.eclipse.jetty.a
1212
directory=/root
1313
stdout_logfile=/dev/stdout
1414
stdout_logfile_maxbytes=0
15+
redirect_stderr=true
1516
user=root
1617

1718
[program:cloudstack-ui]

0 commit comments

Comments
 (0)