Search in sources :

Example 1 with Span

use of co.elastic.apm.api.Span in project apm-agent-java by elastic.

the class SpanInstrumentationTest method testScope.

@Test
void testScope() {
    Span span = transaction.startSpan();
    assertThat(ElasticApm.currentSpan().getId()).isNotEqualTo(span.getId());
    try (final Scope scope = span.activate()) {
        assertThat(ElasticApm.currentSpan().getId()).isEqualTo(span.getId());
        ElasticApm.currentSpan().startSpan().end();
    }
    span.end();
    transaction.end();
    assertThat(reporter.getSpans()).hasSize(2);
    assertThat(reporter.getTransactions()).hasSize(1);
    assertThat(reporter.getSpans().get(0).isChildOf(reporter.getSpans().get(1))).isTrue();
    assertThat(reporter.getSpans().get(1).isChildOf(reporter.getFirstTransaction())).isTrue();
}
Also used : Scope(co.elastic.apm.api.Scope) Span(co.elastic.apm.api.Span) Test(org.junit.jupiter.api.Test) AbstractApiTest(co.elastic.apm.AbstractApiTest)

Example 2 with Span

use of co.elastic.apm.api.Span in project apm-agent-java by elastic.

the class SpanInstrumentationTest method testLegacyAPIs.

@Test
@SuppressWarnings("deprecation")
void testLegacyAPIs() {
    reporter.disableCheckStrictSpanType();
    Span span = transaction.createSpan();
    span.setType("foo.bar.baz");
    endSpan(span);
    co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan();
    assertThat(internalSpan.getType()).isEqualTo("foo");
    assertThat(internalSpan.getSubtype()).isEqualTo("bar");
    assertThat(internalSpan.getAction()).isEqualTo("baz");
}
Also used : Span(co.elastic.apm.api.Span) Test(org.junit.jupiter.api.Test) AbstractApiTest(co.elastic.apm.AbstractApiTest)

Example 3 with Span

use of co.elastic.apm.api.Span in project apm-agent-java by elastic.

the class SpanInstrumentationTest method testTypes.

@Test
void testTypes() {
    reporter.disableCheckStrictSpanType();
    Span span = transaction.startSpan("foo", "bar", "baz");
    endSpan(span);
    co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan();
    assertThat(internalSpan.getType()).isEqualTo("foo");
    assertThat(internalSpan.getSubtype()).isEqualTo("bar");
    assertThat(internalSpan.getAction()).isEqualTo("baz");
}
Also used : Span(co.elastic.apm.api.Span) Test(org.junit.jupiter.api.Test) AbstractApiTest(co.elastic.apm.AbstractApiTest)

Example 4 with Span

use of co.elastic.apm.api.Span in project apm-agent-java by elastic.

the class SpanInstrumentationTest method testTraceHeaders.

@Test
void testTraceHeaders() {
    Span span = transaction.startSpan();
    assertContainsTracingHeaders(span);
    assertContainsTracingHeaders(transaction);
    span.end();
}
Also used : Span(co.elastic.apm.api.Span) Test(org.junit.jupiter.api.Test) AbstractApiTest(co.elastic.apm.AbstractApiTest)

Example 5 with Span

use of co.elastic.apm.api.Span in project apm-agent-java by elastic.

the class SpanInstrumentationTest method testExitSpanFromNonExitSpan.

@Test
void testExitSpanFromNonExitSpan() {
    reporter.disableCheckStrictSpanType();
    reporter.disableCheckDestinationAddress();
    Span parent = transaction.startSpan("foo", "bar", "baz");
    Span span = parent.startExitSpan("foo", "bar", "baz");
    endSpan(span);
    co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan();
    // relying on auto-inference of context.destination.service.resource
    assertThat(internalSpan.getContext().getServiceTarget()).hasDestinationResource("bar");
}
Also used : Span(co.elastic.apm.api.Span) Test(org.junit.jupiter.api.Test) AbstractApiTest(co.elastic.apm.AbstractApiTest)

Aggregations

Span (co.elastic.apm.api.Span)15 AbstractApiTest (co.elastic.apm.AbstractApiTest)13 Test (org.junit.jupiter.api.Test)13 CaptureSpan (co.elastic.apm.api.CaptureSpan)2 Scope (co.elastic.apm.api.Scope)2 Transaction (co.elastic.apm.api.Transaction)2 IOException (java.io.IOException)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 TextHeaderMapAccessor (co.elastic.apm.agent.impl.TextHeaderMapAccessor)1 TraceContext (co.elastic.apm.agent.impl.transaction.TraceContext)1 BookkeeperObjectPool (co.elastic.apm.agent.objectpool.impl.BookkeeperObjectPool)1 Assertions.assertThat (co.elastic.apm.agent.testutils.assertions.Assertions.assertThat)1 ElasticApm (co.elastic.apm.api.ElasticApm)1 ServletException (jakarta.servlet.ServletException)1 SecureRandom (java.security.SecureRandom)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 ServletException (javax.servlet.ServletException)1 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)1