use of co.elastic.apm.agent.impl.transaction.Span in project apm-agent-java by elastic.
the class ElasticApmTracer method createSpan.
private Span createSpan() {
Span span = spanPool.createInstance();
while (span.getReferenceCount() != 0) {
logger.warn("Tried to start a span with a non-zero reference count {} {}", span.getReferenceCount(), span);
span = spanPool.createInstance();
}
return span;
}
use of co.elastic.apm.agent.impl.transaction.Span in project apm-agent-java by elastic.
the class DiscardSpanTest method testErrorCapturingMakesSpansNonDiscardable.
@Test
void testErrorCapturingMakesSpansNonDiscardable() {
Transaction transaction = tracer.startRootTransaction(null);
assertThat(transaction).isNotNull();
try {
Span span = transaction.createSpan();
try {
span.requestDiscarding().appendToName("non-discardable").captureException(new Exception());
assertThat(span.isDiscardable()).isFalse();
} finally {
span.end();
}
} finally {
transaction.end();
}
assertThat(reporter.getSpans().stream().map(Span::getNameAsString)).containsExactly("non-discardable");
assertThat(transaction.getSpanCount().getTotal()).hasValue(1);
assertThat(transaction.getSpanCount().getDropped()).hasValue(0);
assertThat(transaction.getSpanCount().getReported()).hasValue(1);
}
use of co.elastic.apm.agent.impl.transaction.Span in project apm-agent-java by elastic.
the class DiscardSpanTest method testParentsOfContextPropagatingSpansAreNonDiscardable.
@Test
void testParentsOfContextPropagatingSpansAreNonDiscardable() {
Transaction transaction = tracer.startRootTransaction(null);
assertThat(transaction).isNotNull();
try {
Span parentSpan = transaction.createSpan().requestDiscarding();
try {
Span contextPropagatingSpan = parentSpan.createSpan();
try {
contextPropagatingSpan.propagateTraceContext(new HashMap<>(), TextHeaderMapAccessor.INSTANCE);
assertThat(contextPropagatingSpan.isDiscardable()).isFalse();
assertThat(parentSpan.isDiscardable()).isFalse();
} finally {
contextPropagatingSpan.end();
}
} finally {
parentSpan.end();
}
} finally {
transaction.end();
}
assertThat(transaction.getSpanCount().getTotal()).hasValue(2);
assertThat(transaction.getSpanCount().getDropped()).hasValue(0);
assertThat(transaction.getSpanCount().getReported()).hasValue(2);
}
use of co.elastic.apm.agent.impl.transaction.Span in project apm-agent-java by elastic.
the class ElasticApmTracerTest method testNestedSpan.
@Test
void testNestedSpan() {
Transaction transaction = startTestRootTransaction();
try (Scope scope = transaction.activateInScope()) {
assertThat(tracerImpl.currentTransaction()).isSameAs(transaction);
Span span = tracerImpl.getActive().createSpan();
try (Scope spanScope = span.activateInScope()) {
assertThat(tracerImpl.getActive()).isSameAs(span);
assertThat(span.isChildOf(transaction)).isTrue();
Span nestedSpan = tracerImpl.getActive().createSpan();
try (Scope nestedSpanScope = nestedSpan.activateInScope()) {
assertThat(tracerImpl.getActive()).isSameAs(nestedSpan);
assertThat(nestedSpan.isChildOf(span)).isTrue();
nestedSpan.end();
}
span.end();
}
assertThat(tracerImpl.getActive()).isEqualTo(transaction);
transaction.end();
}
assertThat(tracerImpl.currentTransaction()).isNull();
assertThat(reporter.getSpans()).hasSize(2);
}
use of co.elastic.apm.agent.impl.transaction.Span in project apm-agent-java by elastic.
the class ElasticApmTracerTest method testSamplingNone.
@Test
void testSamplingNone() throws IOException {
config.getConfig(CoreConfiguration.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME);
Transaction transaction = startTestRootTransaction().withType("request");
try (Scope scope = transaction.activateInScope()) {
transaction.setUser("1", "jon.doe@example.com", "jondoe", "domain");
Span span = tracerImpl.getActive().createSpan();
try (Scope spanScope = span.activateInScope()) {
span.end();
}
transaction.end();
}
// we do report non-sampled transactions (without the context)
assertThat(reporter.getTransactions()).hasSize(1);
assertThat(reporter.getSpans()).hasSize(0);
assertThat(reporter.getFirstTransaction().getContext().getUser().getEmail()).isNull();
assertThat(reporter.getFirstTransaction().getType()).isEqualTo("request");
}
Aggregations