use of com.newrelic.api.agent.SlowQueryDatastoreParameters in project newrelic-java-agent by newrelic.
the class AgentPreprocessorsTest method testRewriteSlowQueryBuilderWithHighSecurity.
@Test
public void testRewriteSlowQueryBuilderWithHighSecurity() throws Exception {
final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass6";
Map<String, Object> confProps = new HashMap<>();
confProps.put("high_security", true);
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);
ExternalParametersFactoryTestClass6 testClass = (ExternalParametersFactoryTestClass6) 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.SlowQueryDatastoreParameters in project newrelic-java-agent by newrelic.
the class AgentPreprocessorsTest method testRewriteSlowQueryWithHighSecurity.
@Test
public void testRewriteSlowQueryWithHighSecurity() throws Exception {
final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass2";
Map<String, Object> confProps = new HashMap<>();
confProps.put("high_security", true);
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);
ExternalParametersFactoryTestClass2 testClass = (ExternalParametersFactoryTestClass2) 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.SlowQueryDatastoreParameters in project newrelic-java-agent by newrelic.
the class AgentPreprocessorsTest method testRewriteSlowQueryBuilderWithHighSecurityAndNonPresentListToCollect.
@Test
public void testRewriteSlowQueryBuilderWithHighSecurityAndNonPresentListToCollect() throws Exception {
final ClassLoader classloader = Thread.currentThread().getContextClassLoader();
final String classname = "com.newrelic.agent.instrumentation.weaver.preprocessors.AgentPreprocessorsTest$ExternalParametersFactoryTestClass8";
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);
ExternalParametersFactoryTestClass8 testClass = (ExternalParametersFactoryTestClass8) 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.SlowQueryDatastoreParameters 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;
}
Aggregations