From 9799c17988261de0119059f753bac0b8e45268d2 Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko <121111529+nikita-tkachenko-datadog@users.noreply.github.com> Date: Thu, 22 Jun 2023 17:10:47 +0200 Subject: [PATCH] Do not send empty test suite spans (#5405) --- .../trace/civisibility/DDTestSessionImpl.java | 3 ++- .../trace/civisibility/DDTestSuiteImpl.java | 17 ++++++++++------- .../context/AbstractTestContext.java | 9 +++++++-- 3 files changed, 19 insertions(+), 10 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 5f0e98bf5f4..e19bb06d379 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 8d00f92e94b..f508e8e5ee7 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 @@ -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 e2bfebc57f1..5db4b65a1d1 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; }