-
Notifications
You must be signed in to change notification settings - Fork 1k
Added initial commit of camunda instrumentation #12830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cb645j
wants to merge
51
commits into
open-telemetry:main
Choose a base branch
from
cb645j:feature/camunda_instrumentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
a631796
Added initial commit of camunda instrumentation
cb645j 979c377
Add module to parent settings
cb645j 4fbdbf8
Reorganized project structure and fixed gradle settings
cb645j 7b268c0
fix the version reference in the build settings
cb645j c6aa4c2
Fixed the formatting for spotless
cb645j 80b0e67
Fix formatting for lib folder also per spotless
cb645j b267316
fix bad import in span name extractor class
cb645j fb19def
Added dependencies to javaagent module, changed library instead of im…
cb645j b44bc9d
Fix import statements and remove dead code
cb645j 26df3f1
Fix more errors on compile
cb645j 9fb1aed
remove unused dependencies and supress warning
cb645j d7f179f
Add private constructor for singletons
cb645j 308f6a8
Removed javadocs with no description and unused fields
cb645j fd44b57
remove print line and fix scope
cb645j bdd9ea1
Surpress unused warning in instrumentation
cb645j 628d839
Surpress false warnings so build doesnt fail
cb645j 75f3fdc
Combine supress warnings into one
cb645j 0cd3185
remove empty if blocks from the code
cb645j 3f9833a
Add extra dependency for muzzle check
cb645j 38ff7f0
Consolidated similiar type instrumentations into single module
cb645j 7fcfa7d
fix spotless java format
cb645j da9e851
Fix typos and compilation errors
cb645j 4355c63
remove the label from method
cb645j c5718bc
Add a camunda test to test instrumentation all
cb645j 193cd63
Remove unused imports
cb645j d60eaf3
remove print line from test class
cb645j cc90160
fix formatting and add required aliases
cb645j 6e797eb
fix build errors and spotless
cb645j e484aa7
Add history time to live option
cb645j f938b85
Merge remote-tracking branch 'origin/main' into feature/camunda_instr…
cb645j 2aa9616
add fossa
cb645j 3277d7e
Trigger build
cb645j a3fd09c
Trigger build PR
cb645j 1f4d357
Made changes based off comments
cb645j 0c9ac2d
Merge branch 'main' into feature/camunda_instrumentation
cb645j ad4f524
./gradlew spotlessApply
otelbot[bot] 0a2a414
Accidentely removed file
cb645j bcf17bf
Merge branch 'feature/camunda_instrumentation' of https://github.com/…
cb645j 7aa48b4
./gradlew spotlessApply
otelbot[bot] 096fb01
moved class in correct spot
cb645j d0d2c6c
Merge branch 'feature/camunda_instrumentation' of https://github.com/…
cb645j 4f13543
fix package
cb645j 305c58a
Made updates based off of comments
cb645j 5e151e3
fix typo
cb645j 1298c3f
./gradlew spotlessApply
otelbot[bot] b6d1b32
cast to void
cb645j 35ae48e
Merge branch 'feature/camunda_instrumentation' of https://github.com/…
cb645j bb18387
fix typo
cb645j 9e5df91
update extract
cb645j 78bc660
Merge branch 'main' into feature/camunda_instrumentation
cb645j 62e9317
Merge branch 'main' into feature/camunda_instrumentation
cb645j File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
instrumentation/camunda/camunda-7.0/javaagent/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| plugins { | ||
| id("otel.javaagent-instrumentation") | ||
| } | ||
|
|
||
| muzzle { | ||
| pass { | ||
| group.set("org.camunda.bpm") | ||
| module.set("camunda-engine") | ||
|
|
||
| // have not tested with versions prior to 7.18.0 | ||
| versions.set("[7.18.0,)") | ||
| extraDependency("org.camunda.bpm:camunda-external-task-client:7.18.0") | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":instrumentation:camunda:camunda-7.0:library")) | ||
|
|
||
| library("org.camunda.bpm:camunda-engine:7.18.0") | ||
| library("org.camunda.bpm:camunda-external-task-client:7.18.0") | ||
|
|
||
| annotationProcessor("com.google.auto.value:auto-value:1.6") | ||
|
|
||
| testImplementation(project(":instrumentation:camunda:camunda-7.0:testing")) | ||
| testImplementation("com.h2database:h2:2.2.224") | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
...ntelemetry/javaagent/instrumentation/camunda/v7_0/behavior/CamundaBehaviorSingletons.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.camunda.v7_0.behavior; | ||
|
|
||
| import io.opentelemetry.api.GlobalOpenTelemetry; | ||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; | ||
| import io.opentelemetry.instrumentation.camunda.v7_0.behavior.CamundaBehaviorSpanNameExtractor; | ||
| import io.opentelemetry.instrumentation.camunda.v7_0.common.CamundaCommonRequest; | ||
| import io.opentelemetry.instrumentation.camunda.v7_0.common.CamundaVariableAttributeExtractor; | ||
|
|
||
| public class CamundaBehaviorSingletons { | ||
|
|
||
| private static final Instrumenter<CamundaCommonRequest, Void> instrumenter; | ||
|
|
||
| private static final OpenTelemetry opentelemetry; | ||
|
|
||
| static { | ||
| opentelemetry = GlobalOpenTelemetry.get(); | ||
|
|
||
| InstrumenterBuilder<CamundaCommonRequest, Void> builder = | ||
| Instrumenter.<CamundaCommonRequest, Void>builder( | ||
| opentelemetry, | ||
| "io.opentelemetry.camunda-behavior", | ||
cb645j marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| new CamundaBehaviorSpanNameExtractor()) | ||
| .addAttributesExtractor(new CamundaVariableAttributeExtractor()); | ||
|
|
||
| instrumenter = builder.buildInstrumenter(); | ||
| } | ||
|
|
||
| public static OpenTelemetry getOpentelemetry() { | ||
| return opentelemetry; | ||
| } | ||
|
|
||
| public static Instrumenter<CamundaCommonRequest, Void> getInstumenter() { | ||
| return instrumenter; | ||
| } | ||
|
|
||
| private CamundaBehaviorSingletons() {} | ||
| } | ||
123 changes: 123 additions & 0 deletions
123
...entation/camunda/v7_0/behavior/CamundaCallableElementActivityBehaviorInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.camunda.v7_0.behavior; | ||
|
|
||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasSuperType; | ||
| import static io.opentelemetry.javaagent.instrumentation.camunda.v7_0.behavior.CamundaBehaviorSingletons.getInstumenter; | ||
| import static io.opentelemetry.javaagent.instrumentation.camunda.v7_0.behavior.CamundaBehaviorSingletons.getOpentelemetry; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
|
||
| import io.opentelemetry.api.trace.SpanContext; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.context.Scope; | ||
| import io.opentelemetry.instrumentation.camunda.v7_0.behavior.CamundaActivityExecutionGetter; | ||
| import io.opentelemetry.instrumentation.camunda.v7_0.behavior.CamundaVariableMapSetter; | ||
| import io.opentelemetry.instrumentation.camunda.v7_0.common.CamundaCommonRequest; | ||
| import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
| import java.util.Optional; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
| import org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution; | ||
| import org.camunda.bpm.engine.variable.VariableMap; | ||
|
|
||
| public class CamundaCallableElementActivityBehaviorInstrumentation implements TypeInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher<ClassLoader> classLoaderOptimization() { | ||
| return hasClassesNamed( | ||
| "org.camunda.bpm.engine.impl.bpmn.behavior.CallableElementActivityBehavior"); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher<TypeDescription> typeMatcher() { | ||
| return hasSuperType( | ||
| named("org.camunda.bpm.engine.impl.bpmn.behavior.CallableElementActivityBehavior")); | ||
| } | ||
|
|
||
| @Override | ||
| public void transform(TypeTransformer transformer) { | ||
| transformer.applyAdviceToMethod( | ||
| isMethod().and(named("startInstance")), | ||
| this.getClass().getName() + "$CamundaCallableElementActivityBehaviorAdvice"); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| public static class CamundaCallableElementActivityBehaviorAdvice { | ||
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void addTracingEnter( | ||
| @Advice.Argument(0) ActivityExecution execution, | ||
| @Advice.Argument(1) VariableMap variables, | ||
| @Advice.Local("request") CamundaCommonRequest request, | ||
| @Advice.Local("otelParentScope") Scope parentScope, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope) { | ||
|
|
||
| if (execution == null) { | ||
| return; | ||
| } | ||
|
|
||
| request = new CamundaCommonRequest(); | ||
| request.setProcessDefinitionId(Optional.ofNullable(execution.getProcessDefinitionId())); | ||
| request.setProcessInstanceId(Optional.ofNullable(execution.getProcessInstanceId())); | ||
| request.setActivityId(Optional.ofNullable(execution.getCurrentActivityId())); | ||
| request.setActivityName(Optional.ofNullable(execution.getCurrentActivityName())); | ||
| request.setBusinessKey(Optional.ofNullable(execution.getProcessBusinessKey())); | ||
|
|
||
| Context parentContext = | ||
| getOpentelemetry() | ||
| .getPropagators() | ||
| .getTextMapPropagator() | ||
| .extract( | ||
| Java8BytecodeBridge.currentContext(), | ||
| execution, | ||
| new CamundaActivityExecutionGetter()); | ||
|
|
||
| parentScope = parentContext.makeCurrent(); | ||
|
|
||
| if (getInstumenter().shouldStart(Java8BytecodeBridge.currentContext(), request)) { | ||
| context = getInstumenter().start(Java8BytecodeBridge.currentContext(), request); | ||
| scope = context.makeCurrent(); | ||
|
|
||
| // Inject subflow trace context as pi variables so they are propagated and | ||
| // accessible | ||
|
|
||
| SpanContext currentSpanContext = | ||
| Java8BytecodeBridge.spanFromContext(context).getSpanContext(); | ||
| if (currentSpanContext.isValid()) { | ||
| getOpentelemetry() | ||
| .getPropagators() | ||
| .getTextMapPropagator() | ||
| .inject(context, variables, new CamundaVariableMapSetter()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
| public static void closeTrace( | ||
| @Advice.Argument(0) ActivityExecution execution, | ||
| @Advice.Local("request") CamundaCommonRequest request, | ||
| @Advice.Local("otelParentScope") Scope parentScope, | ||
| @Advice.Local("otelContext") Context context, | ||
| @Advice.Local("otelScope") Scope scope, | ||
| @Advice.Thrown Throwable throwable) { | ||
|
|
||
| if (context != null && scope != null) { | ||
| getInstumenter().end(context, request, null, throwable); | ||
| scope.close(); | ||
| } | ||
|
|
||
| if (parentScope != null) { | ||
| parentScope.close(); | ||
| } | ||
| } | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
...t/instrumentation/camunda/v7_0/behavior/CamundaCallableElementActivityBehaviorModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.camunda.v7_0.behavior; | ||
|
|
||
| import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
| import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| @AutoService(InstrumentationModule.class) | ||
| public class CamundaCallableElementActivityBehaviorModule extends InstrumentationModule { | ||
|
|
||
| public CamundaCallableElementActivityBehaviorModule() { | ||
| super("camunda", "camunda-7.0", "camunda-behavior"); | ||
| } | ||
|
|
||
| @Override | ||
| public List<TypeInstrumentation> typeInstrumentations() { | ||
| return Collections.singletonList(new CamundaCallableElementActivityBehaviorInstrumentation()); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
| return hasClassesNamed( | ||
| "org.camunda.bpm.engine.impl.bpmn.behavior.CallableElementActivityBehavior"); | ||
| } | ||
|
|
||
| String[] helperClassnames = { | ||
| "io.opentelemetry.javaagent.instrumentation.camunda.v7_0.behavior", | ||
| "io.opentelemetry.instrumentation.camunda.v7_0.behavior", | ||
| "io.opentelemetry.instrumentation.camunda.v7_0.common" | ||
| }; | ||
|
|
||
| @Override | ||
| public boolean isHelperClass(String classname) { | ||
| return super.isHelperClass(classname) | ||
| || Arrays.stream(helperClassnames).anyMatch(c -> classname.startsWith(c)); | ||
| } | ||
cb645j marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.