Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ This is not a breaking change, so former
* Adds <<config-span-min-duration,`span_min_duration`>> option to exclude fast executing spans.
When set together with one of the more specific thresholds - `trace_methods_duration_threshold` or `profiling_inferred_spans_min_duration`,
the higher threshold will determine which spans will be discarded.
* Automatically instrument quartz jobs from the quartz-jobs artifact {pull}1170[#1170]

[float]
===== Bug fixes
Expand Down
7 changes: 7 additions & 0 deletions apm-agent-plugins/apm-quartz-job-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
<version>${version.spring}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>${version.quartz}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static net.bytebuddy.matcher.ElementMatchers.declaresMethod;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

Expand All @@ -56,6 +57,7 @@ public JobTransactionNameInstrumentation(ElasticApmTracer tracer) {
@Override
public ElementMatcher<? super TypeDescription> getTypeMatcher() {
return isInAnyPackage(applicationPackages, ElementMatchers.<NamedElement>none())
.or(nameStartsWith("org.quartz.job"))
.and(hasSuperType(named("org.quartz.Job")))
.and(declaresMethod(getMethodMatcher()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
*/
package co.elastic.apm.agent.quartz.job;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import co.elastic.apm.agent.AbstractInstrumentationTest;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.TracerInternalApiUtils;
import co.elastic.apm.agent.impl.transaction.Transaction;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.quartz.Job;
Expand All @@ -45,12 +47,10 @@
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.jobs.DirectoryScanJob;
import org.quartz.jobs.DirectoryScanListener;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

Expand Down Expand Up @@ -159,6 +159,27 @@ void testJobWithResult() throws SchedulerException {
assertThat(reporter.getTransactions().get(0).getResult()).isEqualTo("this is the result");
}

@Test
void testDirectoryScan() throws SchedulerException, IOException {
Path directoryScanTest = Files.createTempDirectory("DirectoryScanTest");

Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("myTrigger")
.withSchedule(
SimpleScheduleBuilder.repeatSecondlyForTotalCount(1, 1))
.build();
final JobDetail job = JobBuilder.newJob(DirectoryScanJob.class)
.withIdentity("dummyJobName")
.usingJobData(DirectoryScanJob.DIRECTORY_NAME, directoryScanTest.toAbsolutePath().toString())
.usingJobData(DirectoryScanJob.DIRECTORY_SCAN_LISTENER_NAME, TestDirectoryScanListener.class.getSimpleName())
.build();

scheduler.getContext().put(TestDirectoryScanListener.class.getSimpleName(), new TestDirectoryScanListener());
scheduler.scheduleJob(job, trigger);
verifyJobDetails(job);
}

public static class TestJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
Expand Down Expand Up @@ -201,4 +222,11 @@ protected void executeInternal(JobExecutionContext context) throws JobExecutionE
}

}

public static class TestDirectoryScanListener implements DirectoryScanListener {

@Override
public void filesUpdatedOrAdded(File[] files) {
}
}
}
2 changes: 1 addition & 1 deletion docs/supported-technologies.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ When using a scheduling framework a transaction for every execution will be crea
|2.0+
|The agent instruments the `execute` method of any class implementing `org.quartz.Job`, as well as the `executeInternal` method of any class extending `org.springframework.scheduling.quartz.QuartzJobBean`, and creates a transaction with the type `scheduled`, representing the job execution

NOTE: only classes from packages configured in <<config-application-packages>> will be instrumented.
NOTE: only classes from the quartz-jobs dependency will be instrumented automatically. For the instrumentation of other jobs the package must be added to the <<config-application-packages>> parameter.
|1.8.0
|===

Expand Down