Skip to content

Commit d9942db

Browse files
authored
Merge pull request #25 from newrelic/v5.0-enahancements
V5.0 enhancements
2 parents 09de438 + d502348 commit d9942db

File tree

33 files changed

+1791
-9
lines changed

33 files changed

+1791
-9
lines changed

Vertx-Cassandra-4.x/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jar {
2323
}
2424

2525
verifyInstrumentation {
26-
passes 'io.vertx:vertx-cassandra-client:[4.0.0,)'
26+
passes 'io.vertx:vertx-cassandra-client:[4.0.0,5.0.0)'
2727
excludeRegex '.*SNAPSHOT'
2828
excludeRegex '.*Beta.*'
2929
excludeRegex '.*milestone.*'

Vertx-Cassandra-5.x/build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
// Build.gradle generated for instrumentation module Vertx-Cassandra-4.x
3+
4+
apply plugin: 'java'
5+
6+
dependencies {
7+
implementation group: 'io.vertx', name: 'vertx-cassandra-client', version: '5.0.0'
8+
9+
// New Relic Labs Java Agent dependencies
10+
implementation 'com.newrelic.agent.java:newrelic-agent:6.0.0'
11+
implementation 'com.newrelic.agent.java:newrelic-api:6.0.0'
12+
implementation fileTree(include: ['*.jar'], dir: '../libs')
13+
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
14+
}
15+
16+
jar {
17+
manifest {
18+
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.Vertx-Cassandra-5.x'
19+
attributes 'Implementation-Vendor': 'New Relic Labs'
20+
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
21+
attributes 'Implementation-Version': 1.0
22+
}
23+
}
24+
25+
verifyInstrumentation {
26+
passes 'io.vertx:vertx-cassandra-client:[5.0.0,)'
27+
excludeRegex '.*SNAPSHOT'
28+
excludeRegex '.*Beta.*'
29+
excludeRegex '.*milestone.*'
30+
excludeRegex '.*CR.*'
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.newrelic.instrumentation.labs.vertx.cassandra5;
2+
3+
import java.util.Map;
4+
5+
import com.datastax.oss.driver.api.core.cql.BoundStatement;
6+
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
7+
import com.datastax.oss.driver.api.core.cql.Statement;
8+
9+
public class CassandraUtils {
10+
11+
public static void addAttribute(Map<String, Object> attributes, String key, Object value) {
12+
if(attributes != null && key != null && !key.isEmpty() && value != null) {
13+
attributes.put(key, value);
14+
}
15+
}
16+
17+
public static void addStatement(Map<String, Object> attributes,Statement<?> statement) {
18+
if (statement != null) {
19+
addAttribute(attributes, "KeySpace", statement.getKeyspace());
20+
addAttribute(attributes, "StatementType", statement.getClass().getSimpleName());
21+
if(statement instanceof BoundStatement) {
22+
addBoundStatement(attributes, (BoundStatement)statement);
23+
}
24+
}
25+
}
26+
27+
public static void addBoundStatement(Map<String, Object> attributes, BoundStatement statement) {
28+
if(statement != null) {
29+
PreparedStatement prepared = statement.getPreparedStatement();
30+
if (prepared != null) {
31+
addAttribute(attributes, "BoundStatement-Prepared-QueryString", prepared.getQuery());
32+
}
33+
}
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.newrelic.instrumentation.labs.vertx.cassandra5;
2+
3+
import java.util.logging.Level;
4+
5+
import com.newrelic.agent.bridge.AgentBridge;
6+
import com.newrelic.api.agent.Segment;
7+
import com.newrelic.api.agent.Trace;
8+
9+
import io.vertx.core.Completable;
10+
11+
public class NRCompletableListener<T> implements Completable<T> {
12+
13+
private Segment segment = null;
14+
private Completable<T> delegate = null;
15+
16+
public NRCompletableListener(Segment s) {
17+
18+
AgentBridge.getAgent().getLogger().log(Level.FINEST, "NRCompletableListener initialised with segment: {0}", s);
19+
segment = s;
20+
}
21+
22+
@Override
23+
@Trace(async = true)
24+
public void complete(T result, Throwable failure) {
25+
26+
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Complete called");
27+
if (segment != null) {
28+
segment.end();
29+
segment = null;
30+
}
31+
if (delegate != null) {
32+
33+
delegate.complete(result, failure);
34+
}
35+
}
36+
37+
@Override
38+
@Trace(async = true)
39+
public void succeed(T result) {
40+
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Succeed called");
41+
if (segment != null) {
42+
segment.end();
43+
segment = null;
44+
}
45+
if (delegate != null) {
46+
delegate.succeed(result);
47+
}
48+
}
49+
50+
@Override
51+
@Trace(async = true)
52+
public void succeed() {
53+
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Succeed (no result) called");
54+
if (segment != null) {
55+
segment.end();
56+
segment = null;
57+
}
58+
if (delegate != null) {
59+
delegate.succeed();
60+
}
61+
}
62+
63+
@Override
64+
@Trace(async = true)
65+
public void fail(Throwable failure) {
66+
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Fail (Throwable) called");
67+
if (segment != null) {
68+
segment.end();
69+
segment = null;
70+
}
71+
if (delegate != null) {
72+
delegate.fail(failure);
73+
}
74+
}
75+
76+
@Override
77+
@Trace(async = true)
78+
public void fail(String message) {
79+
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Fail (String message) called");
80+
if (segment != null) {
81+
segment.end();
82+
segment = null;
83+
}
84+
if (delegate != null) {
85+
delegate.fail(message);
86+
}
87+
}
88+
89+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package io.vertx.cassandra.impl;
2+
3+
import java.util.logging.Level;
4+
import java.util.stream.Collector;
5+
6+
import com.datastax.oss.driver.api.core.cql.Row;
7+
import com.datastax.oss.driver.api.core.cql.Statement;
8+
import com.newrelic.agent.bridge.AgentBridge;
9+
import com.newrelic.api.agent.NewRelic;
10+
import com.newrelic.api.agent.Trace;
11+
import com.newrelic.api.agent.weaver.Weave;
12+
import com.newrelic.api.agent.weaver.Weaver;
13+
import com.newrelic.instrumentation.labs.vertx.cassandra5.NRCompletableListener;
14+
15+
import io.vertx.cassandra.CassandraRowStream;
16+
import io.vertx.cassandra.ResultSet;
17+
import io.vertx.core.Future;
18+
import io.vertx.core.impl.future.FutureImpl;
19+
20+
@SuppressWarnings("rawtypes")
21+
@Weave(originalName = "io.vertx.cassandra.impl.CassandraClientImpl")
22+
public abstract class CassandraClientImpl_Instrumentation {
23+
24+
@Trace
25+
public Future<ResultSet> execute(Statement statement) {
26+
AgentBridge.getAgent().getLogger().log(Level.FINEST,
27+
"CassandraClientImpl_Instrumentation.execute called with statement: {0}", statement);
28+
Future<ResultSet> f = Weaver.callOriginal();
29+
if (f instanceof FutureImpl) {
30+
NRCompletableListener<ResultSet> listener = new NRCompletableListener<ResultSet>(
31+
NewRelic.getAgent().getTransaction().startSegment("Vertx-Cassandra"));
32+
((FutureImpl<ResultSet>) f).addListener(listener);
33+
}
34+
return f;
35+
}
36+
37+
@Trace
38+
public <R> Future<R> execute(Statement statement, Collector<Row, ?, R> collector) {
39+
Future<R> f = Weaver.callOriginal();
40+
if (f instanceof FutureImpl) {
41+
NRCompletableListener<R> listener = new NRCompletableListener<R>(
42+
NewRelic.getAgent().getTransaction().startSegment("Vertx-Cassandra"));
43+
((FutureImpl<R>) f).addListener(listener);
44+
}
45+
return f;
46+
}
47+
48+
@Trace
49+
public Future<CassandraRowStream> queryStream(Statement statement) {
50+
Future<CassandraRowStream> f = Weaver.callOriginal();
51+
if (f instanceof FutureImpl) {
52+
NRCompletableListener<CassandraRowStream> listener = new NRCompletableListener<CassandraRowStream>(
53+
NewRelic.getAgent().getTransaction().startSegment("Vertx-Cassandra"));
54+
((FutureImpl<CassandraRowStream>) f).addListener(listener);
55+
}
56+
57+
return f;
58+
}
59+
}

Vertx-JDBCClient-4.0/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jar {
2323
}
2424

2525
verifyInstrumentation {
26-
passes 'io.vertx:vertx-jdbc-client:[4.0.0,)'
26+
passes 'io.vertx:vertx-jdbc-client:[4.0.0,5.0.0)'
2727
excludeRegex '.*SNAPSHOT'
2828
excludeRegex '.*milestone.*'
2929
excludeRegex '.*Beta.*'

Vertx-MongoDB-4.0/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jar {
2323
}
2424

2525
verifyInstrumentation {
26-
passes 'io.vertx:vertx-mongo-client:[4.0.0,)'
26+
passes 'io.vertx:vertx-mongo-client:[4.0.0,5.0.0)'
2727
excludeRegex '.*SNAPSHOT'
2828
excludeRegex '.*CR.*'
2929
excludeRegex '.*Beta.*'

Vertx-RabbitMQ-4.0/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jar {
2323
}
2424

2525
verifyInstrumentation {
26-
passes 'io.vertx:vertx-rabbitmq-client:[4.0.0,)'
26+
passes 'io.vertx:vertx-rabbitmq-client:[4.0.0,5.0.0)'
2727
excludeRegex '.*SNAPSHOT.*'
2828
excludeRegex '.*milestone.*'
2929
excludeRegex '.*CR.*'

Vertx-Reactive-3.9/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jar {
2424
}
2525

2626
verifyInstrumentation {
27-
passes 'io.vertx:vertx-rx-java2:[3.9.0,)'
27+
passes 'io.vertx:vertx-rx-java2:[3.9.0,5.0.0)'
2828
excludeRegex '.*SNAPSHOT'
2929
excludeRegex '.*milestone.*'
3030
excludeRegex '.*Beta.*'

Vertx-Redis-4.3/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jar {
2323
}
2424

2525
verifyInstrumentation {
26-
passesOnly "io.vertx:vertx-redis-client:[4.3.1,)"
26+
passesOnly "io.vertx:vertx-redis-client:[4.3.1,5.0.0)"
2727
excludeRegex '.*SNAPSHOT'
2828
excludeRegex '.*milestone.*'
2929
excludeRegex '.*Beta.*'

0 commit comments

Comments
 (0)