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