/
Job_Instrumentation.java
42 lines (37 loc) · 1.79 KB
/
Job_Instrumentation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package org.springframework.batch.core;
import com.newrelic.agent.bridge.AgentBridge;
import com.newrelic.agent.bridge.Transaction;
import com.newrelic.agent.bridge.TransactionNamePriority;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
@Weave(type = MatchType.Interface, originalName = "org.springframework.batch.core.Job")
public class Job_Instrumentation {
@Trace(dispatcher = true)
public void execute(JobExecution jobExecution) {
Weaver.callOriginal();
Transaction transaction = AgentBridge.getAgent().getTransaction(false);
if (transaction != null) {
String jobName = jobExecution.getJobInstance().getJobName();
transaction.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, false, "SpringBatch", "Job", jobName);
String status = jobExecution.getExitStatus().getExitCode();
if ("COMPLETED".equals(status) || "FAILED".equals(status)) {
NewRelic.incrementCounter("SpringBatch/Job/" + jobName + "/" + status);
}
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
String metricName = "SpringBatch/Job/" + jobName + "/Step/" + stepExecution.getStepName();
NewRelic.incrementCounter(metricName + "/read", stepExecution.getReadCount());
NewRelic.incrementCounter(metricName + "/write", stepExecution.getWriteCount());
NewRelic.incrementCounter(metricName + "/skip", stepExecution.getSkipCount());
}
}
}
}