1414import io .opentelemetry .context .Context ;
1515import io .opentelemetry .context .Scope ;
1616import io .opentelemetry .instrumentation .camunda .v7_0 .behavior .CamundaActivityExecutionGetter ;
17+ import io .opentelemetry .instrumentation .camunda .v7_0 .behavior .CamundaActivityExecutionLocalSetter ;
1718import io .opentelemetry .instrumentation .camunda .v7_0 .common .CamundaCommonRequest ;
1819import io .opentelemetry .javaagent .bootstrap .Java8BytecodeBridge ;
1920import io .opentelemetry .javaagent .extension .instrumentation .TypeInstrumentation ;
2425import net .bytebuddy .matcher .ElementMatcher ;
2526import net .bytebuddy .matcher .ElementMatchers ;
2627import org .camunda .bpm .engine .impl .pvm .delegate .ActivityExecution ;
28+ import org .camunda .bpm .model .bpmn .instance .CompensateEventDefinition ;
29+ import org .camunda .bpm .model .bpmn .instance .EndEvent ;
30+ import org .camunda .bpm .model .bpmn .instance .ErrorEventDefinition ;
31+ import org .camunda .bpm .model .bpmn .instance .EventDefinition ;
32+ import org .camunda .bpm .model .bpmn .instance .Gateway ;
33+ import org .camunda .bpm .model .bpmn .instance .TerminateEventDefinition ;
2734
2835public class CamundaCommonBehaviorInstrumentation implements TypeInstrumentation {
2936
@@ -32,19 +39,19 @@ public ElementMatcher<ClassLoader> classLoaderOptimization() {
3239 return hasClassesNamed ("org.camunda.bpm.engine.impl.bpmn.behavior.TaskActivityBehavior" );
3340 }
3441
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- }
42+ @ Override
43+ public ElementMatcher <TypeDescription > typeMatcher () {
44+ return hasSuperType (named ("org.camunda.bpm.engine.impl.bpmn.behavior.TaskActivityBehavior" ))
45+ .or (named ("org.camunda.bpm.engine.impl.bpmn.behavior.ExternalTaskActivityBehavior" ))
46+ .or (named ("org.camunda.bpm.engine.impl.bpmn.behavior.TerminateEndEventActivityBehavior" ))
47+ .or (named ("org.camunda.bpm.engine.impl.bpmn.behavior.NoneEndEventActivityBehavior" ))
48+ .or (named ("org.camunda.bpm.engine.impl.bpmn.behavior.ErrorEndEventActivityBehavior" ));
49+ // elements that have been tested with instrumentation, eventually this can be
50+ // replaced by the supertype AbstractBpmnActivityBehavior, once all elements
51+ // instrumentations have been certified and instrumented, but will need to make
52+ // sure its not callable element as the instrumentation should remain separate
53+ // due to logic
54+ }
4855
4956 @ Override
5057 public void transform (TypeTransformer transformer ) {
@@ -73,34 +80,34 @@ public static void addTracingEnter(
7380 request .setProcessInstanceId (Optional .ofNullable (execution .getProcessInstanceId ()));
7481 request .setActivityId (Optional .ofNullable (execution .getCurrentActivityId ()));
7582
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- }
83+ name :
84+ {
85+ if ( execution . getBpmnModelElementInstance () != null ) {
86+ // TODO lambda does not work due to access modifier
87+ if ( execution . getBpmnModelElementInstance () instanceof EndEvent ) {
88+ EndEvent e = (EndEvent ) execution .getBpmnModelElementInstance ();
89+
90+ if (e .getEventDefinitions () == null || e .getEventDefinitions ().isEmpty ()) {
91+ request .setActivityName (Optional .of ("End" ));
92+ }
93+ for (EventDefinition ed : e .getEventDefinitions ()) {
94+ if (ed instanceof TerminateEventDefinition ) {
95+ request .setActivityName (Optional .of ("End" ));
96+ } else if (ed instanceof ErrorEventDefinition ) {
97+ request .setActivityName (Optional .of ("Error End" ));
98+ } else if (ed instanceof CompensateEventDefinition ) {
99+ request .setActivityName (Optional .of ("Compensation End" ));
100+ } else {
101+ request .setActivityName (Optional .of ("End" ));
102+ }
103+ }
104+ break name ;
105+ } else if (execution .getBpmnModelElementInstance () instanceof Gateway ) {
106+ // TODO
107+ }
108+ }
109+ request .setActivityName (Optional .ofNullable (execution .getCurrentActivityName ()));
110+ }
104111
105112 Context parentContext =
106113 getOpentelemetry ()
@@ -117,17 +124,21 @@ public static void addTracingEnter(
117124 context = getInstumenter ().start (Java8BytecodeBridge .currentContext (), request );
118125 scope = context .makeCurrent ();
119126
120- if (target .getClass () == org .camunda .bpm .engine .impl .bpmn .behavior .ExternalTaskActivityBehavior .class ) {
127+ if (target .getClass ()
128+ == org .camunda .bpm .engine .impl .bpmn .behavior .ExternalTaskActivityBehavior .class ) {
121129
122- getOpentelemetry ().getPropagators ().getTextMapPropagator ().inject (context , execution ,
123- new CamundaActivityExecutionLocalSetter ());
124- }
130+ getOpentelemetry ()
131+ .getPropagators ()
132+ .getTextMapPropagator ()
133+ .inject (context , execution , new CamundaActivityExecutionLocalSetter ());
134+ }
125135 }
126136 }
127137
128138 @ Advice .OnMethodExit (onThrowable = Throwable .class , suppress = Throwable .class )
129139 public static void closeTrace (
130- @ Advice .Local ("request" ) CamundaCommonRequest request , @ Advice .This Object target ,
140+ @ Advice .Local ("request" ) CamundaCommonRequest request ,
141+ @ Advice .This Object target ,
131142 @ Advice .Local ("otelParentScope" ) Scope parentScope ,
132143 @ Advice .Local ("otelContext" ) Context context ,
133144 @ Advice .Local ("otelScope" ) Scope scope ,
0 commit comments