Search in sources :

Example 46 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class SpanParentTest method testCrossProcessOnly.

@Test
public void testCrossProcessOnly() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("cross_process_only_test");
    executeCrossProcessOnlyTest();
    try {
        TransactionDataList transactionList = holder.getTransactionList();
        assertEquals(2, transactionList.size());
        TransactionData tx1 = transactionList.get(0);
        TransactionData tx2 = transactionList.get(1);
        Collection<Tracer> tracers1 = tx1.getTracers();
        // Only a "rootTracer" on this transaction (root tracer is not in this list)
        assertEquals(0, tracers1.size());
        Collection<Tracer> tracers2 = tx2.getTracers();
        // 1 "rootTracer" (not in this list) + 2 non-external/datastore tracers + 2 external datastore tracers
        assertEquals(4, tracers2.size());
        SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
        String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
        SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
        assertNotNull(spanEventsPool);
        List<SpanEvent> spanEvents = spanEventsPool.asList();
        spanEventsPool.clear();
        assertNotNull(spanEvents);
        assertEquals(2, spanEvents.size());
        SpanEvent externalSpanEvent = null;
        SpanEvent datastoreSpanEvent = null;
        for (SpanEvent spanEvent : spanEvents) {
            if (spanEvent.getCategory() == SpanCategory.http) {
                externalSpanEvent = spanEvent;
            } else if (spanEvent.getCategory() == SpanCategory.datastore) {
                datastoreSpanEvent = spanEvent;
            }
        }
        assertNotNull(externalSpanEvent);
        assertNotNull(datastoreSpanEvent);
        // For right now, we are putting cross-process only mode on ice. Poor orphan spans :(
        assertNull(externalSpanEvent.getParentId());
        assertNull(datastoreSpanEvent.getParentId());
    } finally {
        holder.close();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) Tracer(com.newrelic.agent.tracers.Tracer) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 47 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class TransactionAttributesOnSpanTest method testCustomParameterAndAttributeOnSpans.

@Test
public void testCustomParameterAndAttributeOnSpans() {
    String expectedSpanName = "Java/test.newrelic.test.agent.spans.TransactionAttributesOnSpanTest/transactionLaunchPoint";
    transactionLaunchPoint(1, 1);
    int numberOfSpansWithSpanAttribute = 0;
    String spanNameWithTransactionAttribute = null;
    List<SpanEvent> spanEvents = spanEventPool.asList();
    for (SpanEvent span : spanEvents) {
        if (span.getUserAttributesCopy().containsKey("txAttrib0")) {
            assertNull("Span, " + span.getName() + ", should not have a transaction attribute. The attribute " + "is already on " + spanNameWithTransactionAttribute, spanNameWithTransactionAttribute);
            assertEquals(expectedSpanName, span.getName());
            spanNameWithTransactionAttribute = span.getName();
        }
        if (span.getUserAttributesCopy().containsKey("spanAttrib0")) {
            numberOfSpansWithSpanAttribute++;
        }
    }
    assertEquals(1, numberOfSpansWithSpanAttribute);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Example 48 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class SpanEventSender method pollAndWrite.

@VisibleForTesting
void pollAndWrite() {
    // Get stream observer
    ClientCallStreamObserver<V1.Span> observer = channelManager.getSpanObserver();
    // Confirm the observer is ready
    if (!awaitReadyObserver(observer)) {
        return;
    }
    // Poll queue for span
    SpanEvent span = pollSafely();
    if (span == null) {
        return;
    }
    // Convert span and write to observer
    V1.Span convertedSpan = SpanConverter.convert(span);
    writeToObserver(observer, convertedSpan);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) V1(com.newrelic.trace.v1.V1) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 49 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class InfiniteTracingTest method accept_IncrementsCounterAndOffersToQueue.

@Test
@Timeout(1)
void accept_IncrementsCounterAndOffersToQueue() {
    SpanEvent spanEvent = SpanEvent.builder().build();
    target.accept(spanEvent);
    verify(aggregator).incrementCounter("Supportability/InfiniteTracing/Span/Seen");
    assertEquals(spanEvent, queue.poll());
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 50 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class SpanConverterTest method convert_Valid.

@Test
void convert_Valid() throws IOException {
    SpanEvent spanEvent = buildSpanEvent();
    V1.Span result = SpanConverter.convert(spanEvent);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    result.writeTo(baos);
    V1.Span deserialized = V1.Span.parseFrom(baos.toByteArray());
    assertEquals("abc123", deserialized.getTraceId());
    assertEquals("abc123", deserialized.getIntrinsicsOrThrow("traceId").getStringValue());
    assertEquals("my app", deserialized.getIntrinsicsOrThrow("appName").getStringValue());
    assertEquals("value", deserialized.getIntrinsicsOrThrow("intrStr").getStringValue());
    assertEquals(12345, deserialized.getIntrinsicsOrThrow("intrInt").getIntValue());
    assertEquals(3.14, deserialized.getIntrinsicsOrThrow("intrFloat").getDoubleValue(), 0.00001);
    assertTrue(deserialized.getIntrinsicsOrThrow("intrBool").getBoolValue());
    assertFalse(deserialized.containsIntrinsics("intrOther"));
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) V1(com.newrelic.trace.v1.V1) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

SpanEvent (com.newrelic.agent.model.SpanEvent)81 Test (org.junit.Test)64 AttributeFilter (com.newrelic.agent.model.AttributeFilter)23 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)19 TransactionStats (com.newrelic.agent.stats.TransactionStats)14 TransactionData (com.newrelic.agent.TransactionData)12 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)12 Tracer (com.newrelic.agent.tracers.Tracer)9 HashMap (java.util.HashMap)8 Map (java.util.Map)5 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)4 TransactionDataList (com.newrelic.agent.TransactionDataList)3 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)3 Test (org.junit.jupiter.api.Test)3 SpanConverterTest.buildSpanEvent (com.newrelic.SpanConverterTest.buildSpanEvent)2 BoundTransactionApiImpl (com.newrelic.agent.BoundTransactionApiImpl)2 AttributesService (com.newrelic.agent.attributes.AttributesService)2 AgentConfig (com.newrelic.agent.config.AgentConfig)2 ReservoirManager (com.newrelic.agent.interfaces.ReservoirManager)2 Consumer (com.newrelic.agent.interfaces.backport.Consumer)2