use of com.newrelic.api.agent.TracedMethod in project newrelic-java-agent by newrelic.
the class DB_Weave method command.
/*
* Command calls db.$cmd.find({command}). Since that isn't actually a find operation we want to include its metrics
* in this tracer. Hence, this tracer is a leaf.
*/
@Trace(leaf = true)
public CommandResult command(final DBObject command, final ReadPreference readPreference, final DBEncoder encoder) {
String commandName = null;
String collectionName = null;
try {
commandName = command.keySet().iterator().next();
collectionName = String.valueOf(command.get(commandName));
} catch (NoSuchElementException nse) {
NewRelic.getAgent().getLogger().log(Level.FINER, "WARNING: Could not determine mongo command name.");
commandName = MongoUtil.DEFAULT_OPERATION;
collectionName = MongoUtil.DEFAULT_COLLECTION;
}
CommandResult result = Weaver.callOriginal();
TracedMethod tracedMethod = NewRelic.getAgent().getTracedMethod();
DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.MongoDB.name()).collection(collectionName).operation(commandName).instance(getMongo().getAddress().getHost(), getMongo().getAddress().getPort()).databaseName(getName()).build();
tracedMethod.reportAsExternal(params);
return result;
}
use of com.newrelic.api.agent.TracedMethod in project newrelic-java-agent by newrelic.
the class NettyDispatcher method channelRead.
@Trace(dispatcher = true)
public static void channelRead(ChannelHandlerContext_Instrumentation ctx, Object msg) {
ctx.pipeline().token = AgentBridge.getAgent().getTransaction().getToken();
TracedMethod tracer = AgentBridge.getAgent().getTransaction().getTracedMethod();
if (tracer == null) {
// it happens.
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Unable to dispatch netty tx. No tracer.");
} else {
tracer.setMetricName("NettyUpstreamDispatcher");
AgentBridge.getAgent().getTransaction().setTransactionName(TransactionNamePriority.SERVLET_NAME, true, "NettyDispatcher", "NettyDispatcher");
}
Transaction tx = AgentBridge.getAgent().getTransaction(false);
if (tx != null) {
tx.setWebRequest(new RequestWrapper((HttpRequest) msg));
}
}
use of com.newrelic.api.agent.TracedMethod in project newrelic-java-agent by newrelic.
the class CircuitBreakerApiTest method runTestExternalCatAPI.
@Trace(dispatcher = true)
private void runTestExternalCatAPI() {
URL myURL = null;
try {
Thread.sleep(1000);
myURL = new URL("http://localhost:8080");
HttpUriRequest request = RequestBuilder.get().setUri(myURL.toURI()).build();
ApiTestHelper.OutboundWrapper outboundWrapper = new ApiTestHelper.OutboundWrapper(request, HeaderType.HTTP);
TracedMethod tracedMethod = NewRelic.getAgent().getTracedMethod();
tracedMethod.addOutboundRequestHeaders(outboundWrapper);
Assert.assertTrue(request.getHeaders("X-NewRelic-ID").length == 0);
ApiTestHelper.DummyRequest incomingRequest = new ApiTestHelper.DummyRequest(HeaderType.HTTP);
ApiTestHelper.DummyResponse response = new ApiTestHelper.DummyResponse(HeaderType.HTTP);
NewRelic.getAgent().getTransaction().setWebRequest(incomingRequest);
NewRelic.getAgent().getTransaction().setWebResponse(response);
NewRelic.getAgent().getTransaction().addOutboundResponseHeaders();
NewRelic.getAgent().getTransaction().markResponseSent();
Assert.assertFalse(response.didSetHeader());
Tracer rootTracer = Transaction.getTransaction().getRootTracer();
Assert.assertNull(rootTracer);
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
use of com.newrelic.api.agent.TracedMethod in project newrelic-java-agent by newrelic.
the class AmazonSNS_Instrumentation method publish.
@Trace
public PublishResult publish(PublishRequest publishRequest) {
TracedMethod tracedMethod = NewRelic.getAgent().getTracedMethod();
ExternalParameters params = SNSInstrumentationHelper.makeMessageProducerParameters(publishRequest);
tracedMethod.reportAsExternal(params);
return Weaver.callOriginal();
}
use of com.newrelic.api.agent.TracedMethod in project newrelic-java-agent by newrelic.
the class NettyDispatcher method upstreamDispatcher.
@Trace(dispatcher = true)
public static void upstreamDispatcher(ChannelHandlerContext_Instrumentation ctx, Object msg) {
try {
ctx.getPipeline().token = AgentBridge.getAgent().getTransaction().getToken();
TracedMethod tracer = AgentBridge.getAgent().getTransaction().getTracedMethod();
if (tracer == null) {
// it happens.
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Unable to dispatch netty tx. No tracer.");
} else {
tracer.setMetricName("NettyUpstreamDispatcher");
AgentBridge.currentApiSource.set(WeavePackageType.INTERNAL);
AgentBridge.getAgent().getTransaction().setTransactionName(TransactionNamePriority.SERVLET_NAME, true, "NettyDispatcher", "NettyDispatcher");
}
Transaction tx = AgentBridge.getAgent().getTransaction(false);
if (tx != null) {
tx.setWebRequest(new RequestWrapper((DefaultHttpRequest) msg));
}
} catch (Throwable t) {
AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
} finally {
AgentBridge.currentApiSource.remove();
}
}
Aggregations