use of com.newrelic.api.agent.NewRelicApiImplementation in project newrelic-java-agent by newrelic.
the class AgentAttributeSenderTest method testErrorAttributesTypes.
@Test
public void testErrorAttributesTypes() {
try {
Map<String, Object> settings = new HashMap<>();
settings.put("app_name", APP_NAME);
manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
Transaction t = Transaction.getTransaction();
NewRelicApiImplementation impl = new NewRelicApiImplementation();
Map<String, Object> attributes = new HashMap<>();
attributes.put("MyNumber", 54);
attributes.put("MyAtomicInteger", new AtomicInteger(54));
attributes.put("MyAtomicLong", new AtomicLong(54));
attributes.put("MyAtomicBool", new AtomicBoolean(true));
// Invalid attribute values
attributes.put("MyBigDecimal", BigDecimal.valueOf(10.000000));
attributes.put("MyBigInteger", BigInteger.valueOf(10000000L));
attributes.put("MyNaN", Double.NaN);
attributes.put("MyPosInf", Double.POSITIVE_INFINITY);
attributes.put("MyNegInf", Double.NEGATIVE_INFINITY);
Exception exception = new Exception("~~ oops ~~");
impl.noticeError(exception, attributes);
// no tx - no atts
Set<String> expected = new HashSet<>();
verifyOutput(t.getUserAttributes(), expected);
} finally {
Transaction.clearTransaction();
}
}
use of com.newrelic.api.agent.NewRelicApiImplementation in project newrelic-java-agent by newrelic.
the class AgentAttributeSenderTest method shouldTruncateLongAttributeValues.
@Test
public void shouldTruncateLongAttributeValues() {
try {
Map<String, Object> settings = new HashMap<>();
settings.put("app_name", APP_NAME);
manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
manager.setAttributesService(new AttributesService());
Transaction t = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
t.getTransactionActivity().tracerStarted(tracer);
NewRelicApiImplementation impl = new NewRelicApiImplementation();
impl.addCustomParameter(makeLongString("ignored-key-too-long"), "vv");
String valueVeryLong = makeLongString("v2");
impl.addCustomParameter("truncated-single-value", valueVeryLong);
Map<String, Object> customParamMap = new HashMap<>();
customParamMap.put(makeLongString("ignored-key-too-long-also"), "vx");
customParamMap.put("truncated-map-value", makeLongString("v4"));
impl.addCustomParameters(customParamMap);
Set<String> expected = Sets.newHashSet("truncated-single-value", "truncated-map-value");
Map<String, Object> attribs = t.getUserAttributes();
Assert.assertEquals(expected, attribs.keySet());
Assert.assertEquals(255, attribs.get("truncated-single-value").toString().length());
Assert.assertNotEquals(255, valueVeryLong.length());
Assert.assertEquals(255, attribs.get("truncated-map-value").toString().length());
Assert.assertNotEquals(255, customParamMap.get("truncated-map-value"));
} finally {
Transaction.clearTransaction();
}
}
use of com.newrelic.api.agent.NewRelicApiImplementation in project newrelic-java-agent by newrelic.
the class AgentAttributeSenderTest method testCustomAttributesOutsideTransaction.
@Test
public void testCustomAttributesOutsideTransaction() {
try {
Map<String, Object> settings = new HashMap<>();
settings.put("app_name", APP_NAME);
manager.setConfigService(new ConfigServiceFactory().createConfigServiceUsingSettings(settings));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
Transaction t = Transaction.getTransaction();
NewRelicApiImplementation impl = new NewRelicApiImplementation();
impl.addCustomParameter("abc.thread", "1");
impl.addCustomParameter("request.many", "1");
impl.addCustomParameter("message.many", "1");
Map<String, Object> customParamMap = new HashMap<>();
customParamMap.put("key1", "val1");
customParamMap.put("key2", 2);
customParamMap.put("key3", new HashMap<>());
customParamMap.put("key4", true);
customParamMap.put("key5", null);
impl.addCustomParameters(customParamMap);
// no tx - no atts
Set<String> expected = new HashSet<>();
verifyOutput(t.getUserAttributes(), expected);
} finally {
Transaction.clearTransaction();
}
}
use of com.newrelic.api.agent.NewRelicApiImplementation in project newrelic-java-agent by newrelic.
the class HighSecurityAttributesTest method testHighSecurityDefaultsThroughAPI.
@Test
public void testHighSecurityDefaultsThroughAPI() {
Map<String, Object> settings = new HashMap<>();
settings.put("app_name", APP_NAME);
enableBrowser(settings);
manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
AttributesService service = new AttributesService();
manager.setAttributesService(service);
try {
Transaction t = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
t.getTransactionActivity().tracerStarted(tracer);
NewRelicApiImplementation impl = new NewRelicApiImplementation();
impl.addCustomParameter("abc.thread", "1");
impl.addCustomParameter("request.many", "1");
impl.addCustomParameter("message.many", "1");
impl.addCustomParameter("request.parameters.foo", "1");
impl.addCustomParameter("request.parameters.bar", "1");
impl.addCustomParameter("message.parameters.foo", "1");
impl.addCustomParameter("message.parameters.bar", "1");
// request and message parameters are off by default
Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many");
verifyOutput(service.filterErrorEventAttributes(APP_NAME, t.getUserAttributes()), expected);
verifyOutput(service.filterTransactionEventAttributes(APP_NAME, t.getUserAttributes()), expected);
verifyOutput(service.filterTransactionTraceAttributes(APP_NAME, t.getUserAttributes()), expected);
verifyOutput(service.filterBrowserAttributes(APP_NAME, t.getUserAttributes()), expected);
verifyOutput(service.filterSpanEventAttributes(APP_NAME, t.getUserAttributes()), expected);
verifyOutput(service.filterTransactionSegmentAttributes(APP_NAME, t.getUserAttributes()), expected);
} finally {
Transaction.clearTransaction();
}
}
use of com.newrelic.api.agent.NewRelicApiImplementation in project newrelic-java-agent by newrelic.
the class HighSecurityAttributesTest method testHighSecurityOffWithOtherDefaultsThroughNoticeErrorAPIMessage.
@Test
public void testHighSecurityOffWithOtherDefaultsThroughNoticeErrorAPIMessage() {
try {
Map<String, Object> settings = new HashMap<>();
settings.put("app_name", APP_NAME);
settings.put("high_security", Boolean.FALSE);
enableBrowser(settings);
manager.setConfigService(ConfigServiceFactory.createConfigServiceUsingSettings(settings));
manager.setTransactionService(new TransactionService());
manager.setTransactionTraceService(new TransactionTraceService());
AttributesService service = new AttributesService();
manager.setAttributesService(service);
RPMServiceManager mockRPMServiceManager = manager.getRPMServiceManager();
RPMService mockRPMService = mock(RPMService.class);
ErrorService errorService = new ErrorServiceImpl(APP_NAME);
when(mockRPMServiceManager.getRPMService()).thenReturn(mockRPMService);
when(mockRPMService.getErrorService()).thenReturn(errorService);
Transaction t = Transaction.getTransaction();
BasicRequestRootTracer tracer = createDispatcherTracer();
t.getTransactionActivity().tracerStarted(tracer);
NewRelicApiImplementation impl = new NewRelicApiImplementation();
Map<String, String> atts = new HashMap<>();
atts.put("abc.thread", "1");
atts.put("request.many", "1");
atts.put("message.many", "1");
atts.put("request.parameters.foo", "1");
atts.put("request.parameters.bar", "1");
atts.put("message.parameters.foo", "1");
atts.put("message.parameters.bar", "1");
impl.noticeError("hello", atts);
// user attributes should be off
Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many");
verifyOutput(service.filterErrorEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
verifyOutput(service.filterTransactionEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
verifyOutput(service.filterTransactionTraceAttributes(APP_NAME, t.getErrorAttributes()), expected);
verifyOutput(service.filterBrowserAttributes(APP_NAME, t.getErrorAttributes()), expected);
verifyOutput(service.filterSpanEventAttributes(APP_NAME, t.getErrorAttributes()), expected);
verifyOutput(service.filterTransactionSegmentAttributes(APP_NAME, t.getErrorAttributes()), expected);
} finally {
Transaction.clearTransaction();
}
}
Aggregations