Search in sources :

Example 1 with AgentIdentity

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);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) AttributeFilter(com.newrelic.agent.model.AttributeFilter) AgentIdentity(com.newrelic.agent.environment.AgentIdentity) Test(org.junit.Test)

Example 2 with AgentIdentity

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"));
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) Tracer(com.newrelic.agent.tracers.Tracer) SpanProxy(com.newrelic.agent.tracing.SpanProxy) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) SpanError(com.newrelic.agent.model.SpanError) Environment(com.newrelic.agent.environment.Environment) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) TransactionData(com.newrelic.agent.TransactionData) AgentIdentity(com.newrelic.agent.environment.AgentIdentity) Before(org.junit.Before)

Example 3 with AgentIdentity

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);
}
Also used : AgentIdentity(com.newrelic.agent.environment.AgentIdentity) Trace(com.newrelic.api.agent.Trace)

Example 4 with AgentIdentity

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());
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) AgentIdentity(com.newrelic.agent.environment.AgentIdentity) Transaction(com.newrelic.agent.Transaction) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Trace(com.newrelic.api.agent.Trace)

Aggregations

AgentIdentity (com.newrelic.agent.environment.AgentIdentity)4 Trace (com.newrelic.api.agent.Trace)2 Transaction (com.newrelic.agent.Transaction)1 TransactionData (com.newrelic.agent.TransactionData)1 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)1 Environment (com.newrelic.agent.environment.Environment)1 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)1 AttributeFilter (com.newrelic.agent.model.AttributeFilter)1 SpanError (com.newrelic.agent.model.SpanError)1 SpanEvent (com.newrelic.agent.model.SpanEvent)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 Tracer (com.newrelic.agent.tracers.Tracer)1 SpanProxy (com.newrelic.agent.tracing.SpanProxy)1 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)1 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)1 Before (org.junit.Before)1