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