private ErrorCapture validateError(AbstractSpan span, boolean sampled, Transaction correspondingTransaction) { assertThat(reporter.getErrors()).hasSize(1); ErrorCapture error = reporter.getFirstError(); assertThat(error.getTraceContext().isChildOf(span.getTraceContext())).isTrue(); assertThat(error.getTransactionInfo().isSampled()).isEqualTo(sampled); assertThat(error.getTransactionInfo().getType()).isEqualTo(correspondingTransaction.getType()); return error; }
public void captureException(long epochMicros, @Nullable Throwable e, @Nullable TraceContextHolder<?> active) { if (e != null) { ErrorCapture error = errorPool.createInstance(); error.withTimestamp(epochMicros); error.setException(e); Transaction currentTransaction = currentTransaction(); if (currentTransaction != null) { error.setTransactionType(currentTransaction.getType()); error.setTransactionSampled(currentTransaction.isSampled()); } if (active != null) { if (active instanceof Transaction) { Transaction transaction = (Transaction) active; // The error might have occurred in a different thread than the one the transaction was recorded // That's why we have to ensure the visibility of the transaction properties error.getContext().copyFrom(transaction.getContextEnsureVisibility()); } else if (active instanceof Span) { Span span = (Span) active; error.getContext().getTags().putAll(span.getContext().getTags()); } error.asChildOf(active.getTraceContext()); } else { error.getTraceContext().getId().setToRandomValue(); } reporter.report(error); } }
@Test void testSamplingNone() throws IOException { config.getConfig(CoreConfiguration.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME); Transaction transaction = tracerImpl.startTransaction().withType("request"); try (Scope scope = transaction.activateInScope()) { transaction.setUser("1", "jon.doe@example.com", "jondoe"); 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"); }
private void serializeTransaction(final Transaction transaction) { jw.writeByte(OBJECT_START); writeTimestamp(transaction.getTimestamp()); writeField("name", transaction.getName()); serializeTraceContext(transaction.getTraceContext(), false); writeField("type", transaction.getType()); writeField("duration", transaction.getDuration()); writeField("result", transaction.getResult()); serializeContext(transaction.getContext()); serializeSpanCount(transaction.getSpanCount()); writeLastField("sampled", transaction.isSampled()); jw.writeByte(OBJECT_END); }