use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.
the class CrossProcessStateCatApiTest method trustAppAndGetTracer.
private CatTestCustomTracer trustAppAndGetTracer(String accountID) {
ImmutableMap<String, Object> crossProcessSettings = ImmutableMap.<String, Object>builder().put(CrossProcessConfigImpl.ENCODING_KEY, ENCODING_KEY).put(CrossProcessConfigImpl.ENABLED, Boolean.TRUE).put(CrossProcessConfigImpl.TRUSTED_ACCOUNT_IDS, accountID).put(CrossProcessConfigImpl.CROSS_PROCESS_ID, accountID + "#878").build();
// Disable DT for CAT specific tests
ImmutableMap<String, Object> distributedTracingSettings = ImmutableMap.<String, Object>builder().put(DistributedTracingConfig.ENABLED, Boolean.FALSE).build();
Map<String, Object> settings = new HashMap<>();
settings.put(AgentConfigImpl.CROSS_APPLICATION_TRACER, crossProcessSettings);
settings.put(AgentConfigImpl.APP_NAME, "TransactionAppNamingTest");
settings.put(AgentConfigImpl.DISTRIBUTED_TRACING, distributedTracingSettings);
ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(settings);
serviceManager.setConfigService(configService);
Transaction.clearTransaction();
Transaction transaction = Transaction.getTransaction(true);
ClassMethodSignature classMethodSignature = new ClassMethodSignature("className", "methodName", "methodDesc");
MetricNameFormat metricNameFormat = new DefaultMetricNameFormat(classMethodSignature, "", "something");
CatTestCustomTracer tracer = new CatTestCustomTracer(transaction, classMethodSignature, null, metricNameFormat, TracerFlags.DISPATCHER | TracerFlags.GENERATE_SCOPED_METRIC);
transaction.getTransactionActivity().tracerStarted(tracer);
cps = transaction.getCrossProcessState();
return tracer;
}
use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.
the class DatabaseServiceTest method instanceSlowSqlAttribute.
@Test
public void instanceSlowSqlAttribute() throws Exception {
Map<String, Object> configMap = createStagingMap();
Map<String, Object> ttConfigMap = createMap();
ttConfigMap.put(TransactionTracerConfigImpl.ENABLED, true);
ttConfigMap.put(TransactionTracerConfigImpl.COLLECT_TRACES, true);
ttConfigMap.put(TransactionTracerConfigImpl.EXPLAIN_THRESHOLD, 0);
configMap.put(AgentConfigImpl.TRANSACTION_TRACER, ttConfigMap);
Map<String, Object> dsConfigMap = createMap();
dsConfigMap.put(DatastoreConfigImpl.INSTANCE_REPORTING, true);
configMap.put(AgentConfigImpl.DATASTORE_TRACER, dsConfigMap);
Map<String, Object> stConfigMap = createMap();
stConfigMap.put(SqlTraceConfigImpl.ENABLED, true);
configMap.put(AgentConfigImpl.SLOW_SQL, stConfigMap);
createServiceManager(configMap);
final Connection connection = Mockito.mock(Connection.class);
final String databaseName = "myDatabase";
Mockito.when(connection.getCatalog()).thenReturn(databaseName);
DatastoreInstanceDetection.detectConnectionAddress();
InetSocketAddress address = new InetSocketAddress("address", 8080);
DatastoreInstanceDetection.associateAddress(connection, address);
DatastoreInstanceDetection.stopDetectingConnectionAddress();
Transaction transaction = Transaction.getTransaction(true);
ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
TestDefaultSqlTracer tracer = new TestDefaultSqlTracer(transaction, sig, null, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS);
tracer.setRawSql("select * from metrics");
tracer.provideConnection(connection);
ConnectionFactory connectionFactory = createConnectionFactory(connection);
tracer.setConnectionFactory(connectionFactory);
AgentHelper.setLastTracer(tracer);
tracer.finish(Opcodes.ARETURN, new DummyResultSet());
Assert.assertEquals(address.getHostName(), tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_HOST));
Assert.assertEquals(String.valueOf(address.getPort()), tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_PORT_PATH_OR_ID));
Assert.assertEquals(databaseName, tracer.getAgentAttribute(DatastoreMetrics.DB_INSTANCE));
Transaction.clearTransaction();
}
use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.
the class WebRequestDispatcherTest method createDispatcher.
private WebRequestDispatcher createDispatcher(MockHttpRequest httpRequest) throws Exception {
Transaction tx = Transaction.getTransaction();
Response httpResponse = new MockHttpResponse();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "methodName", "()V");
DefaultTracer tracer = new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
tx.getTransactionActivity().tracerStarted(tracer);
WebRequestDispatcher dispatcher = new WebRequestDispatcher(httpRequest, httpResponse, tx);
tx.setDispatcher(dispatcher);
return dispatcher;
}
use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.
the class TransactionTraceTest method serializeAttsDisabledWithIntrinsics.
@SuppressWarnings("unchecked")
@Test
public void serializeAttsDisabledWithIntrinsics() throws Exception {
setUp(false, true, false);
Tracer rootTracer = new TestMethodExitTracer();
Map<String, Object> parameters = Collections.emptyMap();
Tracer tracer = Mockito.mock(Tracer.class);
Mockito.when(tracer.getClassMethodSignature()).thenReturn(new ClassMethodSignature(getClass().getName(), "testMethod", "testSignature"));
Mockito.when(tracer.getAgentAttributes()).thenReturn(parameters);
Mockito.when(tracer.getEndTime()).thenReturn(5000000000L);
Mockito.when(tracer.getDuration()).thenReturn(3000000000L);
;
Map<String, String> requestParams = new HashMap<>();
requestParams.put("key1", "value1");
Map<String, Object> userParams = new HashMap<>();
userParams.put("key2", "value2");
Map<String, Object> errorParams = new HashMap<>();
errorParams.put("error1", "valueError");
Map<String, Object> agentParams = new HashMap<>();
agentParams.put("key3", "value3");
Map<String, Object> intrinsics = new HashMap<>();
intrinsics.put("key4", "value4");
intrinsics.put("key5", 5L);
long startTime = System.currentTimeMillis();
String frontendMetricName = "Frontend/dude";
String requestUri = "/dude";
String appName = "dude";
String transactionGuid = "guid";
TransactionData transactionData = new TransactionDataTestBuilder(appName, iAgentConfig, tracer).setStartTime(startTime).setRequestUri(requestUri).setFrontendMetricName(frontendMetricName).setTracers(Collections.singletonList(rootTracer)).setRequestParams(requestParams).setUserParams(userParams).setAgentParams(agentParams).setErrorParams(errorParams).setIntrinsics(intrinsics).build();
TransactionTrace trace = TransactionTrace.getTransactionTrace(transactionData, SqlObfuscator.getDefaultSqlObfuscator());
JSONParser parser = new JSONParser();
// Get the raw data
JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(trace);
// Manually create an "inflated" version for comparison with simple compression
JSONArray inflatedJsonArray = new JSONArray();
inflatedJsonArray.addAll(jsonArray);
// Extract and inflate
Object decodedTTData = decodeTransactionTraceData(inflatedJsonArray.get(4));
// Store back in array to compare with simple compression below
inflatedJsonArray.set(4, decodedTTData);
Assert.assertNotNull(jsonArray);
// Second, serialize with simple compression off (data will be deflated)
byte[] jsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
JSONArray parsedJsonByteArray = (JSONArray) parser.parse(new String(jsonByteArray, StandardCharsets.UTF_8));
Assert.assertEquals(jsonArray, parsedJsonByteArray);
// Third, turn on simple compression and compare with raw data above
setUp(false, true, true);
byte[] simpleCompressionJsonByteArray = AgentHelper.serializeJSONToByteArray(trace);
JSONArray parsedSimpleCompressionJsonByteArray = (JSONArray) parser.parse(new String(simpleCompressionJsonByteArray, StandardCharsets.UTF_8));
Assert.assertEquals(inflatedJsonArray, parsedSimpleCompressionJsonByteArray);
JSONArray jsonRootSegment = (JSONArray) decodedTTData;
Assert.assertEquals(8, jsonArray.size());
Assert.assertEquals(startTime, jsonArray.get(0));
Assert.assertEquals(5000L, jsonArray.get(1));
Assert.assertEquals(frontendMetricName, jsonArray.get(2));
Object serializedRequestUri = jsonArray.get(3);
Assert.assertEquals(null, serializedRequestUri);
Assert.assertEquals(transactionGuid, jsonArray.get(5));
Assert.assertNull(jsonArray.get(6));
// obsolete forcePersist flag
Assert.assertEquals(false, jsonArray.get(7));
Assert.assertEquals(5, jsonRootSegment.size());
Assert.assertEquals(startTime, jsonRootSegment.get(0));
JSONObject emptyObject = (JSONObject) jsonRootSegment.get(1);
Assert.assertEquals(0, emptyObject.size());
emptyObject = (JSONObject) jsonRootSegment.get(2);
Assert.assertEquals(0, emptyObject.size());
JSONObject atts = (JSONObject) jsonRootSegment.get(4);
Assert.assertEquals(1, atts.size());
Map<String, Object> innerAtts = (Map<String, Object>) atts.get("intrinsics");
Assert.assertEquals(3, innerAtts.size());
Assert.assertEquals("value4", innerAtts.get("key4"));
Assert.assertEquals(5L, innerAtts.get("key5"));
Assert.assertNotNull(innerAtts.get("totalTime"));
}
use of com.newrelic.agent.tracers.ClassMethodSignature in project newrelic-java-agent by newrelic.
the class TransactionTraceTest method testDistributedTracingAtts.
@Test
public void testDistributedTracingAtts() throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
Map<String, Object> config = new HashMap<>();
Map<String, Object> dtConfig = new HashMap<>();
dtConfig.put("enabled", true);
config.put("distributed_tracing", dtConfig);
Map<String, Object> spanConfig = new HashMap<>();
spanConfig.put("collect_span_events", true);
config.put("span_events", spanConfig);
config.put(AgentConfigImpl.APP_NAME, "TransactionTraceTest");
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), config);
serviceManager.setConfigService(configService);
serviceManager.setAttributesService(new AttributesService());
serviceManager.setTransactionTraceService(new TransactionTraceService());
serviceManager.setTransactionService(new TransactionService());
DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
serviceManager.setDistributedTraceService(distributedTraceService);
TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
serviceManager.setRPMServiceManager(new MockRPMServiceManager());
Transaction.clearTransaction();
Transaction transaction = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("class", "method", "desc");
OtherRootTracer tracer = new OtherRootTracer(transaction, sig, null, new SimpleMetricNameFormat("metric"));
transaction.getTransactionActivity().tracerStarted(tracer);
tracer.finish(Opcodes.ARETURN, null);
TransactionData td = new TransactionData(transaction, 0);
((DistributedTraceServiceImpl) ServiceFactory.getDistributedTraceService()).dispatcherTransactionFinished(td, new TransactionStats());
TransactionTrace trace = TransactionTrace.getTransactionTrace(td, SqlObfuscator.getDefaultSqlObfuscator());
Writer writer = new StringWriter();
trace.writeJSONString(writer);
JSONArray serializedTrace = (JSONArray) AgentHelper.serializeJSON(trace);
JSONArray traceDetails = (JSONArray) decodeTransactionTraceData(serializedTrace.get(4));
JSONObject atts = (JSONObject) traceDetails.get(4);
Map<String, Object> intrinsics = (Map<String, Object>) atts.get("intrinsics");
Assert.assertTrue(intrinsics.containsKey("traceId"));
Assert.assertTrue(intrinsics.containsKey("guid"));
Assert.assertTrue(intrinsics.containsKey("priority"));
Assert.assertTrue(intrinsics.containsKey("sampled"));
}
Aggregations