use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class MemcachedClient_Instrumentation method reportDatastoreMetricsAsync.
// Async reporting - overload for OperationsFuture
private void reportDatastoreMetricsAsync(String op, OperationFuture<?> future) {
String host = null;
Integer port = null;
try {
MemcachedNode memcachedNode = MemcachedUtil.OPERATION_NODE.get();
if (memcachedNode != null) {
SocketAddress address = memcachedNode.getSocketAddress();
if (address instanceof InetSocketAddress) {
InetSocketAddress nodeAddress = (InetSocketAddress) address;
host = nodeAddress.getHostName();
port = nodeAddress.getPort();
}
}
} catch (Throwable t) {
AgentBridge.getAgent().getLogger().log(Level.FINER, t, "Unable to capture host/port for memcached operation");
} finally {
MemcachedUtil.OPERATION_NODE.set(null);
}
final Segment segment = AgentBridge.getAgent().getTransaction().createAndStartTracedActivity();
if (segment != null) {
ExternalParameters params = DatastoreParameters.product("Memcached").collection("cache").operation(op).instance(host, port).build();
segment.reportAsExternal(params);
if (future.isDone()) {
segment.endAsync();
} else {
future.addListener(new OperationCompletionListener(segment));
}
}
}
use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class MemcachedClient_Instrumentation method reportDatastoreMetricsAsync.
/**
* Async reporting - overload for GetFuture
*
* Create traced activity and call reportAsExternal on the traced activitiy TracedMethod.
*
* Callers of this helper should not have an @Trace.
*
* @param op Operation to report
* @param future Future to add listener to.
*/
private void reportDatastoreMetricsAsync(String op, GetFuture<?> future) {
String host = null;
Integer port = null;
try {
MemcachedNode memcachedNode = MemcachedUtil.OPERATION_NODE.get();
if (memcachedNode != null) {
SocketAddress address = memcachedNode.getSocketAddress();
if (address instanceof InetSocketAddress) {
InetSocketAddress nodeAddress = (InetSocketAddress) address;
host = nodeAddress.getHostName();
port = nodeAddress.getPort();
}
}
} catch (Throwable t) {
AgentBridge.getAgent().getLogger().log(Level.FINER, t, "Unable to capture host/port for memcached operation");
} finally {
MemcachedUtil.OPERATION_NODE.set(null);
}
if (AgentBridge.getAgent().getTransaction(false) != null) {
final Segment segment = NewRelic.getAgent().getTransaction().startSegment(op);
ExternalParameters params = DatastoreParameters.product("Memcached").collection("cache").operation(op).instance(host, port).build();
segment.reportAsExternal(params);
if (future.isDone()) {
segment.endAsync();
} else {
future.addListener(new GetCompletionListener(segment));
}
}
}
use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class MemcachedClient_Instrumentation method reportDatastoreMetricsAsync.
/**
* Async reporting - overload for BulkFuture
*
* Create traced activity and call reportAsExternal on the traced activitiy TracedMethod.
*
* Callers of this helper should not have an @Trace.
*
* @param op Operation to report
* @param future Future to add listener to.
*/
private void reportDatastoreMetricsAsync(String op, BulkFuture<?> future) {
String host = null;
Integer port = null;
// This is where we would normally grab the host and port for the instance metrics from the MemcachedNode
// instrumentation. But for a bulk operation like this one, this would be incorrect, because the bulk operation
// can send off a whole bunch of operations to multiple memcached servers, while this logic is only capable of
// capturing instance information for one of them. Tracked by JAVA-2640.
// Let's clear the thread local despite the fact that we didn't use it.
MemcachedUtil.OPERATION_NODE.set(null);
if (AgentBridge.getAgent().getTransaction(false) != null) {
final Segment segment = NewRelic.getAgent().getTransaction().startSegment(op);
ExternalParameters params = DatastoreParameters.product("Memcached").collection("cache").operation(op).instance(host, port).build();
segment.reportAsExternal(params);
if (future.isDone()) {
segment.endAsync();
} else {
future.addListener(new BulkGetCompletionListener(segment));
}
}
}
use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testNoPortSupportabilityMetrics.
@Test
public void testNoPortSupportabilityMetrics() {
DefaultTracer tracer = prepareTracer();
String product = "Product";
ExternalParameters parameters = DatastoreParameters.product(product).collection("Collection").operation("operation").instance("myHost", 12345).databaseName("databaseName").build();
tracer.reportAsExternal(parameters);
tracer.finish(0, null);
checkUnknownDatastoreSupportabilityMetrics("Product", 0, 0, 0);
}
use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testAllSupportabilityMetrics.
@Test
public void testAllSupportabilityMetrics() {
DefaultTracer tracer = prepareTracer();
String unknownPort = null;
String unknownHost = null;
String product = "Product";
ExternalParameters parameters = DatastoreParameters.product(product).collection("Collection").operation("operation").instance(unknownHost, unknownPort).noDatabaseName().build();
tracer.reportAsExternal(parameters);
tracer.finish(0, null);
checkUnknownDatastoreSupportabilityMetrics("Product", 1, 1, 1);
}
Aggregations