Skip to content

Commit e5c7810

Browse files
authored
Merge branch 'master' into es-rest-client-indy
2 parents dc4aedc + 9cfc8f3 commit e5c7810

File tree

31 files changed

+139
-127
lines changed

31 files changed

+139
-127
lines changed

CHANGELOG.asciidoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ endif::[]
3535
user to configure an arbitrary agent version that will be downloaded from maven and attached - {pull}1959[#1959]
3636
* Add extra check to detect improper agent setup - {pull}2076[#2076]
3737
38+
[float]
39+
===== Performance improvements
40+
* Reduce GC time overhead caused by WeakReferences {pull}2086[2086]
41+
3842
[float]
3943
===== Bug fixes
4044
* Fix failure to parse some forms of the `Implementation-Version` property from jar manifest files - {pull}1931[#1931]
@@ -44,7 +48,7 @@ user to configure an arbitrary agent version that will be downloaded from maven
4448
4549
[float]
4650
===== Refactorings
47-
* Migrate several plugins to indy dispatcher {pull}2087[#2087], {pull}2088[#2088]
51+
* Migrate several plugins to indy dispatcher {pull}2087[#2087], {pull}2088[#2088], {pull}2090[#2090]
4852
4953
[[release-notes-1.x]]
5054
=== Java Agent version 1.x

apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcClientInstrumentationTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import co.elastic.apm.agent.impl.transaction.Transaction;
2727
import org.junit.jupiter.api.AfterEach;
2828
import org.junit.jupiter.api.BeforeEach;
29+
import org.junit.jupiter.api.Disabled;
2930
import org.junit.jupiter.api.Test;
3031
import org.junit.jupiter.params.ParameterizedTest;
3132
import org.junit.jupiter.params.provider.ValueSource;
@@ -155,6 +156,7 @@ void clientStreamingCallShouldBeIgnored() {
155156
}
156157

157158
@Test
159+
@Disabled // disabled for now as it's flaky on CI
158160
void serverStreamingCallShouldBeIgnored() {
159161
String s = app.sayHelloServerStreaming("alice", 5);
160162
assertThat(s)

apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/StatementInstrumentation.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,29 @@ public static void onAfterExecute(@Advice.This Statement statement,
336336

337337
}
338338

339+
/**
340+
* Instruments:
341+
* <ul>
342+
* <li>{@link Statement#close()}</li>
343+
* </ul>
344+
*/
345+
public static class CloseStatementInstrumentation extends StatementInstrumentation {
346+
347+
private static final JdbcHelper helper = JdbcHelper.get();
348+
349+
public CloseStatementInstrumentation(ElasticApmTracer tracer) {
350+
super(
351+
named("close")
352+
.and(takesArguments(0))
353+
.and(isPublic())
354+
);
355+
}
356+
357+
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
358+
public static void onBeforeClose(@Advice.This Statement statement) {
359+
if (statement instanceof PreparedStatement) {
360+
helper.removeSqlForStatement(statement);
361+
}
362+
}
363+
}
339364
}

apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ private static void markNotSupported(JdbcFeature feature, Class<?> type, SQLExce
213213
}
214214
}
215215

216+
public void removeSqlForStatement(Statement statement) {
217+
statementSqlMap.remove(statement);
218+
}
219+
216220
/**
217221
* Represent JDBC features for which availability has to be checked at runtime
218222
*/

apm-agent-plugins/apm-jdbc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ co.elastic.apm.agent.jdbc.StatementInstrumentation$ExecuteUpdateNoQueryInstrumen
55
co.elastic.apm.agent.jdbc.StatementInstrumentation$AddBatchInstrumentation
66
co.elastic.apm.agent.jdbc.StatementInstrumentation$ExecuteBatchInstrumentation
77
co.elastic.apm.agent.jdbc.StatementInstrumentation$ExecutePreparedStatementInstrumentation
8+
co.elastic.apm.agent.jdbc.StatementInstrumentation$CloseStatementInstrumentation

apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/AbstractJdbcInstrumentationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ private void testPreparedStatementUpdate(PreparedStatementExecutor<Number> state
305305
reporter.reset();
306306
// unique key violation
307307
assertThatThrownBy(() -> statementConsumer.withStatement(statement)).isInstanceOf(SQLException.class);
308+
int mappedStatements = JdbcGlobalState.statementSqlMap.approximateSize();
309+
statement.close();
310+
assertThat(JdbcGlobalState.statementSqlMap.approximateSize()).isLessThan(mappedStatements);
308311
Span span = assertSpanRecorded(insert, false, -1);
309312
assertThat(span.getOutcome()).isEqualTo(Outcome.FAILURE);
310313
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package co.elastic.apm.agent.redis.jedis;
19+
package co.elastic.apm.agent.jedis;
2020

2121
import org.junit.jupiter.api.AfterEach;
2222
import org.junit.jupiter.api.BeforeEach;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package co.elastic.apm.agent.redis.jedis;
19+
package co.elastic.apm.agent.jedis;
2020

2121
class Jedis3InstrumentationTest extends Jedis2InstrumentationTest {
2222

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package co.elastic.apm.agent.redis.jedis;
19+
package co.elastic.apm.agent.jedis;
2020

2121
import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
2222
import co.elastic.apm.agent.impl.transaction.Span;
@@ -41,21 +41,23 @@
4141

4242
public class JedisInstrumentation extends TracerAwareInstrumentation {
4343

44-
@Advice.OnMethodEnter(suppress = Throwable.class)
45-
private static void beforeSendCommand(@Advice.This(typing = Assigner.Typing.DYNAMIC) BinaryJedis thiz,
46-
@Advice.Local("span") Span span,
47-
@Advice.Origin("#m") String method) {
48-
span = RedisSpanUtils.createRedisSpan(method);
44+
@Nullable
45+
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
46+
public static Object beforeSendCommand(@Advice.This(typing = Assigner.Typing.DYNAMIC) BinaryJedis thiz,
47+
@Advice.Origin("#m") String method) {
48+
Span span = RedisSpanUtils.createRedisSpan(method);
4949
if (span != null) {
5050
span.getContext().getDestination()
5151
.withAddress(thiz.getClient().getHost())
5252
.withPort(thiz.getClient().getPort());
5353
}
54+
return span;
5455
}
5556

56-
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
57-
private static void afterSendCommand(@Nullable @Advice.Local("span") Span span,
58-
@Nullable @Advice.Thrown Throwable thrown) {
57+
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
58+
public static void afterSendCommand(@Nullable @Advice.Enter Object spanObj,
59+
@Nullable @Advice.Thrown Throwable thrown) {
60+
Span span = (Span) spanObj;
5961
if (span != null) {
6062
span.captureException(thrown)
6163
.deactivate()
@@ -84,8 +86,4 @@ public Collection<String> getInstrumentationGroupNames() {
8486
return Arrays.asList("redis", "jedis");
8587
}
8688

87-
@Override
88-
public boolean indyPlugin() {
89-
return false;
90-
}
9189
}
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package co.elastic.apm.agent.redis.jedis;
19+
package co.elastic.apm.agent.jedis;
2020

2121
import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
2222
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
@@ -42,15 +42,13 @@
4242
*/
4343
public class JedisSpanNameInstrumentation extends TracerAwareInstrumentation {
4444

45-
@Advice.OnMethodEnter
46-
private static void setSpanNameToRedisProtocolCommand(@Advice.Argument(1) Object command) {
47-
if (tracer != null) {
48-
AbstractSpan<?> active = tracer.getActive();
49-
if (active instanceof Span) {
50-
Span activeSpan = (Span) active;
51-
if ("redis".equals(activeSpan.getSubtype())) {
52-
activeSpan.withName(command.toString());
53-
}
45+
@Advice.OnMethodEnter(inline = false)
46+
public static void setSpanNameToRedisProtocolCommand(@Advice.Argument(1) Object command) {
47+
AbstractSpan<?> active = tracer.getActive();
48+
if (active instanceof Span) {
49+
Span activeSpan = (Span) active;
50+
if ("redis".equals(activeSpan.getSubtype())) {
51+
activeSpan.withName(command.toString());
5452
}
5553
}
5654
}
@@ -74,8 +72,4 @@ public Collection<String> getInstrumentationGroupNames() {
7472
return Arrays.asList("redis", "jedis");
7573
}
7674

77-
@Override
78-
public boolean indyPlugin() {
79-
return false;
80-
}
8175
}

0 commit comments

Comments
 (0)