use of com.newrelic.api.agent.Segment 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.Segment 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.Segment 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.Segment in project newrelic-java-agent by newrelic.
the class TransactionApiImpl method startSegment.
@Override
public Segment startSegment(String category, String segmentName) {
Transaction tx = getTransactionIfExists();
if (null == tx) {
return NoOpSegment.INSTANCE;
}
if (category == null || category.isEmpty()) {
// maybe log?
category = MetricNames.CUSTOM;
}
if (segmentName == null || segmentName.isEmpty()) {
// maybe log?
segmentName = com.newrelic.agent.Segment.UNNAMED_SEGMENT;
}
Segment segment = tx.startSegment(category, segmentName);
return segment == null ? NoOpSegment.INSTANCE : segment;
}
use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.
the class ExternalAsyncTest method startSegment.
private static Segment startSegment(OutboundHeaders outbound) {
Segment externalEvent = NewRelic.getAgent().getTransaction().startSegment(ASYNC_TXA_NAME);
Assert.assertNotNull(externalEvent);
externalEvent.addOutboundRequestHeaders(outbound);
return externalEvent;
}
Aggregations