Skip to content

Commit ced1832

Browse files
authored
Add OpenTelemetry API smoke test (#1391)
* Add OpenTelemetry API smoke test * Remove unnecessary smoke test dependencies * Update to 0.11.0
1 parent 4a1762e commit ced1832

File tree

8 files changed

+123
-0
lines changed

8 files changed

+123
-0
lines changed

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ include ':test:smoke:testApps:VerifyShading'
8484
include ':test:smoke:testApps:VerifyJava7'
8585
include ':test:smoke:testApps:JettyNativeHandler'
8686
include ':test:smoke:testApps:DataScrubbing'
87+
include ':test:smoke:testApps:OpenTelemetryApiSupport'
8788

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-0FEEDDADBEEF;IngestionEndpoint=http://fakeingestion:60606/",
3+
"preview": {
4+
"openTelemetryApiSupport": true
5+
}
6+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apply plugin: 'war'
2+
3+
sourceCompatibility = 1.8
4+
targetCompatibility = 1.8
5+
compileSmokeTestJava.sourceCompatibility = 1.8
6+
compileSmokeTestJava.targetCompatibility = 1.8
7+
8+
war {
9+
// this is done to remove the version from the archive file name
10+
// to make span name verification simpler
11+
archiveFileName = project.name + '.war'
12+
}
13+
14+
ext.testAppArtifactDir = war.destinationDirectory
15+
ext.testAppArtifactFilename = project.name + '.war'
16+
17+
dependencies {
18+
compileOnly aiAgentJar // this is just to force building the agent first
19+
20+
compile (group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.7.RELEASE') {
21+
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
22+
}
23+
24+
compile group: 'io.opentelemetry', name: 'opentelemetry-api', version: '0.11.0'
25+
26+
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.microsoft.ajl.simple;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
5+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
6+
7+
@SpringBootApplication
8+
public class SpringBootApp extends SpringBootServletInitializer {
9+
@Override
10+
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
11+
return applicationBuilder.sources(SpringBootApp.class);
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.microsoft.ajl.simple;
2+
3+
import io.opentelemetry.api.trace.Span;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
@RestController
8+
public class TestController {
9+
10+
@GetMapping("/")
11+
public String root() {
12+
return "OK";
13+
}
14+
15+
16+
@GetMapping("/test")
17+
public String test() {
18+
Span.current().setAttribute("myattr1", "myvalue1");
19+
Span.current().setAttribute("myattr2", "myvalue2");
20+
Span.current().updateName("myspanname");
21+
return "OK!";
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.microsoft.applicationinsights.smoketest;
2+
3+
import java.util.List;
4+
5+
import com.microsoft.applicationinsights.internal.schemav2.Data;
6+
import com.microsoft.applicationinsights.internal.schemav2.Envelope;
7+
import com.microsoft.applicationinsights.internal.schemav2.RemoteDependencyData;
8+
import com.microsoft.applicationinsights.internal.schemav2.RequestData;
9+
import org.junit.Test;
10+
11+
import static org.junit.Assert.*;
12+
13+
@UseAgent("opentelemetryapisupport")
14+
public class OpenTelemetryApiSupportTest extends AiSmokeTest {
15+
16+
@Test
17+
@TargetUri("/test")
18+
public void doMostBasicTest() throws Exception {
19+
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
20+
21+
Envelope rdEnvelope = rdList.get(0);
22+
String operationId = rdEnvelope.getTags().get("ai.operation.id");
23+
List<Envelope> rddList = mockedIngestion.waitForItemsInOperation("RemoteDependencyData", 1, operationId);
24+
25+
Envelope rddEnvelope = rddList.get(0);
26+
27+
RequestData rd = (RequestData) ((Data) rdEnvelope.getData()).getBaseData();
28+
RemoteDependencyData rdd = (RemoteDependencyData) ((Data) rddEnvelope.getData()).getBaseData();
29+
30+
// ideally want these on rd, but can't get SERVER span yet
31+
// see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1726#issuecomment-731890267
32+
assertEquals("myvalue1", rdd.getProperties().get("myattr1"));
33+
assertEquals("myvalue2", rdd.getProperties().get("myattr2"));
34+
assertEquals("myspanname", rdd.getName());
35+
36+
assertTrue(rd.getSuccess());
37+
}
38+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
jbosseap7
2+
tomcat85
3+
jetty9
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE configuration>
3+
<configuration>
4+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
5+
<encoder>
6+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
7+
</encoder>
8+
</appender>
9+
<root level="warn">
10+
<appender-ref ref="CONSOLE" />
11+
</root>
12+
</configuration>

0 commit comments

Comments
 (0)