Skip to content

Commit 38ff7f0

Browse files
committed
Consolidated similiar type instrumentations into single module
1 parent 3f9833a commit 38ff7f0

File tree

6 files changed

+58
-368
lines changed

6 files changed

+58
-368
lines changed
Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,36 @@
2525
import net.bytebuddy.matcher.ElementMatchers;
2626
import org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution;
2727

28-
public class CamundaTaskActivityBehaviorInstrumentation implements TypeInstrumentation {
28+
public class CamundaCommonBehaviorInstrumentation implements TypeInstrumentation {
2929

3030
@Override
3131
public ElementMatcher<ClassLoader> classLoaderOptimization() {
3232
return hasClassesNamed("org.camunda.bpm.engine.impl.bpmn.behavior.TaskActivityBehavior");
3333
}
3434

35-
@Override
36-
public ElementMatcher<TypeDescription> typeMatcher() {
37-
return hasSuperType(named("org.camunda.bpm.engine.impl.bpmn.behavior.TaskActivityBehavior"));
38-
}
35+
@Override
36+
public ElementMatcher<TypeDescription> typeMatcher() {
37+
return hasSuperType(named("org.camunda.bpm.engine.impl.bpmn.behavior.TaskActivityBehavior"))
38+
.or(named("org.camunda.bpm.engine.impl.bpmn.behavior.ExternalTaskActivityBehavior"))
39+
.or(named("org.camunda.bpm.engine.impl.bpmn.behavior.TerminateEndEventActivityBehavior"))
40+
.or(named("org.camunda.bpm.engine.impl.bpmn.behavior.NoneEndEventActivityBehavior"))
41+
.or(named("org.camunda.bpm.engine.impl.bpmn.behavior.ErrorEndEventActivityBehavior"));
42+
// elements that have been tested with instrumentation, eventually this can be
43+
// replaced by the supertype AbstractBpmnActivityBehavior, once all elements
44+
// instrumentations have been certified and instrumented, but will need to make
45+
// sure its not callable element as the instrumentation should remain separate
46+
// due to logic
47+
}
3948

4049
@Override
4150
public void transform(TypeTransformer transformer) {
4251
transformer.applyAdviceToMethod(
43-
ElementMatchers.isMethod().and(ElementMatchers.named("performExecution")),
44-
this.getClass().getName() + "$CamundaTaskActivityBehaviorAdvice");
52+
ElementMatchers.isMethod().and(ElementMatchers.named("execute")),
53+
this.getClass().getName() + "$CamundaCommonBehaviorAdvice");
4554
}
4655

4756
@SuppressWarnings("unused")
48-
public static class CamundaTaskActivityBehaviorAdvice {
57+
public static class CamundaCommonBehaviorAdvice {
4958

5059
@Advice.OnMethodEnter(suppress = Throwable.class)
5160
public static void addTracingEnter(
@@ -63,7 +72,35 @@ public static void addTracingEnter(
6372
request.setProcessDefinitionId(Optional.ofNullable(execution.getProcessDefinitionId()));
6473
request.setProcessInstanceId(Optional.ofNullable(execution.getProcessInstanceId()));
6574
request.setActivityId(Optional.ofNullable(execution.getCurrentActivityId()));
66-
request.setActivityName(Optional.ofNullable(execution.getCurrentActivityName()));
75+
76+
name: {
77+
if (execution.getBpmnModelElementInstance() != null) {
78+
// TODO lambda does not work due to access modifier
79+
if (execution.getBpmnModelElementInstance() instanceof EndEvent) {
80+
getLogger().info("instance of EndEvent");
81+
EndEvent e = (EndEvent) execution.getBpmnModelElementInstance();
82+
83+
if (e.getEventDefinitions() == null || e.getEventDefinitions().isEmpty()) {
84+
request.setActivityName(Optional.of("End"));
85+
}
86+
for (EventDefinition ed : e.getEventDefinitions()) {
87+
if (ed instanceof TerminateEventDefinition) {
88+
request.setActivityName(Optional.of("End"));
89+
} else if (ed instanceof ErrorEventDefinition) {
90+
request.setActivityName(Optional.of("Error End"));
91+
} else if (ed instanceof CompensateEventDefinition) {
92+
request.setActivityName(Optional.of("Compensation End"));
93+
} else {
94+
request.setActivityName(Optional.of("End"));
95+
}
96+
}
97+
break name;
98+
} else if (execution.getBpmnModelElementInstance() instanceof Gateway) {
99+
// TODO
100+
}
101+
}
102+
request.setActivityName(Optional.ofNullable(execution.getCurrentActivityName()));
103+
}
67104

68105
Context parentContext =
69106
getOpentelemetry()
@@ -79,12 +116,18 @@ public static void addTracingEnter(
79116
if (getInstumenter().shouldStart(Java8BytecodeBridge.currentContext(), request)) {
80117
context = getInstumenter().start(Java8BytecodeBridge.currentContext(), request);
81118
scope = context.makeCurrent();
119+
120+
if (target.getClass() == org.camunda.bpm.engine.impl.bpmn.behavior.ExternalTaskActivityBehavior.class) {
121+
122+
getOpentelemetry().getPropagators().getTextMapPropagator().inject(context, execution,
123+
new CamundaActivityExecutionLocalSetter());
124+
}
82125
}
83126
}
84127

85128
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
86129
public static void closeTrace(
87-
@Advice.Local("request") CamundaCommonRequest request,
130+
@Advice.Local("request") CamundaCommonRequest request, @Advice.This Object target,
88131
@Advice.Local("otelParentScope") Scope parentScope,
89132
@Advice.Local("otelContext") Context context,
90133
@Advice.Local("otelScope") Scope scope,
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,22 @@
1616
import net.bytebuddy.matcher.ElementMatcher;
1717

1818
@AutoService(InstrumentationModule.class)
19-
public class CamundaTaskActivityBehaviorModule extends InstrumentationModule {
19+
public class CamundaCommonBehaviorModule extends InstrumentationModule {
2020

2121
public CamundaTaskActivityBehaviorModule() {
2222
super("camunda", "camunda-behavior", "camunda-behavior-7_18");
2323
}
2424

2525
@Override
2626
public List<TypeInstrumentation> typeInstrumentations() {
27-
return Collections.singletonList(new CamundaTaskActivityBehaviorInstrumentation());
27+
return Collections.singletonList(new CamundaCommonBehaviorInstrumentation());
2828
}
2929

3030
@Override
3131
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
32-
return hasClassesNamed("org.camunda.bpm.engine.impl.bpmn.behavior.TaskActivityBehavior");
32+
return hasClassesNamed("org.camunda.bpm.engine.impl.bpmn.behavior.TaskActivityBehavior",
33+
"org.camunda.bpm.engine.impl.bpmn.behavior.NoneEndEventActivityBehavior",
34+
"org.camunda.bpm.engine.impl.bpmn.behavior.ErrorEndEventActivityBehavior");
3335
}
3436

3537
String[] helperClassnames = {

instrumentation/camunda/camunda-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/camunda/v7_0/behavior/CamundaEndEventActivityBehaviorInstrumentation.java

Lines changed: 0 additions & 132 deletions
This file was deleted.

instrumentation/camunda/camunda-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/camunda/v7_0/behavior/CamundaEndEventActivityBehaviorModule.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)