use of com.newrelic.agent.environment.AgentIdentity in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method testRequestAttributesAddedToRoot.
@Test
public void testRequestAttributesAddedToRoot() {
// setup
String requestUri = "httpss://404.com";
String requestMethod = "SUPERGET";
String requestHeadersRefer = "referee";
String requestHeadersAccept = "college";
String requestHeadersContentLength = "very long";
String requestHeadersHost = "Drew Carey";
String requestHeadersUserAgent = "007";
float queueDuration = 123456789F;
expectedAgentAttributes.put(REQUEST_REFERER_PARAMETER_NAME, requestHeadersRefer);
expectedAgentAttributes.put(REQUEST_ACCEPT_PARAMETER_NAME, requestHeadersAccept);
expectedAgentAttributes.put(REQUEST_CONTENT_LENGTH_PARAMETER_NAME, requestHeadersContentLength);
expectedAgentAttributes.put(REQUEST_HOST_PARAMETER_NAME, requestHeadersHost);
expectedAgentAttributes.put(REQUEST_USER_AGENT_PARAMETER_NAME, requestHeadersUserAgent);
expectedAgentAttributes.put(REQUEST_METHOD_PARAMETER_NAME, requestMethod);
expectedAgentAttributes.put(REQUEST_URI, requestUri);
expectedAgentAttributes.put(PORT, port);
expectedAgentAttributes.put(QUEUE_DURATION, queueDuration);
SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
transactionAgentAttributes.put(REQUEST_REFERER_PARAMETER_NAME, requestHeadersRefer);
transactionAgentAttributes.put(REQUEST_ACCEPT_PARAMETER_NAME, requestHeadersAccept);
transactionAgentAttributes.put(REQUEST_CONTENT_LENGTH_PARAMETER_NAME, requestHeadersContentLength);
transactionAgentAttributes.put(REQUEST_HOST_PARAMETER_NAME, requestHeadersHost);
transactionAgentAttributes.put(REQUEST_USER_AGENT_PARAMETER_NAME, requestHeadersUserAgent);
transactionAgentAttributes.put(REQUEST_METHOD_PARAMETER_NAME, requestMethod);
transactionAgentAttributes.put(REQUEST_URI, requestUri);
transactionAgentAttributes.put(PORT, port);
when(txnData.getAgentAttributes()).thenReturn(transactionAgentAttributes);
when(environment.getAgentIdentity()).thenReturn(new AgentIdentity("dispatcher", "1.2.3", port, "myInstance"));
when(txnStats.getUnscopedStats().getStatsMap().containsKey(QUEUE_TIME)).thenReturn(true);
when(txnStats.getUnscopedStats().getOrCreateResponseTimeStats(QUEUE_TIME).getTotal()).thenReturn(queueDuration);
TracerToSpanEvent testClass = new TracerToSpanEvent(errorBuilderMap, new AttributeFilter.PassEverythingAttributeFilter(), timestampProvider, environmentService, transactionDataToDistributedTraceIntrinsics, spanErrorBuilder);
// execution
SpanEvent spanEvent = testClass.createSpanEvent(tracer, txnData, txnStats, isRoot, false);
// assertions
assertEquals(expectedSpanEvent, spanEvent);
}
use of com.newrelic.agent.environment.AgentIdentity in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method setup.
@Before
public void setup() {
transactionAgentAttributes = new HashMap<>();
transactionUserAttributes = new HashMap<>();
tracerAgentAttributes = new HashMap<>();
tracerUserAttributes = new HashMap<>();
expectedAgentAttributes = new HashMap<>();
expectedUserAttributes = new HashMap<>();
expectedAgentAttributes.put("error.class", "0");
expectedAgentAttributes.put("port", 9191);
expectedIntrinsicAttributes = new HashMap<>();
expectedIntrinsicAttributes.put("traceId", traceId);
expectedIntrinsicAttributes.put("duration", (float) duration / TimeConversion.NANOSECONDS_PER_SECOND);
expectedIntrinsicAttributes.put("type", "Span");
expectedIntrinsicAttributes.put("category", "generic");
expectedIntrinsicAttributes.put("sampled", sampled);
expectedIntrinsicAttributes.put("nr.entryPoint", true);
expectedIntrinsicAttributes.put("timestamp", timestamp);
expectedIntrinsicAttributes.put("priority", priority);
expectedIntrinsicAttributes.put("transaction.name", txnName.getName());
tracer = mock(Tracer.class);
txnData = mock(TransactionData.class);
spanErrorBuilder = mock(SpanErrorBuilder.class);
spanError = mock(SpanError.class);
spanProxy = mock(SpanProxy.class);
throwable = mock(TransactionThrowable.class);
environmentService = mock(EnvironmentService.class);
environment = mock(Environment.class);
transactionDataToDistributedTraceIntrinsics = mock(TransactionDataToDistributedTraceIntrinsics.class);
txnStats = mock(TransactionStats.class, RETURNS_DEEP_STUBS);
errorBuilderMap = new HashMap<>();
errorBuilderMap.put(appName, spanErrorBuilder);
when(tracer.getDuration()).thenReturn(duration);
when(tracer.getStartTimeInMillis()).thenReturn(timestamp);
when(tracer.getAgentAttributes()).thenReturn(tracerAgentAttributes);
when(tracer.getCustomAttributes()).thenReturn(tracerUserAttributes);
when(spanErrorBuilder.buildSpanError(tracer, isRoot, responseStatus, statusMessage, throwable)).thenReturn(spanError);
when(spanErrorBuilder.areErrorsEnabled()).thenReturn(true);
when(txnData.getApplicationName()).thenReturn(appName);
when(txnData.getResponseStatus()).thenReturn(responseStatus);
when(txnData.getStatusMessage()).thenReturn(statusMessage);
when(txnData.getThrowable()).thenReturn(throwable);
when(txnData.getPriority()).thenReturn(priority);
when(txnData.sampled()).thenReturn(sampled);
when(txnData.getSpanProxy()).thenReturn(spanProxy);
when(txnData.getPriorityTransactionName()).thenReturn(txnName);
when(txnData.getUserAttributes()).thenReturn(transactionUserAttributes);
when(spanProxy.getOrCreateTraceId()).thenReturn(traceId);
when(environmentService.getEnvironment()).thenReturn(environment);
when(environment.getAgentIdentity()).thenReturn(new AgentIdentity("dispatcher", "1.2.3", 9191, "myInstance"));
}
use of com.newrelic.agent.environment.AgentIdentity in project newrelic-java-agent by newrelic.
the class CircuitBreakerApiTest method runTestWebFrameworkAPI.
@Trace(dispatcher = true)
private void runTestWebFrameworkAPI() {
NewRelic.setAppServerPort(666);
NewRelic.setInstanceName("instance");
NewRelic.setServerInfo("server", "6.6.6");
AgentIdentity env = ServiceFactory.getEnvironmentService().getEnvironment().getAgentIdentity();
int port = env.getServerPort();
String instance = env.getInstanceName();
String dispatcher = env.getDispatcher();
String version = env.getDispatcherVersion();
Assert.assertEquals(666, port);
Assert.assertEquals("instance", instance);
Assert.assertEquals("server", dispatcher);
Assert.assertEquals("6.6.6", version);
}
use of com.newrelic.agent.environment.AgentIdentity in project newrelic-java-agent by newrelic.
the class ApiTest method runTestWebFrameworkAPI.
@Trace(dispatcher = true)
private void runTestWebFrameworkAPI() {
NewRelic.setAppServerPort(666);
NewRelic.setInstanceName("instance");
NewRelic.setServerInfo("server", "6.6.6");
com.newrelic.agent.bridge.Transaction txn = AgentBridge.getAgent().getTransaction();
AgentIdentity env = ServiceFactory.getEnvironmentService().getEnvironment().getAgentIdentity();
txn.convertToWebTransaction();
Assert.assertTrue(txn.isWebTransaction());
ExtendedRequest request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
txn.setWebRequest(request);
Assert.assertTrue(txn.isWebRequestSet());
ApiTestHelper.DummyResponse dummyResponse = new ApiTestHelper.DummyResponse();
NewRelic.getAgent().getTransaction().setWebResponse(dummyResponse);
Assert.assertTrue(txn.isWebResponseSet());
WebRequestDispatcher webRequestDispatcher = (WebRequestDispatcher) AgentBridge.getAgent().getTransaction().getWebResponse();
try {
int status = webRequestDispatcher.getResponse().getStatus();
String statusMessage = webRequestDispatcher.getResponse().getStatusMessage();
Assert.assertEquals(200, status);
Assert.assertEquals("HTTP 200 OK", statusMessage);
} catch (Exception ex) {
Assert.fail();
}
int port = env.getServerPort();
String instance = env.getInstanceName();
String dispatcher = env.getDispatcher();
String version = env.getDispatcherVersion();
Assert.assertEquals(666, port);
Assert.assertEquals("instance", instance);
Assert.assertEquals("server", dispatcher);
Assert.assertEquals("6.6.6", version);
NewRelic.getAgent().getTransaction().markResponseSent();
Transaction tx = Transaction.getTransaction(false);
Assert.assertNotEquals(0, tx.getTransactionTimer().getResponseTimeInNanos());
}
Aggregations