Search in sources :

Example 6 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)

Example 7 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(Segment segment, 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();
        segment.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 8 with HttpParameters

use of com.newrelic.api.agent.HttpParameters in project newrelic-java-agent by newrelic.

the class SpanEventFactoryTest method doesNotSetHttpAgentAttributesWhenFiltering.

@Test
public void doesNotSetHttpAgentAttributesWhenFiltering() {
    HttpParameters mockParameters = mock(HttpParameters.class);
    when(mockParameters.getLibrary()).thenReturn("library");
    when(mockParameters.getProcedure()).thenReturn("procedure");
    SpanEventFactory target = new SpanEventFactory("blerb", new PassNothingAttributeFilter(), DEFAULT_SYSTEM_TIMESTAMP_SUPPLIER);
    SpanEvent spanEvent = target.setExternalParameterAttributes(mockParameters).build();
    assertEquals("library", spanEvent.getIntrinsics().get("component"));
    assertNull(spanEvent.getAgentAttributes().get("http.method"));
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Example 9 with HttpParameters

use of com.newrelic.api.agent.HttpParameters in project newrelic-java-agent by newrelic.

the class SpanEventFactory method setExternalParameterAttributes.

public SpanEventFactory setExternalParameterAttributes(ExternalParameters parameters) {
    if (parameters instanceof HttpParameters) {
        HttpParameters httpParameters = (HttpParameters) parameters;
        setCategory(SpanCategory.http);
        setUri(httpParameters.getUri());
        setHttpMethod(httpParameters.getProcedure());
        setHttpStatusCode(httpParameters.getStatusCode());
        setHttpStatusText(httpParameters.getStatusText());
        setHttpComponent((httpParameters).getLibrary());
        setKindFromUserAttributes();
    } else if (parameters instanceof DatastoreParameters) {
        DatastoreParameters datastoreParameters = (DatastoreParameters) parameters;
        setCategory(SpanCategory.datastore);
        setDatastoreComponent(datastoreParameters.getProduct());
        setDatabaseName(datastoreParameters.getDatabaseName());
        setDatabaseCollection(datastoreParameters.getCollection());
        setHostName(datastoreParameters.getHost());
        setKindFromUserAttributes();
        if (datastoreParameters instanceof SlowQueryDatastoreParameters) {
            SlowQueryDatastoreParameters<?> queryDatastoreParameters = (SlowQueryDatastoreParameters<?>) datastoreParameters;
            setDatabaseStatement(determineObfuscationLevel(queryDatastoreParameters));
        }
        if (datastoreParameters.getPort() != null) {
            setAddress(datastoreParameters.getHost(), String.valueOf(datastoreParameters.getPort()));
        } else {
            setAddress(datastoreParameters.getHost(), datastoreParameters.getPathOrId());
        }
    } else {
        setCategory(SpanCategory.generic);
    }
    return this;
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) SlowQueryDatastoreParameters(com.newrelic.api.agent.SlowQueryDatastoreParameters) DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) SlowQueryDatastoreParameters(com.newrelic.api.agent.SlowQueryDatastoreParameters)

Example 10 with HttpParameters

use of com.newrelic.api.agent.HttpParameters in project newrelic-java-agent by newrelic.

the class DefaultTracer method reportAsExternal.

@Override
public void reportAsExternal(ExternalParameters externalParameters) {
    if (Agent.LOG.isFineEnabled()) {
        Agent.LOG.log(Level.FINE, "Setting externalParameters to: " + externalParameters);
    }
    MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_REPORT_AS_EXTERNAL);
    this.externalParameters = externalParameters;
    if (this.externalParameters instanceof HttpParameters) {
        // URI validity check and logging
        HttpParameters httpParameters = (HttpParameters) this.externalParameters;
        URI uri = httpParameters.getUri();
        if (uri == null || uri.getScheme() == null || uri.getHost() == null || uri.getPort() == -1) {
            Agent.LOG.log(Level.FINE, "URI parameter passed to HttpParameters should include a valid scheme, host, and port.");
        }
        InboundHeaders headers = httpParameters.getInboundResponseHeaders();
        if (null != headers) {
            readInboundResponseHeaders(headers);
        }
    } else if (this.externalParameters instanceof MessageProduceParameters) {
        catForMessaging(((MessageProduceParameters) this.externalParameters));
    } else if (this.externalParameters instanceof MessageConsumeParameters) {
        catForMessaging(((MessageConsumeParameters) this.externalParameters));
    }
}
Also used : HttpParameters(com.newrelic.api.agent.HttpParameters) MessageConsumeParameters(com.newrelic.api.agent.MessageConsumeParameters) InboundHeaders(com.newrelic.api.agent.InboundHeaders) MessageProduceParameters(com.newrelic.api.agent.MessageProduceParameters) 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