-
Notifications
You must be signed in to change notification settings - Fork 325
Add Scala concurrent plugin #1048
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
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
404f6fb
WIP
9ce7f3f
Add initial scala instrumentation for Future
milanvdm e0a4335
Remove test-dependency
milanvdm e57e2d8
Merge remote-tracking branch 'upstream/master' into add-scala-executo…
milanvdm 3ef57c0
Add first test approach
milanvdm 2dd336d
Use Java for method matching
milanvdm 167ecde
Add dummy test using Scala
milanvdm 90d0b6f
Add java-version
milanvdm 1b5b369
Add first matching instrumentation test
milanvdm f20a929
WIP
milanvdm b2d2bb7
Use MUnit
milanvdm 2feb98f
Cleanup pom
milanvdm 0af62ce
Add Future instrumentation
milanvdm f97b0b1
Add tests
milanvdm 649207b
Merge remote-tracking branch 'upstream/master' into add-scala-executo…
milanvdm 324ce67
Add plugin to release process
milanvdm 9d0eb39
Instrument ExecutionContext
milanvdm 7ab2834
Merge branch 'master' into add-scala-executor-apm
milanvdm ee6da7d
Add onStream instrumentation on AsyncHandler
milanvdm ec2b7eb
Add StreamHandler tests
milanvdm d9e0762
Merge branch 'keep-spans-active-on-stream-async-http' into add-scala-…
milanvdm 84417b0
Add Promise instrumentation
milanvdm 199e514
Merge remote-tracking branch 'upstream/master' into add-scala-executo…
milanvdm ad42993
Cleanup
milanvdm 49bca5f
Merge remote-tracking branch 'upstream/master' into add-scala-executo…
milanvdm e41f63c
Fix versions
milanvdm a0375b7
Make sure spans are not recycled
milanvdm accd469
Cleanup Java 9 compilers
milanvdm 7843966
Add docs
milanvdm 0f7b257
Merge remote-tracking branch 'upstream/master' into add-scala-executo…
milanvdm f9b8e56
Fix merge
milanvdm 063ed39
Remove Java version
milanvdm 6c638d9
Merge remote-tracking branch 'upstream/master' into add-scala-executo…
milanvdm 40033fa
Improve testing for edge cases
milanvdm 5ee2b3b
Simplify failing test
milanvdm 1721794
Add extra failing test on Future.sequence
milanvdm 737bb0e
Merge branch 'master' into add-scala-executor-apm
felixbarny 1885c8e
Add java apm dependency to test
milanvdm c893ac0
Merge remote-tracking branch 'upstream/master' into add-scala-executo…
milanvdm f844049
Bump to new snapshot version
milanvdm 0f530a0
Start tracer
milanvdm c6a6581
Merge remote-tracking branch 'upstream/master' into add-scala-executo…
milanvdm b68d3d2
Merge branch 'master' into add-scala-executor-apm
felixbarny 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
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,56 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <artifactId>apm-agent-plugins</artifactId> | ||
| <groupId>co.elastic.apm</groupId> | ||
| <version>1.17.1-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>apm-scala-concurrent-plugin</artifactId> | ||
| <name>${project.groupId}:${project.artifactId}</name> | ||
|
|
||
| <properties> | ||
| <apm-agent-parent.base.dir>${project.basedir}/../..</apm-agent-parent.base.dir> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>apm-java-concurrent-plugin</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.scalameta</groupId> | ||
| <artifactId>munit_2.13</artifactId> | ||
| <version>0.7.2</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <testSourceDirectory>src/test/scala</testSourceDirectory> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>net.alchim31.maven</groupId> | ||
| <artifactId>scala-maven-plugin</artifactId> | ||
| <version>4.3.1</version> | ||
| <configuration> | ||
| <scalaVersion>2.13.2</scalaVersion> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <id>scala-test-compile</id> | ||
| <phase>process-test-resources</phase> | ||
| <goals> | ||
| <goal>testCompile</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
milanvdm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </project> | ||
114 changes: 114 additions & 0 deletions
114
...ent-plugin/src/main/java/co/elastic/apm/agent/scala/concurrent/FutureInstrumentation.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,114 @@ | ||
| /*- | ||
| * #%L | ||
| * Elastic APM Java agent | ||
| * %% | ||
| * Copyright (C) 2018 - 2020 Elastic and contributors | ||
| * %% | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| * #L% | ||
| */ | ||
| package co.elastic.apm.agent.scala.concurrent; | ||
|
|
||
| import co.elastic.apm.agent.bci.ElasticApmInstrumentation; | ||
| import co.elastic.apm.agent.bci.VisibleForAdvice; | ||
| import co.elastic.apm.agent.impl.transaction.AbstractSpan; | ||
| import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.method.MethodDescription; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| import static net.bytebuddy.matcher.ElementMatchers.*; | ||
|
|
||
| public abstract class FutureInstrumentation extends ElasticApmInstrumentation { | ||
|
|
||
| @VisibleForAdvice | ||
| @SuppressWarnings("WeakerAccess") | ||
| public static final WeakConcurrentMap<Object, AbstractSpan<?>> promisesToContext = | ||
| new WeakConcurrentMap.WithInlinedExpunction<>(); | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public Collection<String> getInstrumentationGroupNames() { | ||
| return Arrays.asList("scala-future", "experimental"); | ||
| } | ||
|
|
||
| public static class ConstructorInstrumentation extends FutureInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super TypeDescription> getTypeMatcher() { | ||
| return named("scala.concurrent.impl.Promise$Transformation"); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super MethodDescription> getMethodMatcher() { | ||
| return isConstructor(); | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| public static void onExit(@Advice.This Object thiz) { | ||
| final AbstractSpan<?> context = getActive(); | ||
| if (context != null) { | ||
| promisesToContext.put(thiz, context); | ||
milanvdm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // this span might be ended before the Promise$Transformation#run method starts | ||
| // we have to avoid that this span gets recycled, even in the above mentioned case | ||
| context.incrementReferences(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public static class RunInstrumentation extends FutureInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super TypeDescription> getTypeMatcher() { | ||
| return named("scala.concurrent.impl.Promise$Transformation"); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super MethodDescription> getMethodMatcher() { | ||
| return named("run").and(returns(void.class)); | ||
| } | ||
|
|
||
| @VisibleForAdvice | ||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| public static void onEnter(@Advice.This Object thiz, @Nullable @Advice.Local("context") AbstractSpan<?> context) { | ||
| context = promisesToContext.remove(thiz); | ||
| if (tracer != null && context != null) { | ||
| tracer.activate(context); | ||
milanvdm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // decrements the reference we incremented to avoid that the parent context gets recycled before the promise is run | ||
| // because we have activated it, we can be sure it doesn't get recycled until we deactivate in the OnMethodExit advice | ||
| context.decrementReferences(); | ||
| } | ||
| } | ||
|
|
||
| @Advice.OnMethodExit(suppress = Throwable.class) | ||
| public static void onExit(@Nullable @Advice.Local("context") AbstractSpan<?> context) { | ||
| if (tracer != null && context != null) { | ||
| tracer.deactivate(context); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
2 changes: 2 additions & 0 deletions
2
...n/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
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,2 @@ | ||
| co.elastic.apm.agent.scala.concurrent.FutureInstrumentation$ConstructorInstrumentation | ||
| co.elastic.apm.agent.scala.concurrent.FutureInstrumentation$RunInstrumentation |
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.