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();
}
}
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;
}
}
}
}
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();
}
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();
}
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);
}
}
Aggregations