Search in sources :

Example 21 with Transaction

use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.

the class MetricState method getInboundPostamble.

public void getInboundPostamble(HttpURLConnection connection, TracedMethod method) {
    Transaction tx = AgentBridge.getAgent().getTransaction(false);
    if (method.isMetricProducer() && !metricsRecorded && tx != null) {
        this.metricsRecorded = true;
        String uri = URISupport.getURI(connection.getURL());
        InboundWrapper inboundWrapper = new InboundWrapper(connection);
        tx.getCrossProcessState().processInboundResponseHeaders(inboundWrapper, method, connection.getURL().getHost(), uri, true);
    }
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction)

Example 22 with Transaction

use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.

the class HttpMethodBase method execute.

@Trace(leaf = true)
public int execute(HttpState state, HttpConnection conn) throws IOException {
    String host = null;
    String uri = null;
    TracedMethod method = AgentBridge.getAgent().getTracedMethod();
    Transaction tx = AgentBridge.getAgent().getTransaction();
    if (!checkForIgnoredSocketCall(method)) {
        // URI calculation logic migrated from old pointcut to maintain parity
        URI methodURI = getURI();
        String scheme = methodURI.getScheme();
        if (scheme == null) {
            scheme = conn.getProtocol().getScheme();
            host = conn.getHost();
            String path = methodURI.getPath();
            if ("null".equals(path)) {
                path = null;
            }
            uri = URISupport.getURI(scheme, host, conn.getPort(), path);
        } else {
            host = methodURI.getHost();
            uri = URISupport.getURI(methodURI.getScheme(), host, conn.getPort(), methodURI.getPath());
        }
        // Set cross process headers for this outbound request
        method.addOutboundRequestHeaders(new OutboundWrapper(this));
    }
    int responseCode = Weaver.callOriginal();
    if (!checkForIgnoredSocketCall(method) && uri != null) {
        try {
            InboundWrapper inboundHeaders = new InboundWrapper(this);
            java.net.URI netURI = java.net.URI.create(uri);
            method.reportAsExternal(HttpParameters.library(LIBRARY).uri(netURI).procedure("execute").inboundHeaders(inboundHeaders).status(responseCode, this.getStatusText()).build());
        } catch (Throwable e) {
            AgentBridge.getAgent().getLogger().log(Level.FINER, e, "Unable to reportAsExternal for execute()");
        }
    }
    return responseCode;
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) InboundWrapper(com.nr.agent.instrumentation.httpclient31.InboundWrapper) TracedMethod(com.newrelic.agent.bridge.TracedMethod) OutboundWrapper(com.nr.agent.instrumentation.httpclient31.OutboundWrapper) Trace(com.newrelic.api.agent.Trace)

Example 23 with Transaction

use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.

the class StandardHostValve method invoke.

/**
 * This is the entry and exit point for a request in Tomcat. If we see a requestInitialized but no corresponding
 * requestDestroyed then we need to manually finish this transaction ourselves or we will potentially leak an
 * unfinished Transaction and cause extremely long response times to be reported from "requestInitialized()"
 */
public final void invoke(Request request, Response response) throws IOException, ServletException {
    requestDestroyedNeeded.set(false);
    boolean nrAsyncAtStart = request.isAsync();
    try {
        Weaver.callOriginal();
    } finally {
        try {
            // This logic (aside from the requestDestroyedNeeded check) comes directly from Tomcat
            if (requestDestroyedNeeded.get() && !request.isAsync() && (!nrAsyncAtStart || !response.isError())) {
                Transaction transaction = AgentBridge.getAgent().getTransaction(false);
                if (transaction != null) {
                    AgentBridge.getAgent().getLogger().log(Level.FINEST, "Missing required requestDestroyed call. " + "Manually destroying transaction: {0}", transaction);
                    transaction.requestDestroyed();
                }
            }
        } finally {
            // Ensure that we always reset this when we leave this method
            requestDestroyedNeeded.set(false);
        }
    }
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction)

Example 24 with Transaction

use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.

the class HttpResponseBuilder_Instrumentation method build.

@Trace(excludeFromTransactionTrace = true)
public HttpResponse build() {
    MuleHttpConnectorResponse response = new MuleHttpConnectorResponse(headers, responseStatus);
    NewRelic.getAgent().getTracedMethod().addOutboundRequestHeaders(response);
    final Transaction txn = AgentBridge.getAgent().getTransaction(false);
    if (txn != null) {
        txn.setWebResponse(response);
        long contentLength;
        try {
            contentLength = getContentLength(response);
        } catch (Exception e) {
            contentLength = -1L;
        }
        txn.getCrossProcessState().processOutboundResponseHeaders(response, contentLength);
    }
    return Weaver.callOriginal();
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) MuleHttpConnectorResponse(com.nr.agent.instrumentation.mule3.MuleHttpConnectorResponse) Trace(com.newrelic.api.agent.Trace)

Example 25 with Transaction

use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.

the class MuleUtils method reportToAgent.

/**
 * Called inbound when using Http Transport. Verify this is consistent with usages of MuleHttpConnectorRequest in
 * the mule-3.6 and mule-3.7 modules.
 */
public static void reportToAgent(final MuleEvent muleEvent) {
    if (muleEvent == null) {
        NewRelic.getAgent().getLogger().log(Level.FINE, "MuleUtils#reportToAgent muleEvent is null");
        return;
    }
    MuleMessage message = muleEvent.getMessage();
    if (message == null) {
        NewRelic.getAgent().getLogger().log(Level.FINE, "MuleUtils#reportToAgent muleEvent.message is null");
        return;
    }
    final MuleHttpTransportRequest muleRequest = new MuleHttpTransportRequest(message);
    ExternalParameters params;
    try {
        URI uri = new URI(muleRequest.getRequestURI());
        params = HttpParameters.library("MuleHTTP").uri(uri).procedure("writeResponse").inboundHeaders(muleRequest).build();
    } catch (URISyntaxException uriSyntaxException) {
        params = HttpParameters.library("MuleHTTP").uri(UNKNOWN_HOST_URI).procedure("writeResponse").inboundHeaders(muleRequest).build();
    }
    NewRelic.getAgent().getTracedMethod().reportAsExternal(params);
    final Transaction txn = AgentBridge.getAgent().getTransaction(false);
    txn.setWebRequest(muleRequest);
    final String txnName = message.getInboundProperty("http.context.path") + " (" + muleRequest.getMethod() + ")";
    txn.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, false, "Mule/Transport", txnName);
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) MuleMessage(org.mule.api.MuleMessage) ExternalParameters(com.newrelic.api.agent.ExternalParameters) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

Transaction (com.newrelic.agent.bridge.Transaction)40 Trace (com.newrelic.api.agent.Trace)18 TracedMethod (com.newrelic.agent.bridge.TracedMethod)7 AgentBridge (com.newrelic.agent.bridge.AgentBridge)4 WeaveIntoAllMethods (com.newrelic.api.agent.weaver.WeaveIntoAllMethods)4 WeaveWithAnnotation (com.newrelic.api.agent.weaver.WeaveWithAnnotation)4 URI (java.net.URI)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Segment (com.newrelic.api.agent.Segment)3 Label (org.objectweb.asm.Label)3 Method (org.objectweb.asm.commons.Method)3 TracedMethod (com.newrelic.api.agent.TracedMethod)2 MuleHttpConnectorRequest (com.nr.agent.instrumentation.mule3.MuleHttpConnectorRequest)2 OutboundWrapper (com.nr.instrumentation.jersey.client.OutboundWrapper)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 GET (javax.ws.rs.GET)2 HEAD (javax.ws.rs.HEAD)2 PUT (javax.ws.rs.PUT)2 Test (org.junit.Test)2