use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class ApiTest method runTestExternalCatAPI.
@Trace(dispatcher = true)
private void runTestExternalCatAPI() {
URL myURL = null;
try {
Thread.sleep(1000);
myURL = new URL("http://localhost:8088");
HttpUriRequest request = RequestBuilder.get().setUri(myURL.toURI()).build();
ApiTestHelper.OutboundWrapper outboundWrapper = new ApiTestHelper.OutboundWrapper(request, HeaderType.HTTP);
com.newrelic.api.agent.TracedMethod tracedMethod = NewRelic.getAgent().getTracedMethod();
tracedMethod.addOutboundRequestHeaders(outboundWrapper);
CloseableHttpClient connection = HttpClientBuilder.create().build();
CloseableHttpResponse response = connection.execute(request);
ApiTestHelper.InboundWrapper inboundHeaders = new ApiTestHelper.InboundWrapper(response, HeaderType.HTTP);
ExternalParameters params = HttpParameters.library("HttpClient").uri(myURL.toURI()).procedure("execute").inboundHeaders(inboundHeaders).build();
NewRelic.getAgent().getTransaction().getTracedMethod().reportAsExternal(params);
Tracer rootTracer = Transaction.getTransaction().getRootTracer();
rootTracer.finish(0, null);
Map<String, Object> attributes = rootTracer.getAgentAttributes();
Assert.assertNotNull(attributes.get("transaction_guid"));
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class ApiTest method runTestDatastoreAPI.
@Trace(dispatcher = true)
private void runTestDatastoreAPI() {
String vendor = "MongoDB";
String collection = "Users";
String operation = "SELECT";
String host = "awesome-host";
Integer port = 27017;
ExternalParameters params = DatastoreParameters.product(vendor).collection(collection).operation(operation).instance(host, port).build();
NewRelic.getAgent().getTracedMethod().reportAsExternal(params);
}
use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class AgentPreprocessorsTest method testRewriteSlowQueryWithHighSecurityAndNonPresentListToCollect.
@Test
public void testRewriteSlowQueryWithHighSecurityAndNonPresentListToCollect() throws Exception {
final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass4";
Map<String, Object> confProps = new HashMap<>();
confProps.put("high_security", true);
Map<String, Object> ttConfig = new HashMap<>();
ttConfig.put("collect_slow_queries_from", "some-other-module");
confProps.put("transaction_tracer", ttConfig);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(confProps);
byte[] bytes = getClassBytesFromClassLoaderResource(classname, classloader);
Assert.assertNotNull(bytes);
ClassNode source = WeaveUtils.convertToClassNode(bytes);
ClassNode result = new ClassNode(WeaveUtils.ASM_API_LEVEL);
ClassVisitor cv = new CheckClassAdapter(result);
AgentPreprocessors preprocessors = new AgentPreprocessors(agentConfig, null);
preprocessors.setInstrumentationTitle(INSTRUMENTATION_TITLE);
cv = preprocessors.rewriteSlowQueryIfRequired(cv);
source.accept(cv);
Class<?> clazz = addToClassloader(result, classloader);
Assert.assertNotNull(clazz);
ExternalParametersFactoryTestClass4 testClass = (ExternalParametersFactoryTestClass4) clazz.newInstance();
assertNotNull(testClass);
ExternalParameters regularDatastore = testClass.createRegularDatastore();
assertNotNull(regularDatastore);
assertTrue(regularDatastore instanceof DatastoreParameters);
ExternalParameters slowQueryDatastore = testClass.createSlowQueryDatastore();
assertNotNull(slowQueryDatastore);
// AgentPreprocessors should re-write the call to return a regular DatastoreParameters object
assertTrue(!(slowQueryDatastore instanceof SlowQueryDatastoreParameters));
ExternalParameters slowQueryWithInputDatastore = testClass.createSlowQueryWithInputDatastore();
assertNotNull(slowQueryWithInputDatastore);
// AgentPreprocessors should re-write the call to return a regular DatastoreParameters object
assertTrue(!(slowQueryWithInputDatastore instanceof SlowQueryWithInputDatastoreParameters));
}
use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class AgentPreprocessorsTest method testRewriteSlowQueryWithHighSecurityAndListToCollect.
@Test
public void testRewriteSlowQueryWithHighSecurityAndListToCollect() throws Exception {
final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass3";
Map<String, Object> confProps = new HashMap<>();
confProps.put("high_security", true);
Map<String, Object> ttConfig = new HashMap<>();
ttConfig.put("collect_slow_queries_from", INSTRUMENTATION_TITLE + ",some-other-module");
confProps.put("transaction_tracer", ttConfig);
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(confProps);
byte[] bytes = getClassBytesFromClassLoaderResource(classname, classloader);
Assert.assertNotNull(bytes);
ClassNode source = WeaveUtils.convertToClassNode(bytes);
ClassNode result = new ClassNode(WeaveUtils.ASM_API_LEVEL);
ClassVisitor cv = new CheckClassAdapter(result);
AgentPreprocessors preprocessors = new AgentPreprocessors(agentConfig, null);
preprocessors.setInstrumentationTitle(INSTRUMENTATION_TITLE);
cv = preprocessors.rewriteSlowQueryIfRequired(cv);
source.accept(cv);
Class<?> clazz = addToClassloader(result, classloader);
Assert.assertNotNull(clazz);
ExternalParametersFactoryTestClass3 testClass = (ExternalParametersFactoryTestClass3) clazz.newInstance();
assertNotNull(testClass);
ExternalParameters regularDatastore = testClass.createRegularDatastore();
assertNotNull(regularDatastore);
assertTrue(regularDatastore instanceof DatastoreParameters);
ExternalParameters slowQueryDatastore = testClass.createSlowQueryDatastore();
assertNotNull(slowQueryDatastore);
assertTrue(slowQueryDatastore instanceof SlowQueryDatastoreParameters);
ExternalParameters slowQueryWithInputDatastore = testClass.createSlowQueryWithInputDatastore();
assertNotNull(slowQueryWithInputDatastore);
assertTrue(slowQueryWithInputDatastore instanceof SlowQueryWithInputDatastoreParameters);
}
use of com.newrelic.api.agent.ExternalParameters in project newrelic-java-agent by newrelic.
the class AgentPreprocessorsTest method testRewriteSlowQueryBuilderNoHighSecurity.
@Test
public void testRewriteSlowQueryBuilderNoHighSecurity() throws Exception {
final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass5";
Map<String, Object> confProps = new HashMap<>();
AgentConfig agentConfig = AgentConfigImpl.createAgentConfig(confProps);
byte[] bytes = getClassBytesFromClassLoaderResource(classname, classloader);
Assert.assertNotNull(bytes);
ClassNode source = WeaveUtils.convertToClassNode(bytes);
ClassNode result = new ClassNode(WeaveUtils.ASM_API_LEVEL);
ClassVisitor cv = new CheckClassAdapter(result);
AgentPreprocessors preprocessors = new AgentPreprocessors(agentConfig, null);
preprocessors.setInstrumentationTitle(INSTRUMENTATION_TITLE);
cv = preprocessors.rewriteSlowQueryIfRequired(cv);
source.accept(cv);
Class<?> clazz = addToClassloader(result, classloader);
Assert.assertNotNull(clazz);
ExternalParametersFactoryTestClass5 testClass = (ExternalParametersFactoryTestClass5) clazz.newInstance();
assertNotNull(testClass);
ExternalParameters regularDatastore = testClass.createRegularDatastore();
assertNotNull(regularDatastore);
assertTrue(regularDatastore instanceof DatastoreParameters);
ExternalParameters slowQueryDatastore = testClass.createSlowQueryDatastore();
assertNotNull(slowQueryDatastore);
assertTrue(slowQueryDatastore instanceof SlowQueryDatastoreParameters);
ExternalParameters slowQueryWithInputDatastore = testClass.createSlowQueryWithInputDatastore();
assertNotNull(slowQueryWithInputDatastore);
assertTrue(slowQueryWithInputDatastore instanceof SlowQueryWithInputDatastoreParameters);
}
Aggregations