Skip to content
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

Implement Kotlin Coroutines Plugin #1964

Closed
wants to merge 6 commits into from

Conversation

bastrich
Copy link

@bastrich bastrich commented Aug 6, 2021

Implemented #1963

Here I build CoroutineInterceptor and CoroutineWrapper classes manually with ByteBuddy and in the local scope of the advice method. Otherwise, if I build them in another static context or just write like simple Java/Kotlin classes, I get ClassDefNotFoundError for Kotlin classes when integrating with traced applications. I don't know why, but building classes with ByteBuddy in the local scope of advice function resolved that issue. And I wrote an integration test for such case.

  • This is a new plugin
    • I have updated CHANGELOG.asciidoc
    • My code follows the style guidelines of this project
    • I have made corresponding changes to the documentation
    • I have added tests that prove my fix is effective or that my feature works
    • New and existing unit tests pass locally with my changes
    • I have updated supported-technologies.asciidoc
    • Added an API method or config option? Document in which version this will be introduced
    • Added an instrumentation plugin? Describe how you made sure that old, non-supported versions are not instrumented by accident.

@cla-checker-service
Copy link

cla-checker-service bot commented Aug 6, 2021

❌ Author of the following commits did not sign a Contributor Agreement:
31a8d4f, 39a86bb, 204b5dd, 6f65f6d, 1a749bc, 7648b35

Please, read and sign the above mentioned agreement if you want to contribute to this project

@github-actions github-actions bot added agent-java community Issues and PRs created by the community labels Aug 6, 2021
@apmmachine
Copy link
Contributor

apmmachine commented Aug 6, 2021

❕ Build Aborted

The PR is not allowed to run in the CI yet

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Reason: The PR is not allowed to run in the CI yet

  • Start Time: 2021-08-20T11:39:17.923+0000

  • Duration: 3 min 16 sec

  • Commit: 7648b35

Trends 🧪

Image of Build Times

Steps errors 2

Expand to view the steps failures

Load a resource file from a shared library
  • Took 0 min 0 sec . View more details on here
  • Description: approval-list/elastic/apm-agent-java.yml
Error signal
  • Took 0 min 0 sec . View more details on here
  • Description: githubPrCheckApproved: The PR is not allowed to run in the CI yet. (Only users with write permissions can do so.)

Log output

Expand to view the last 100 lines of log output

[2021-08-20T11:42:04.979Z]  > git config --get remote.origin.url # timeout=10
[2021-08-20T11:42:04.991Z] using GIT_ASKPASS to set credentials GitHub user @apmmachine User + Personal Access Token
[2021-08-20T11:42:04.993Z]  > git merge 849b1f55429ef6189307483f1d1ff47e19b535b0 # timeout=10
[2021-08-20T11:42:05.310Z]  > git rev-parse HEAD^{commit} # timeout=10
[2021-08-20T11:42:05.320Z]  > git config core.sparsecheckout # timeout=10
[2021-08-20T11:42:05.327Z]  > git checkout -f 52440395a1f5362c46d7c1cf555a2204b1d5cef7 # timeout=100
[2021-08-20T11:42:09.872Z] Commit message: "Merge commit '849b1f55429ef6189307483f1d1ff47e19b535b0' into HEAD"
[2021-08-20T11:42:09.876Z]  > git rev-list --no-walk 7648b351b08ac1cef27e566604ab824ceab25a6e # timeout=10
[2021-08-20T11:42:10.592Z] Masking supported pattern matches of $JOB_GCS_BUCKET or $NOTIFY_TO
[2021-08-20T11:42:10.665Z] Timeout set to expire in 1 hr 30 min
[2021-08-20T11:42:10.680Z] The timestamps step is unnecessary when timestamps are enabled for all Pipeline builds.
[2021-08-20T11:42:10.950Z] [INFO] Number of builds to be searched 10
[2021-08-20T11:42:11.272Z] [INFO] 'shallow' is forced to be disabled when running on PullRequests
[2021-08-20T11:42:11.290Z] Running in /var/lib/jenkins/workspace/_java_apm-agent-java-mbp_PR-1964/src/github.com/elastic/apm-agent-java
[2021-08-20T11:42:11.313Z] [INFO] gitCheckout: Checkout SCM PR-1964 with some customisation.
[2021-08-20T11:42:11.354Z] [INFO] Override default checkout
[2021-08-20T11:42:11.409Z] Sleeping for 10 sec
[2021-08-20T11:42:21.418Z] The recommended git tool is: git
[2021-08-20T11:42:21.735Z] using credential 2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken
[2021-08-20T11:42:21.752Z] Cloning the remote Git repository
[2021-08-20T11:42:21.812Z] Cloning repository https://github.com/elastic/apm-agent-java.git
[2021-08-20T11:42:21.926Z]  > git init /var/lib/jenkins/workspace/_java_apm-agent-java-mbp_PR-1964/src/github.com/elastic/apm-agent-java # timeout=10
[2021-08-20T11:42:21.940Z] Using reference repository: /var/lib/jenkins/.git-references/apm-agent-java.git
[2021-08-20T11:42:21.940Z] Fetching upstream changes from https://github.com/elastic/apm-agent-java.git
[2021-08-20T11:42:21.941Z]  > git --version # timeout=10
[2021-08-20T11:42:21.947Z]  > git --version # 'git version 2.17.1'
[2021-08-20T11:42:21.947Z] using GIT_ASKPASS to set credentials GitHub user @apmmachine User + Personal Access Token
[2021-08-20T11:42:21.948Z]  > git fetch --tags --progress -- https://github.com/elastic/apm-agent-java.git +refs/heads/*:refs/remotes/origin/* # timeout=10
[2021-08-20T11:42:22.853Z] Checking out Revision 7648b351b08ac1cef27e566604ab824ceab25a6e (origin/PR-1964)
[2021-08-20T11:42:23.067Z] Commit message: "Implement Kotlin Coroutines Plugin"
[2021-08-20T11:42:22.510Z]  > git config remote.origin.url https://github.com/elastic/apm-agent-java.git # timeout=10
[2021-08-20T11:42:22.513Z]  > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
[2021-08-20T11:42:22.523Z]  > git config remote.origin.url https://github.com/elastic/apm-agent-java.git # timeout=10
[2021-08-20T11:42:22.530Z] Fetching upstream changes from https://github.com/elastic/apm-agent-java.git
[2021-08-20T11:42:22.530Z] using GIT_ASKPASS to set credentials GitHub user @apmmachine User + Personal Access Token
[2021-08-20T11:42:22.532Z]  > git fetch --tags --progress -- https://github.com/elastic/apm-agent-java.git +refs/pull/1964/head:refs/remotes/origin/PR-1964 +refs/heads/master:refs/remotes/origin/master # timeout=10
[2021-08-20T11:42:22.849Z]  > git rev-parse origin/PR-1964^{commit} # timeout=10
[2021-08-20T11:42:22.857Z]  > git config core.sparsecheckout # timeout=10
[2021-08-20T11:42:22.863Z]  > git checkout -f 7648b351b08ac1cef27e566604ab824ceab25a6e # timeout=10
[2021-08-20T11:42:23.071Z]  > git rev-list --no-walk 7648b351b08ac1cef27e566604ab824ceab25a6e # timeout=10
[2021-08-20T11:42:23.786Z] Masking supported pattern matches of $GIT_USERNAME or $GIT_PASSWORD
[2021-08-20T11:42:24.502Z] + git fetch https://****:****@github.com/elastic/apm-agent-java.git +refs/pull/*/head:refs/remotes/origin/pr/*
[2021-08-20T11:42:25.587Z] Running in /var/lib/jenkins/workspace/_java_apm-agent-java-mbp_PR-1964/src/github.com/elastic/apm-agent-java/.git
[2021-08-20T11:42:25.719Z] Archiving artifacts
[2021-08-20T11:42:27.014Z] + git rev-parse HEAD
[2021-08-20T11:42:27.382Z] + git rev-parse HEAD
[2021-08-20T11:42:27.715Z] + git rev-parse origin/pr/1964
[2021-08-20T11:42:27.762Z] [INFO] githubEnv: Found Git Build Cause: pr
[2021-08-20T11:42:28.009Z] Masking supported pattern matches of $GITHUB_TOKEN
[2021-08-20T11:42:28.899Z] [WARN] githubApiCall: The REST API call https://api.github.com/repos/elastic/apm-agent-java/pulls/1964/reviews return 0 elements
[2021-08-20T11:42:29.054Z] [INFO] githubPrCheckApproved: Title: Implement Kotlin Coroutines Plugin - User: bastrich - Author Association: FIRST_TIME_CONTRIBUTOR
[2021-08-20T11:42:29.545Z] ERROR: githubPrCheckApproved: The PR is not allowed to run in the CI yet
[2021-08-20T11:42:29.545Z] ERROR: githubPrCheckApproved: The PR is not allowed to run in the CI yet. (Only users with write permissions can do so.)
[2021-08-20T11:42:29.629Z] [INFO] Let's stop build #11. The PR is not allowed to run in the CI yet
[2021-08-20T11:42:29.664Z] Sleeping for 5 sec
[2021-08-20T11:42:30.712Z] Stage "Build" skipped due to earlier failure(s)
[2021-08-20T11:42:30.908Z] Stage "Tests" skipped due to earlier failure(s)
[2021-08-20T11:42:31.062Z] Stage "Unit Tests" skipped due to earlier failure(s)
[2021-08-20T11:42:31.065Z] Stage "Smoke Tests 01" skipped due to earlier failure(s)
[2021-08-20T11:42:31.067Z] Stage "Smoke Tests 02" skipped due to earlier failure(s)
[2021-08-20T11:42:31.068Z] Stage "Benchmarks" skipped due to earlier failure(s)
[2021-08-20T11:42:31.069Z] Stage "Javadoc" skipped due to earlier failure(s)
[2021-08-20T11:42:31.183Z] Failed in branch Unit Tests
[2021-08-20T11:42:31.184Z] Failed in branch Smoke Tests 01
[2021-08-20T11:42:31.185Z] Failed in branch Smoke Tests 02
[2021-08-20T11:42:31.185Z] Failed in branch Benchmarks
[2021-08-20T11:42:31.186Z] Failed in branch Javadoc
[2021-08-20T11:42:31.267Z] Stage "Integration Tests" skipped due to earlier failure(s)
[2021-08-20T11:42:31.317Z] Stage "Unit Tests" skipped due to earlier failure(s)
[2021-08-20T11:42:31.434Z] Stage "Matrix - JAVA_VERSION = 'java12'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.435Z] Stage "Matrix - JAVA_VERSION = 'openjdk12'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.437Z] Stage "Matrix - JAVA_VERSION = 'openjdk13'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.437Z] Stage "Matrix - JAVA_VERSION = 'openjdk14'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.438Z] Stage "Matrix - JAVA_VERSION = 'openjdk15'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.439Z] Stage "Matrix - JAVA_VERSION = 'openjdk16'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.510Z] Stage "Matrix - JAVA_VERSION = 'java12'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.511Z] Stage "Matrix - JAVA_VERSION = 'openjdk12'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.512Z] Stage "Matrix - JAVA_VERSION = 'openjdk13'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.513Z] Stage "Matrix - JAVA_VERSION = 'openjdk14'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.514Z] Stage "Matrix - JAVA_VERSION = 'openjdk15'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.515Z] Stage "Matrix - JAVA_VERSION = 'openjdk16'" skipped due to earlier failure(s)
[2021-08-20T11:42:31.732Z] Failed in branch Matrix - JAVA_VERSION = 'java12'
[2021-08-20T11:42:31.732Z] Failed in branch Matrix - JAVA_VERSION = 'openjdk12'
[2021-08-20T11:42:31.733Z] Failed in branch Matrix - JAVA_VERSION = 'openjdk13'
[2021-08-20T11:42:31.734Z] Failed in branch Matrix - JAVA_VERSION = 'openjdk14'
[2021-08-20T11:42:31.735Z] Failed in branch Matrix - JAVA_VERSION = 'openjdk15'
[2021-08-20T11:42:31.735Z] Failed in branch Matrix - JAVA_VERSION = 'openjdk16'
[2021-08-20T11:42:31.823Z] Stage "Stable" skipped due to earlier failure(s)
[2021-08-20T11:42:31.875Z] Stage "AfterRelease" skipped due to earlier failure(s)
[2021-08-20T11:42:31.902Z] Stage "AfterRelease" skipped due to earlier failure(s)
[2021-08-20T11:42:32.671Z] Running on Jenkins in /var/lib/jenkins/workspace/_java_apm-agent-java-mbp_PR-1964
[2021-08-20T11:42:32.896Z] [INFO] getVaultSecret: Getting secrets
[2021-08-20T11:42:32.990Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2021-08-20T11:42:34.066Z] + chmod 755 generate-build-data.sh
[2021-08-20T11:42:34.066Z] + ./generate-build-data.sh https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-java/apm-agent-java-mbp/PR-1964/ https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-java/apm-agent-java-mbp/PR-1964/runs/11 ABORTED 195826
[2021-08-20T11:42:34.066Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-java/apm-agent-java-mbp/PR-1964/runs/11/steps/?limit=10000 -o steps-info.json
[2021-08-20T11:42:34.617Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-java/apm-agent-java-mbp/PR-1964/runs/11/tests/?status=FAILED -o tests-errors.json
[2021-08-20T11:42:34.617Z] Retry 1/3 exited 22, retrying in 1 seconds...
[2021-08-20T11:42:35.960Z] Retry 2/3 exited 22, retrying in 2 seconds...
[2021-08-20T11:42:37.822Z] Retry 3/3 exited 22, no more retries left.

@bastrich
Copy link
Author

bastrich commented Aug 6, 2021

Do I need to change project.version manually or here is automatic version bump?

@bastrich
Copy link
Author

bastrich commented Aug 8, 2021

@felixbarny should I add you to this PR? or how can it be reviewed?

@SylvainJuge SylvainJuge added the new-feature New feature label Aug 30, 2021
@thecloudgeek
Copy link

can we get this one implemented soon?

@bastrich
Copy link
Author

bastrich commented Sep 27, 2021

can we get this one implemented soon?

@thecloudgeek
not sure, see this thread on the forum - https://discuss.elastic.co/t/support-kotlin-coroutines/281846

but generally it works, you can copy the source code and build your own plugin

@patiramyadav
Copy link

patiramyadav commented Sep 30, 2021

2021-09-29 22:35:46,880 [reactor-http-nio-3] DEBUG co.elastic.apm.agent.mdc.MdcActivationListener - Class loader jdk.internal.loader.ClassLoaders$AppClassLoader@9e89d68 cannot load JBoss Logging API
java.lang.ClassNotFoundException: org.jboss.logging.MDC
	at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[?:?]
	at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[?:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[?:?]
	at co.elastic.apm.agent.mdc.MdcActivationListener$4.get(MdcActivationListener.java:100) ~[elastic-apm-agent-1.26.1-SNAPSHOT.jar:?]
	at co.elastic.apm.agent.mdc.MdcActivationListener$4.get(MdcActivationListener.java:94) ~[elastic-apm-agent-1.26.1-SNAPSHOT.jar:?]

I have

    // logging deps
    implementation 'io.github.microutils:kotlin-logging:1.7.2'

Also, I am getting different trace_id per new worker.

2021-09-29 22:35:48,227 [DefaultDispatcher-worker-3] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - increment references to 'ServiceMock1#getInfo' 00-8385000b2c131fcae6d6a9fd33ca45a2-8826411e77b78d6e-01 (167552e9) (7)
2021-09-29 22:35:48,232 [DefaultDispatcher-worker-4] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - decrement references to 'ServiceMock2#getAddress' 00-4022731725eace998eca7563100293a3-a5e3cb943a1878fe-01 (4dd1c65e) (8)

I don't see any ways to correlate these coroutines logs of same transaction.

private CoroutineConstructorAdvice() {
}

@Advice.OnMethodEnter(suppress = Throwable.class)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think we also need to include inline=false like: @Advice.OnMethodEnter(suppress = Throwable.class, inline = false)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it fix the issue above?

Copy link

@patiramyadav patiramyadav Oct 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bastrich No, doesn't fix. I see major problem here. @jerryjpark has same problem also.
I see the main problem is reflection for java version 11. Reflection is disabled in java version 11.

  • | java.lang.NoSuchFieldException: span
    -- | --

  | Oct 11, 2021 @ 08:45:25.689 | - | at java.base/java.lang.Class.getDeclaredField(Unknown Source)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.AbstractCoroutine.onCompleted(AbstractCoroutine.kt:82)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.AbstractCoroutine.onCompletionInternal(AbstractCoroutine.kt:104)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.JobSupport.tryFinalizeSimpleState(JobSupport.kt:294)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:853)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:825)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:209)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:194)

  | Oct 11, 2021 @ 08:45:25.689 | - | at ..service.$suspendImpl(ABCService.kt:319)

  | Oct 11, 2021 @ 08:45:25.689 | - | at ..abc.mockServic(ABCService.kt:1)

  | Oct 11, 2021 @ 08:45:25.689 | - | at model$mock$2$mock$1.invokeSuspend(ABC.kt:95)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)

  | Oct 11, 2021 @ 08:45:25.689 | - | at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)

Copy link

@patiramyadav patiramyadav Oct 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have to write code without reflection like:

public abstract class KotlinCoroutineInstrumentation extends TracerAwareInstrumentation {
    private static final Logger log = LoggerFactory.getLogger(KotlinCoroutineInstrumentation.class);
    public static final WeakConcurrentMap<Object, AbstractSpan<?>> promisesToContext =
        new WeakConcurrentMap.WithInlinedExpunction<>();

    @Nonnull
    @Override
    public Collection<String> getInstrumentationGroupNames() {
        return Arrays.asList("kotlin-coroutine", "experimental");
    }

    public static class ConstructorInstrumentation extends KotlinCoroutineInstrumentation {
        @Override
        public ElementMatcher<? super TypeDescription> getTypeMatcher() {
            return named("kotlinx.coroutines.AbstractCoroutine");
        }

        @Override
        public ElementMatcher<? super MethodDescription> getMethodMatcher() {
            return isConstructor();
        }

        public static class AdviceClass {
            @Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
            public static void onEnter(@Advice.This Object thiz) {
                log.info("what is thiz" + thiz);
                log.info("What has promisesToContext" + promisesToContext);
                final AbstractSpan<?> context = tracer.getActive();
                if (context != null) {
                    promisesToContext.put(thiz, context);
                    context.incrementReferences();
                    context.setNonDiscardable();
                }
            }
        }
    }
..................

I am new to kotlin world. Also, we are using graphql heavily which is also new. @bastrich Could you have some idea this way? I definitely needs time to understand the depth of kotlin's coroutines first.

@jerryjpark
Copy link

jerryjpark commented Oct 1, 2021

Is there anything that needs to be configured like JVM configs for this AOP code to work? I'm getting below error when I launch the application from CLI. It is currently working for me only when I run the application in IntelliJ IDEA.

java.lang.IllegalStateException: Error invoking (accessor)::defineClass
	at co.elastic.apm.agent.shaded.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$UsingUnsafeInjection.defineClass(ClassInjector.java:1024)
	at co.elastic.apm.agent.shaded.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.injectRaw(ClassInjector.java:276)
	at co.elastic.apm.agent.shaded.bytebuddy.dynamic.loading.ClassInjector$AbstractBase.inject(ClassInjector.java:113)
	at co.elastic.apm.agent.shaded.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:233)
	at co.elastic.apm.agent.shaded.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default.load(ClassLoadingStrategy.java:144)
	at co.elastic.apm.agent.shaded.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:100)
	at co.elastic.apm.agent.shaded.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:6154)
	at kotlinx.coroutines.AbstractCoroutine.<init>(AbstractCoroutine.kt:35)
	at kotlinx.coroutines.AbstractCoroutine.<init>(AbstractCoroutine.kt:41)
	at kotlinx.coroutines.future.CompletableFutureCoroutine.<init>(Future.kt:51)
	at kotlinx.coroutines.future.FutureKt.future(Future.kt:42)

@bastrich
Copy link
Author

@jerryjpark how do you build and add an elastic apm dependency? which kotlin version?

@jerryjpark
Copy link

jerryjpark commented Oct 11, 2021

@bastrich thanks for your reply. I don't have access to my computer now and I won't for couple more days.

I should've shared with you more of the stack trace. The underlying reason (which may or may not be apparent in the stack trace I shared above) is because the Coroutine class the complaining classloader was looking for was not available to the classloader. So, yes it could have to do with the particular version of the class binary the claasloader was looking for. So, I matched the (provided scope) Kotlin dependencies for your plugin to the version of Kotlin used in our project (1.5.0) and rebuilt the plugin to rule out version mismatch as an issue. Still, I cannot say for sure that it is not a version mismatch issue until I debug the Gradle package part.

We are using Gradle and Gradle plugin to package our application with all its dependencies. We are clearly providing the correct version of the Kotlin dependencies that your plugin expects as runtime deps(at least per the Gradle project def).

Once I return to work, I plan to inspect the fat jar file to begin with to make sure the runtime Kotlin dependencies make to where they should be. Then, I will debug the class loaders if there can an issue for the Kotlin dependency to be found by the relevant classloader that throws CNFE.

@botelastic
Copy link

botelastic bot commented Dec 10, 2021

Hi! We just realized that we haven't looked into this issue in a while. We're sorry! We're labeling this issue as stalled to make it hit our filters and make sure we get back to it in as soon as possible. In the meantime, it'd be extremely helpful if you could take a look at it as well and confirm its relevance. A simple comment with a nice emoji will be enough :+1. Thank you for your contribution!

@botelastic botelastic bot added the stalled label Dec 10, 2021
@botelastic
Copy link

botelastic bot commented Dec 24, 2021

Hi! This issue has been stale for a while and we're going to close it as part of our cleanup procedure. We appreciate your contribution and would like to apologize if we have not been able to review it, due to the current heavy load of the team. Feel free to re-open this issue if you think it should stay open. Thank you for your contribution!

@botelastic botelastic bot closed this Dec 24, 2021
@samuelbirocchi
Copy link

Is this dead?

@Reizinixc
Copy link

Does anyone have a plan or picked this up recently? It seems the PR is out-of-date for a while.

My team would like to use this to implement a new service instead of doing a workaround like the existing one.

Although we're absolute novices, we may consider making some changes to this.

Currently, I successfully converted the code that uses reflection to non-reflection, but it's very limited and still breaks the app for some cases, e.g.,

  • Only -javaagent works, apm-agent-attach fails miserably to find kotlinx.coroutines.AbstractCoroutine (not sure yet why)
  • Using a suspend function without async (need to add code to support thread switching). For instance,
    coroutineScope {
        val span = ElasticApm.currentSpan().startSpan("db", "mariadb", "query")
    
        span.setName("SELECT subdivisions").activate().use {
            fun dashIfEmpty(s: String) = if (s == "") "-" else s
    
            println("1 - ${ElasticApm.currentTransaction().id.let(::dashIfEmpty)}: ${ElasticApm.currentSpan().id.let(::dashIfEmpty)} (${Thread.currentThread().name})")
            delay(300L)
            println("1A - ${ElasticApm.currentTransaction().id.let(::dashIfEmpty)}: ${ElasticApm.currentSpan().id.let(::dashIfEmpty)} (${Thread.currentThread().name})")
            span.end()
        }
    }
    1 - c99bfe8ce5f05d85: a57e817c550748c9 (http-nio-8080-exec-1)
    2022-11-14 09:57:06,835 [http-nio-8080-exec-1] WARN  co.elastic.apm.agent.impl.ActiveStack - Deactivating a context ('ExampleController#controller' 00-b7beea814b3b854c500e814a55408e1e-c99bfe8ce5f05d85-01 (595962ca)) which is not the currently active one ('SELECT subdivisions' 00-b7beea814b3b854c500e814a55408e1e-a57e817c550748c9-01 (4a06cfe3)). This can happen when not properly deactivating a previous span or context.
    1A - -: - (kotlinx.coroutines.DefaultExecutor)
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-java community Issues and PRs created by the community new-feature New feature stalled
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants