From 46afe940d7c4cff866a4db9d9053af4cadd60955 Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko Date: Thu, 15 Jun 2023 18:17:28 +0200 Subject: [PATCH] Do not send empty test suite spans --- .../trace/civisibility/DDTestSessionImpl.java | 3 ++- .../trace/civisibility/DDTestSuiteImpl.java | 19 +++++++++++-------- .../context/AbstractTestContext.java | 9 +++++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/DDTestSessionImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/DDTestSessionImpl.java index 5f0e98bf5f4d..e19bb06d3795 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/DDTestSessionImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/DDTestSessionImpl.java @@ -80,7 +80,8 @@ public void setSkipReason(String skipReason) { @Override public void end(@Nullable Long endTime) { - span.setTag(Tags.TEST_STATUS, context.getStatus()); + String status = context.getStatus(); + span.setTag(Tags.TEST_STATUS, status != null ? status : CIConstants.TEST_SKIP); testDecorator.beforeFinish(span); if (endTime != null) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/DDTestSuiteImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/DDTestSuiteImpl.java index 8d00f92e94bd..e415b67528fa 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/DDTestSuiteImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/DDTestSuiteImpl.java @@ -7,7 +7,6 @@ import datadog.trace.api.civisibility.CIConstants; import datadog.trace.api.civisibility.DDTest; import datadog.trace.api.civisibility.DDTestSuite; -import datadog.trace.api.civisibility.decorator.TestDecorator; import datadog.trace.api.civisibility.source.SourcePathResolver; import datadog.trace.bootstrap.instrumentation.api.AgentScope; import datadog.trace.bootstrap.instrumentation.api.AgentSpan; @@ -17,6 +16,7 @@ import datadog.trace.civisibility.codeowners.Codeowners; import datadog.trace.civisibility.context.SpanTestContext; import datadog.trace.civisibility.context.TestContext; +import datadog.trace.civisibility.decorator.TestDecorator; import datadog.trace.civisibility.source.MethodLinesResolver; import java.lang.reflect.Method; import javax.annotation.Nullable; @@ -143,13 +143,16 @@ public void end(@Nullable Long endTime) { testDecorator.beforeFinish(span); String status = context.getStatus(); - span.setTag(Tags.TEST_STATUS, status); - moduleContext.reportChildStatus(status); - - if (endTime != null) { - span.finish(endTime); - } else { - span.finish(); + if (status != null) { + // do not report test suite if no execution took place + span.setTag(Tags.TEST_STATUS, status); + moduleContext.reportChildStatus(status); + + if (endTime != null) { + span.finish(endTime); + } else { + span.finish(); + } } } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/context/AbstractTestContext.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/context/AbstractTestContext.java index e2bfebc57f16..5db4b65a1d1c 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/context/AbstractTestContext.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/context/AbstractTestContext.java @@ -4,19 +4,24 @@ abstract class AbstractTestContext implements TestContext { - private String status = CIConstants.TEST_SKIP; + private String status; @Override public synchronized void reportChildStatus(String childStatus) { switch (childStatus) { case CIConstants.TEST_PASS: - if (CIConstants.TEST_SKIP.equals(status)) { + if (status == null || CIConstants.TEST_SKIP.equals(status)) { status = CIConstants.TEST_PASS; } break; case CIConstants.TEST_FAIL: status = CIConstants.TEST_FAIL; break; + case CIConstants.TEST_SKIP: + if (status == null) { + status = CIConstants.TEST_SKIP; + } + break; default: break; }