use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.
the class SegmentTest method testSyncNamedTracedActivity.
/**
* tracer(dispatcher) start
* --tracedActivity start
* tracer finish
* --tracedActivity finish
* <p>
* Transaction must have two txas due to the tracedActivity being finished after its parent tracer is finished.
* Segment tracer must correctly link to root tracer.
*/
@Test
public void testSyncNamedTracedActivity() throws InterruptedException {
Tracer root = makeTransaction();
Assert.assertNotNull(root);
Assert.assertNotNull(root.getTransactionActivity().getTransaction());
Thread.sleep(1);
final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Segment");
Assert.assertNotNull(segment);
root.finish(Opcodes.ARETURN, null);
Thread.sleep(1);
final AtomicReference<TracedMethod> tracedMethod = new AtomicReference<>();
tracedMethod.set(segment.getTracedMethod());
segment.end();
assertTrue(root.getTransactionActivity().getTransaction().isFinished());
assertTrue(tracedMethod.get() instanceof Tracer);
assertEquals("Segment name was not properly set", "activity", ((Tracer) tracedMethod.get()).getTransactionActivity().getAsyncContext());
assertEquals(2, root.getTransactionActivity().getTransaction().getCountOfRunningAndFinishedTransactionActivities());
assertEquals(2, getNumTracers(root.getTransactionActivity().getTransaction()));
Assert.assertSame("Segment must be child of root tracer", root, tracedMethod.get().getParentTracedMethod());
}
use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.
the class FlyweightTraceMethodVisitorTest method verifyTracedMethodStitching.
@Test
public void verifyTracedMethodStitching() {
// these methods are overridden in the bridge with a different signature. ignore them
Set<Method> excludes = ImmutableSet.of(new Method("getParentTracedMethod", "()Lcom/newrelic/api/agent/TracedMethod;"));
TraceDetails trace = TraceDetailsBuilder.newBuilder().build();
FlyweightTraceMethodVisitor mv = new FlyweightTraceMethodVisitor("", null, 0, "go", "()V", trace, null);
Map<Method, ?> map = mv.tracedMethodMethodHandlers;
java.lang.reflect.Method[] methods = TracedMethod.class.getMethods();
for (java.lang.reflect.Method m : methods) {
Method method = Method.getMethod(m);
if (!map.containsKey(method) && !excludes.contains(method)) {
Assert.fail("There is no method handler for TracedMethod." + method);
}
}
}
use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.
the class MetricState method nonNetworkPreamble.
public void nonNetworkPreamble(boolean isConnected, HttpURLConnection connection, String operation) {
TracedMethod method = AgentBridge.getAgent().getTracedMethod();
Transaction tx = AgentBridge.getAgent().getTransaction(false);
if (!isConnected && method.isMetricProducer() && tx != null) {
// This method doesn't have any network I/O so we are explicitly not recording external rollup metrics
makeMetric(connection, method, operation);
tx.getCrossProcessState().processOutboundRequestHeaders(new OutboundWrapper(connection), method);
}
}
use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.
the class HttpURLConnection method getInputStream.
@Trace(leaf = true)
public synchronized InputStream getInputStream() throws IOException {
MetricState metricState = lazyGetMetricState();
TracedMethod method = AgentBridge.getAgent().getTracedMethod();
metricState.getInputStreamPreamble(connected, this, method);
InputStream inputStream;
try {
// This does a network request (if getResponseCode() wasn't called first)
inputStream = Weaver.callOriginal();
} catch (Exception e) {
// This is the default legacy behavior of the AbstractExternalComponentTracer
if (e instanceof UnknownHostException) {
method.setMetricName("External", "UnknownHost", "HttpURLConnection");
}
throw e;
}
metricState.getInboundPostamble(this, method);
return inputStream;
}
use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.
the class HttpMethodBase method getResponseBody.
@Trace(leaf = true)
public byte[] getResponseBody() throws IOException {
TracedMethod method = AgentBridge.getAgent().getTracedMethod();
if (!checkForIgnoredSocketCall(method)) {
try {
String host = getHostname();
URI methodURI = getURI();
String uri = URISupport.getURI(methodURI.getScheme(), methodURI.getHost(), methodURI.getPort(), methodURI.getPath());
// This method doesn't have any network I/O so we are explicitly not recording external rollup metrics
ExternalMetrics.makeExternalComponentMetric(method, host, LIBRARY, false, uri, "getResponseBody");
} catch (Throwable e) {
AgentBridge.getAgent().getLogger().log(Level.FINER, e, "Unable to record external metrics for getResponseBody()");
}
}
return Weaver.callOriginal();
}
Aggregations