Search in sources :

Example 31 with Transaction

use of com.newrelic.agent.bridge.Transaction 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();
    }
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) RequestWrapper(com.agent.instrumentation.netty38.RequestWrapper) TracedMethod(com.newrelic.api.agent.TracedMethod) Trace(com.newrelic.api.agent.Trace)

Example 32 with Transaction

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

the class CallbackRunnable_Instrumentation method run.

@Trace(excludeFromTransactionTrace = true)
public void run() {
    Segment segment = null;
    WrappedTry wrapped = null;
    boolean remove = false;
    if (value instanceof WrappedTry) {
        wrapped = (WrappedTry) value;
        // If we are here and there is no activeToken in progress we are the first one so we set this boolean in
        // order to correctly remove the "activeToken" from the thread local after the original run() method executes
        remove = AgentBridge.activeToken.get() == null;
        AgentBridge.activeToken.set(wrapped.tokenAndRefCount);
        if (scalaFuturesAsSegments && remove) {
            Transaction tx = AgentBridge.getAgent().getTransaction(false);
            if (tx != null) {
                segment = tx.startSegment("Scala", "Callback");
                segment.setMetricName("Scala", "Callback", ScalaUtils.nameScalaFunction(onComplete.getClass().getName()));
            }
        }
        value = wrapped.original;
    }
    try {
        Weaver.callOriginal();
    } finally {
        if (wrapped != null) {
            if (segment != null) {
                segment.end();
            }
            if (remove) {
                AgentBridge.activeToken.remove();
            }
            if (wrapped.tokenAndRefCount.refCount.decrementAndGet() == 0) {
                wrapped.tokenAndRefCount.token.expire();
                wrapped.tokenAndRefCount.token = null;
            }
        }
    }
}
Also used : WrappedTry(com.nr.agent.instrumentation.scala.WrappedTry) Transaction(com.newrelic.agent.bridge.Transaction) Segment(com.newrelic.api.agent.Segment) Trace(com.newrelic.api.agent.Trace)

Example 33 with Transaction

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

the class Transformation_Instrumentation method submitWithValue.

/**
 * Override the submitWithValue so we can replace it with our wrapped version.
 * It plays similar role to the 2.12 setter for "value" on the old CallbackRunnable
 */
public final Promise.Transformation submitWithValue(final Try<T> resolved) {
    AgentBridge.TokenAndRefCount tokenAndRefCount = AgentBridge.activeToken.get();
    if (tokenAndRefCount == null) {
        Transaction tx = AgentBridge.getAgent().getTransaction(false);
        if (tx != null) {
            this.tokenAndRefCount = new AgentBridge.TokenAndRefCount(tx.getToken(), AgentBridge.getAgent().getTracedMethod(), new AtomicInteger(1));
        }
    } else {
        this.tokenAndRefCount = tokenAndRefCount;
        this.tokenAndRefCount.refCount.incrementAndGet();
    }
    return Weaver.callOriginal();
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AgentBridge(com.newrelic.agent.bridge.AgentBridge)

Example 34 with Transaction

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

the class SprayToResponseMarshallingContext method marshalTo.

@Trace(async = true)
public void marshalTo(HttpResponse httpResponse) {
    Transaction transaction = AgentBridge.getAgent().getTransaction(false);
    if (transaction != null) {
        // First, convert to a java collection so we can add our CAT headers
        List<HttpHeader> modifiableHeaders = new ArrayList<>(JavaConversions.asJavaCollection(httpResponse.headers()));
        // Run through CAT related code to set headers
        transaction.setWebResponse(new ResponseWrapper(httpResponse.status(), modifiableHeaders));
        OutboundWrapper outboundWrapper = new OutboundWrapper(modifiableHeaders);
        transaction.getCrossProcessState().processOutboundResponseHeaders(outboundWrapper, getContentLength(outboundWrapper));
        transaction.markFirstByteOfResponse();
        httpResponse = httpResponse.withHeaders(JavaConversions.asScalaBuffer(modifiableHeaders).toList());
    }
    Weaver.callOriginal();
}
Also used : HttpHeader(spray.http.HttpHeader) Transaction(com.newrelic.agent.bridge.Transaction) ArrayList(java.util.ArrayList) ResponseWrapper(com.agent.instrumentation.spray.ResponseWrapper) OutboundWrapper(com.agent.instrumentation.spray.OutboundWrapper) Trace(com.newrelic.api.agent.Trace)

Example 35 with Transaction

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

the class SearchHandler_Instrumentation method handleRequestBody.

@Trace
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) {
    Weaver.callOriginal();
    Transaction tx = AgentBridge.getAgent().getTransaction(false);
    if (tx != null && tx.isStarted()) {
        Map<String, String> result = new HashMap<>();
        // I can't find a functional difference between these two from the original SolrRequestHandlerPointCut
        String solrQueryRequest = req.getParams().get("q");
        if (solrQueryRequest != null) {
            result.put(SolrUtil.SOLR_RAW_QUERY_STRING, solrQueryRequest);
            result.put(SolrUtil.SOLR_QUERY_STRING, solrQueryRequest);
        }
        // haven't found a replacement for this in Solr 4.0.0 yet
        Query query = SolrUtil.parseQuery(solrQueryRequest, null, req.getSchema());
        if (query != null && query.toString() != null) {
            String luceneQuery = query.toString();
            result.put(SolrUtil.SOLR_LUCENE_QUERY, luceneQuery);
            result.put(SolrUtil.SOLR_LUCENE_QUERY_STRING, luceneQuery);
        }
        if (rsp.getException() != null && rsp.getException().toString() != null) {
            result.put(SolrUtil.SOLR_DEBUG_INFO_ERROR, rsp.getException().toString());
        }
        tx.getAgentAttributes().putAll(result);
    }
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) Query(org.apache.lucene.search.Query) HashMap(java.util.HashMap) Trace(com.newrelic.api.agent.Trace)

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