use of com.newrelic.api.agent.HttpParameters in project newrelic-java-agent by newrelic.
the class ExternalRequestImpl method checkAndMakeExternal.
public static ExternalRequestImpl checkAndMakeExternal(Tracer transactionSegment) {
String transactionSegmentName = transactionSegment.getTransactionSegmentName();
String metricName = transactionSegment.getMetricName();
Matcher segMatcher = EXTERNAL_SEGMENT.matcher(transactionSegmentName);
Matcher metricMatcher = EXTERNAL_METRIC.matcher(metricName);
Integer statusCode = null;
String statusText = null;
if (transactionSegment.getExternalParameters() instanceof HttpParameters) {
HttpParameters httpParams = (HttpParameters) transactionSegment.getExternalParameters();
statusCode = httpParams.getStatusCode();
statusText = httpParams.getStatusText();
}
if (segMatcher.matches() && (segMatcher.groupCount() == 2 || segMatcher.groupCount() == 4) && metricMatcher.matches() && metricMatcher.groupCount() == 2) {
String host = segMatcher.group(1);
String lib = segMatcher.group(2);
String op = null;
if (segMatcher.groupCount() == 4) {
op = segMatcher.group(4);
}
return new ExternalRequestImpl(metricName, transactionSegmentName, host, lib, op, statusCode, statusText, (String) transactionSegment.getAgentAttribute("transaction_guid"));
} else {
segMatcher = EXTERNAL_TX_METRIC.matcher(transactionSegmentName);
metricMatcher = EXTERNAL_TX_SEGMENT.matcher(metricName);
if (segMatcher.matches() && segMatcher.groupCount() == 2 && metricMatcher.matches() && metricMatcher.groupCount() == 2) {
String host = segMatcher.group(1);
String lib = null;
String op = null;
return new ExternalRequestImpl(metricName, transactionSegmentName, host, lib, op, statusCode, statusText, (String) transactionSegment.getAgentAttribute("transaction_guid"));
}
}
return null;
}
use of com.newrelic.api.agent.HttpParameters in project newrelic-java-agent by newrelic.
the class SpanEventFactoryTest method shouldSetHttpParameters.
@Test
public void shouldSetHttpParameters() {
HttpParameters mockParameters = mock(HttpParameters.class);
when(mockParameters.getLibrary()).thenReturn("library");
when(mockParameters.getProcedure()).thenReturn("procedure");
SpanEvent target = spanEventFactory.setExternalParameterAttributes(mockParameters).build();
assertEquals("library", target.getIntrinsics().get("component"));
assertEquals("procedure", target.getAgentAttributes().get("http.method"));
}
use of com.newrelic.api.agent.HttpParameters in project newrelic-java-agent by newrelic.
the class S3MetricUtil method reportExternalMetrics.
public static void reportExternalMetrics(TracedMethod tracedMethod, String uri, String operationName) {
try {
HttpParameters httpParameters = HttpParameters.library(SERVICE).uri(new URI(uri)).procedure(operationName).noInboundHeaders().build();
tracedMethod.reportAsExternal(httpParameters);
} catch (URISyntaxException e) {
AgentBridge.instrumentation.noticeInstrumentationError(e, Weaver.getImplementationTitle());
}
}
use of com.newrelic.api.agent.HttpParameters in project newrelic-java-agent by newrelic.
the class S3MetricUtil method reportExternalMetrics.
public static void reportExternalMetrics(TracedMethod tracedMethod, String uri, S3Response s3Response, String operationName) {
try {
Integer statusCode = null;
String statusText = null;
if (s3Response != null) {
statusCode = s3Response.sdkHttpResponse().statusCode();
statusText = s3Response.sdkHttpResponse().statusText().orElse(null);
}
HttpParameters httpParameters = HttpParameters.library(SERVICE).uri(new URI(uri)).procedure(operationName).noInboundHeaders().status(statusCode, statusText).build();
tracedMethod.reportAsExternal(httpParameters);
} catch (URISyntaxException e) {
AgentBridge.instrumentation.noticeInstrumentationError(e, Weaver.getImplementationTitle());
}
}
use of com.newrelic.api.agent.HttpParameters in project newrelic-java-agent by newrelic.
the class S3MetricUtil method reportExternalMetrics.
public static void reportExternalMetrics(TracedMethod tracedMethod, String uri, Integer statusCode, String operationName) {
try {
HttpParameters httpParameters = HttpParameters.library(SERVICE).uri(new URI(uri)).procedure(operationName).noInboundHeaders().status(statusCode, null).build();
tracedMethod.reportAsExternal(httpParameters);
} catch (URISyntaxException e) {
AgentBridge.instrumentation.noticeInstrumentationError(e, Weaver.getImplementationTitle());
}
}
Aggregations