Search in sources :

Example 1 with HttpParameters

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;
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) Matcher(java.util.regex.Matcher)

Example 2 with HttpParameters

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"));
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Example 3 with HttpParameters

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());
    }
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 4 with HttpParameters

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());
    }
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 5 with HttpParameters

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());
    }
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

HttpParameters (com.newrelic.api.agent.HttpParameters)10 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)5 SpanEvent (com.newrelic.agent.model.SpanEvent)2 Test (org.junit.Test)2 DatastoreParameters (com.newrelic.api.agent.DatastoreParameters)1 InboundHeaders (com.newrelic.api.agent.InboundHeaders)1 MessageConsumeParameters (com.newrelic.api.agent.MessageConsumeParameters)1 MessageProduceParameters (com.newrelic.api.agent.MessageProduceParameters)1 SlowQueryDatastoreParameters (com.newrelic.api.agent.SlowQueryDatastoreParameters)1 Matcher (java.util.regex.Matcher)1