Skip to content

Commit c5718bc

Browse files
committed
Add a camunda test to test instrumentation all
1 parent 4355c63 commit c5718bc

File tree

8 files changed

+284
-0
lines changed

8 files changed

+284
-0
lines changed

instrumentation/camunda/camunda-7.0/javaagent/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ dependencies {
2020
library("org.camunda.bpm:camunda-external-task-client:7.18.0")
2121

2222
annotationProcessor("com.google.auto.value:auto-value:1.6")
23+
24+
testImplementation(project(":instrumentation:camunda:camunda-7.0:testing"))
25+
testImplementation("com.h2database:h2:2.2.224")
2326
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.opentelemetry.javaagent.instrumentation.camunda.v7_0;
2+
3+
import io.opentelemetry.instrumentation.camunda.v7_0.AbstractCamundaTest;
4+
5+
public class CamundaTest extends AbstractCamundaTest {
6+
7+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1sxjr88" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.10.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.19.0">
3+
<bpmn:process id="customerSubProcess" name="customerSubProcess" isExecutable="true">
4+
<bpmn:startEvent id="StartEvent_1">
5+
<bpmn:outgoing>Flow_0ynpw3b</bpmn:outgoing>
6+
</bpmn:startEvent>
7+
<bpmn:endEvent id="Event_12mjag6">
8+
<bpmn:incoming>Flow_0ynpw3b</bpmn:incoming>
9+
<bpmn:terminateEventDefinition id="TerminateEventDefinition_0nv5dzl" />
10+
</bpmn:endEvent>
11+
<bpmn:sequenceFlow id="Flow_0ynpw3b" sourceRef="StartEvent_1" targetRef="Event_12mjag6" />
12+
</bpmn:process>
13+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
14+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="customerSubProcess">
15+
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
16+
<dc:Bounds x="179" y="79" width="36" height="36" />
17+
</bpmndi:BPMNShape>
18+
<bpmndi:BPMNShape id="Event_132saz1_di" bpmnElement="Event_12mjag6">
19+
<dc:Bounds x="392" y="79" width="36" height="36" />
20+
</bpmndi:BPMNShape>
21+
<bpmndi:BPMNEdge id="Flow_0ynpw3b_di" bpmnElement="Flow_0ynpw3b">
22+
<di:waypoint x="215" y="97" />
23+
<di:waypoint x="392" y="97" />
24+
</bpmndi:BPMNEdge>
25+
</bpmndi:BPMNPlane>
26+
</bpmndi:BPMNDiagram>
27+
</bpmn:definitions>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0wu2vf9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.10.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.19.0">
3+
<bpmn:process id="testMainProcess" name="testMainProcess" isExecutable="true">
4+
<bpmn:startEvent id="StartEvent_1">
5+
<bpmn:outgoing>Flow_0oc588e</bpmn:outgoing>
6+
</bpmn:startEvent>
7+
<bpmn:sequenceFlow id="Flow_0oc588e" sourceRef="StartEvent_1" targetRef="getProductInfo" />
8+
<bpmn:endEvent id="Event_110t6od">
9+
<bpmn:incoming>Flow_0zg0twd</bpmn:incoming>
10+
<bpmn:terminateEventDefinition id="TerminateEventDefinition_0fx3yet" />
11+
</bpmn:endEvent>
12+
<bpmn:sequenceFlow id="Flow_1t4wie8" sourceRef="getProductInfo" targetRef="verifyCustomer" />
13+
<bpmn:serviceTask id="getProductInfo" name="Get Product Info" camunda:expression="${Product.getInfo(execution)}">
14+
<bpmn:incoming>Flow_0oc588e</bpmn:incoming>
15+
<bpmn:outgoing>Flow_1t4wie8</bpmn:outgoing>
16+
</bpmn:serviceTask>
17+
<bpmn:sequenceFlow id="Flow_1qcq966" sourceRef="verifyCustomer" targetRef="customerExist" />
18+
<bpmn:callActivity id="verifyCustomer" name="Verify Customer" calledElement="customerSubProcess">
19+
<bpmn:incoming>Flow_1t4wie8</bpmn:incoming>
20+
<bpmn:outgoing>Flow_1qcq966</bpmn:outgoing>
21+
</bpmn:callActivity>
22+
<bpmn:exclusiveGateway id="customerExist" name="Customer Exist" default="Flow_0lo1pvt">
23+
<bpmn:incoming>Flow_1qcq966</bpmn:incoming>
24+
<bpmn:outgoing>Flow_0lo1pvt</bpmn:outgoing>
25+
<bpmn:outgoing>Flow_0h7fg5f</bpmn:outgoing>
26+
</bpmn:exclusiveGateway>
27+
<bpmn:sequenceFlow id="Flow_0lo1pvt" sourceRef="customerExist" targetRef="sendProductInfo" />
28+
<bpmn:endEvent id="Event_0c1osp2">
29+
<bpmn:incoming>Flow_0h7fg5f</bpmn:incoming>
30+
<bpmn:errorEventDefinition id="ErrorEventDefinition_0xll5oi" errorRef="Error_13domxb" />
31+
</bpmn:endEvent>
32+
<bpmn:sequenceFlow id="Flow_0h7fg5f" sourceRef="customerExist" targetRef="Event_0c1osp2">
33+
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{execution.getVariable("customerExist" ) == false}</bpmn:conditionExpression>
34+
</bpmn:sequenceFlow>
35+
<bpmn:serviceTask id="sendProductInfo" name="Send Product Info" camunda:expression="${Product.getInfo(execution)}">
36+
<bpmn:incoming>Flow_0lo1pvt</bpmn:incoming>
37+
<bpmn:outgoing>Flow_0zg0twd</bpmn:outgoing>
38+
</bpmn:serviceTask>
39+
<bpmn:sequenceFlow id="Flow_0zg0twd" sourceRef="sendProductInfo" targetRef="Event_110t6od" />
40+
</bpmn:process>
41+
<bpmn:error id="Error_13domxb" name="GlobalError" errorCode="400" />
42+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
43+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="testMainProcess">
44+
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
45+
<dc:Bounds x="179" y="149" width="36" height="36" />
46+
</bpmndi:BPMNShape>
47+
<bpmndi:BPMNShape id="Activity_1nx1iz4_di" bpmnElement="getProductInfo">
48+
<dc:Bounds x="310" y="127" width="100" height="80" />
49+
</bpmndi:BPMNShape>
50+
<bpmndi:BPMNShape id="Activity_1df2kde_di" bpmnElement="verifyCustomer">
51+
<dc:Bounds x="470" y="127" width="100" height="80" />
52+
<bpmndi:BPMNLabel />
53+
</bpmndi:BPMNShape>
54+
<bpmndi:BPMNShape id="Gateway_0sflauv_di" bpmnElement="customerExist" isMarkerVisible="true">
55+
<dc:Bounds x="675" y="142" width="50" height="50" />
56+
<bpmndi:BPMNLabel>
57+
<dc:Bounds x="744" y="157" width="76" height="14" />
58+
</bpmndi:BPMNLabel>
59+
</bpmndi:BPMNShape>
60+
<bpmndi:BPMNShape id="Event_19no73t_di" bpmnElement="Event_0c1osp2">
61+
<dc:Bounds x="892" y="82" width="36" height="36" />
62+
</bpmndi:BPMNShape>
63+
<bpmndi:BPMNShape id="Event_0g41qff_di" bpmnElement="Event_110t6od">
64+
<dc:Bounds x="1002" y="242" width="36" height="36" />
65+
</bpmndi:BPMNShape>
66+
<bpmndi:BPMNShape id="BPMNShape_1mv97a3" bpmnElement="sendProductInfo">
67+
<dc:Bounds x="800" y="220" width="100" height="80" />
68+
<bpmndi:BPMNLabel />
69+
</bpmndi:BPMNShape>
70+
<bpmndi:BPMNEdge id="Flow_0oc588e_di" bpmnElement="Flow_0oc588e">
71+
<di:waypoint x="215" y="167" />
72+
<di:waypoint x="310" y="167" />
73+
</bpmndi:BPMNEdge>
74+
<bpmndi:BPMNEdge id="Flow_1t4wie8_di" bpmnElement="Flow_1t4wie8">
75+
<di:waypoint x="410" y="167" />
76+
<di:waypoint x="470" y="167" />
77+
</bpmndi:BPMNEdge>
78+
<bpmndi:BPMNEdge id="Flow_1qcq966_di" bpmnElement="Flow_1qcq966">
79+
<di:waypoint x="570" y="167" />
80+
<di:waypoint x="675" y="167" />
81+
</bpmndi:BPMNEdge>
82+
<bpmndi:BPMNEdge id="Flow_0lo1pvt_di" bpmnElement="Flow_0lo1pvt">
83+
<di:waypoint x="700" y="192" />
84+
<di:waypoint x="700" y="260" />
85+
<di:waypoint x="800" y="260" />
86+
</bpmndi:BPMNEdge>
87+
<bpmndi:BPMNEdge id="Flow_0h7fg5f_di" bpmnElement="Flow_0h7fg5f">
88+
<di:waypoint x="700" y="142" />
89+
<di:waypoint x="700" y="100" />
90+
<di:waypoint x="892" y="100" />
91+
</bpmndi:BPMNEdge>
92+
<bpmndi:BPMNEdge id="Flow_0zg0twd_di" bpmnElement="Flow_0zg0twd">
93+
<di:waypoint x="900" y="260" />
94+
<di:waypoint x="1002" y="260" />
95+
</bpmndi:BPMNEdge>
96+
</bpmndi:BPMNPlane>
97+
</bpmndi:BPMNDiagram>
98+
</bpmn:definitions>

instrumentation/camunda/camunda-7.0/library/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ dependencies {
77
library("org.camunda.bpm:camunda-external-task-client:7.18.0")
88

99
annotationProcessor("com.google.auto.value:auto-value:1.6")
10+
11+
testImplementation(project(":instrumentation:camunda:camunda-7.0:testing"))
1012
}
1113

1214
tasks.withType<Test>().configureEach {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
id("otel.java-conventions")
3+
}
4+
5+
dependencies {
6+
api(project(":testing-common"))
7+
8+
implementation("org.camunda.bpm:camunda-engine:7.18.0")
9+
10+
implementation("org.apache.groovy:groovy")
11+
implementation("io.opentelemetry:opentelemetry-api")
12+
implementation("org.spockframework:spock-core")
13+
implementation("com.h2database:h2:2.2.224")
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package io.opentelemetry.instrumentation.camunda.v7_0;
2+
3+
import static org.junit.jupiter.api.Assertions.assertNotNull;
4+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
5+
6+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
7+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
8+
9+
import org.junit.jupiter.api.extension.RegisterExtension;
10+
11+
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
12+
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
13+
14+
import io.opentelemetry.api.trace.Span;
15+
import io.opentelemetry.api.trace.SpanContext;
16+
import io.opentelemetry.context.Context;
17+
import io.opentelemetry.context.Scope;
18+
import org.camunda.bpm.engine.ProcessEngine;
19+
import org.camunda.bpm.engine.ProcessEngineConfiguration;
20+
import org.camunda.bpm.engine.HistoryService;
21+
import org.camunda.bpm.engine.RuntimeService;
22+
import org.camunda.bpm.engine.repository.Deployment;
23+
import org.camunda.bpm.engine.runtime.ProcessInstance;
24+
import org.camunda.bpm.engine.test.mock.Mocks;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
28+
29+
import io.opentelemetry.api.trace.SpanKind;
30+
31+
import io.opentelemetry.semconv.ServerAttributes;
32+
33+
public abstract class AbstractCamundaTest {
34+
35+
@RegisterExtension
36+
private static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
37+
38+
private ProcessEngine processEngine;
39+
private RuntimeService runtimeService;
40+
private HistoryService historyService;
41+
42+
@BeforeEach
43+
void setUp() {
44+
processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
45+
.buildProcessEngine();
46+
runtimeService = processEngine.getRuntimeService();
47+
historyService = processEngine.getHistoryService();
48+
49+
Product mockDelegate = new Product();
50+
51+
Mocks.register("Product", mockDelegate);
52+
}
53+
54+
@AfterEach
55+
void tearDown() {
56+
processEngine.close();
57+
}
58+
59+
@Test
60+
void testProcessExecutionAllSuccess() {
61+
Deployment deployment = processEngine.getRepositoryService().createDeployment()
62+
.addClasspathResource("testMainProcess.bpmn").addClasspathResource("customerSubProcess.bpmn")
63+
.deploy();
64+
65+
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testMainProcess");
66+
67+
assertNotNull(processInstance);
68+
69+
testing.waitAndAssertTracesWithoutScopeVersionVerification(
70+
trace ->
71+
trace.hasSpansSatisfyingExactly(
72+
span ->
73+
span.hasName("testMainProcess")
74+
.hasKind(SpanKind.INTERNAL)
75+
.hasAttributesSatisfyingExactly(
76+
equalTo(stringKey("camunda.processdefinitionkey"), "testMainProcess")),
77+
span ->
78+
span.hasName("Get Product Info Task")
79+
.hasKind(SpanKind.INTERNAL)
80+
.hasAttributesSatisfyingExactly(
81+
equalTo(stringKey("camunda.activityid"), "getProductInfo"),
82+
satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("testMainProcess")),
83+
satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)),
84+
equalTo(stringKey("camunda.activityname"), "Get Product Info")),
85+
span ->
86+
span.hasName("Verify Customer Task")
87+
.hasKind(SpanKind.INTERNAL)
88+
.hasAttributesSatisfyingExactly(
89+
equalTo(stringKey("camunda.activityid"), "verifyCustomer"),
90+
satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("testMainProcess")),
91+
satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)),
92+
equalTo(stringKey("camunda.activityname"), "Verify Customer")),
93+
span ->
94+
span.hasName("End Event")
95+
.hasKind(SpanKind.INTERNAL)
96+
.hasAttributesSatisfyingExactly(
97+
satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("customerSubProcess")),
98+
equalTo(stringKey("camunda.activityid"), "Event_12mjag6"),
99+
satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)),
100+
equalTo(stringKey("camunda.activityname"), "End")),
101+
span ->
102+
span.hasName("Send Product Info Task")
103+
.hasKind(SpanKind.INTERNAL)
104+
.hasAttributesSatisfyingExactly(
105+
equalTo(stringKey("camunda.activityid"), "sendProductInfo"),
106+
satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("testMainProcess")),
107+
satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)),
108+
equalTo(stringKey("camunda.activityname"), "Send Product Info")),
109+
span ->
110+
span.hasName("End Event")
111+
.hasKind(SpanKind.INTERNAL)
112+
.hasAttributesSatisfyingExactly(
113+
satisfies(stringKey("camunda.processdefinitionid"), value -> value.startsWith("testMainProcess")),
114+
equalTo(stringKey("camunda.activityid"), "Event_110t6od"),
115+
satisfies(stringKey("camunda.processinstanceid"), value -> assertNotNull(value)),
116+
equalTo(stringKey("camunda.activityname"), "End"))));
117+
118+
historyService.deleteHistoricProcessInstanceIfExists(processInstance.getId());
119+
processEngine.getRepositoryService().deleteDeployment(deployment.getId(), true);
120+
}
121+
122+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.opentelemetry.instrumentation.camunda.v7_0;
2+
3+
import org.camunda.bpm.engine.delegate.DelegateExecution;
4+
5+
public class Product {
6+
7+
public void getInfo(DelegateExecution execution) {
8+
System.out.println("Product Info");
9+
}
10+
}

0 commit comments

Comments
 (0)