diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/DatadogBasePipelineLogic.java b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/DatadogBasePipelineLogic.java index 64af28e1..45ff9441 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/DatadogBasePipelineLogic.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/DatadogBasePipelineLogic.java @@ -5,11 +5,12 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; +import javax.annotation.Nonnull; import net.sf.json.JSONObject; import org.datadog.jenkins.plugins.datadog.DatadogUtilities; import org.datadog.jenkins.plugins.datadog.model.BuildData; -import org.datadog.jenkins.plugins.datadog.model.PipelineStepData; import org.datadog.jenkins.plugins.datadog.model.PipelineNodeInfoAction; +import org.datadog.jenkins.plugins.datadog.model.PipelineStepData; import org.datadog.jenkins.plugins.datadog.util.SuppressFBWarnings; @@ -21,6 +22,7 @@ public abstract class DatadogBasePipelineLogic { protected static final String CI_PROVIDER = "jenkins"; protected static final String HOSTNAME_NONE = "none"; + @Nonnull public abstract JSONObject toJson(PipelineStepData current, Run run) throws IOException, InterruptedException; @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/AgentTraceWriteStrategy.java b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/AgentTraceWriteStrategy.java index 6afa6746..80697e6f 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/AgentTraceWriteStrategy.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/AgentTraceWriteStrategy.java @@ -9,6 +9,7 @@ import java.util.function.Supplier; import java.util.logging.Logger; import java.util.stream.Collectors; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.datadog.jenkins.plugins.datadog.clients.DatadogAgentClient; import org.datadog.jenkins.plugins.datadog.model.BuildData; @@ -53,7 +54,7 @@ public Payload serialize(BuildData buildData, Run run) { return getCurrentStrategy().serialize(buildData, run); } - @Nullable + @Nonnull @Override public Payload serialize(PipelineStepData stepData, Run run) throws IOException, InterruptedException { return getCurrentStrategy().serialize(stepData, run); diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategy.java b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategy.java index 68323ae8..f357195e 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategy.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategy.java @@ -3,6 +3,7 @@ import hudson.model.Run; import java.io.IOException; import java.util.Collection; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.datadog.jenkins.plugins.datadog.model.BuildData; import org.datadog.jenkins.plugins.datadog.model.PipelineStepData; @@ -11,7 +12,7 @@ public interface TraceWriteStrategy { @Nullable Payload serialize(BuildData buildData, Run run); - @Nullable + @Nonnull Payload serialize(PipelineStepData stepData, Run run) throws IOException, InterruptedException; void send(Collection spans); diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategyImpl.java b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategyImpl.java index 57c0f3ae..b0f44226 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategyImpl.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/traces/write/TraceWriteStrategyImpl.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.function.Consumer; import java.util.logging.Logger; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import net.sf.json.JSONObject; import org.datadog.jenkins.plugins.datadog.DatadogUtilities; @@ -52,11 +53,11 @@ public Payload serialize(final BuildData buildData, final Run run) { return buildSpan != null ? new Payload(buildSpan, track) : null; } - @Nullable + @Nonnull @Override public Payload serialize(PipelineStepData stepData, Run run) throws IOException, InterruptedException { JSONObject stepSpan = pipelineLogic.toJson(stepData, run); - return stepSpan != null ? new Payload(stepSpan, track) : null; + return new Payload(stepSpan, track); } @Override diff --git a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientStub.java b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientStub.java index 9acc22a2..f2dff677 100644 --- a/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientStub.java +++ b/src/test/java/org/datadog/jenkins/plugins/datadog/clients/DatadogClientStub.java @@ -41,6 +41,7 @@ of this software and associated documentation files (the "Software"), to deal import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import net.sf.json.JSONObject; import org.datadog.jenkins.plugins.datadog.DatadogClient; @@ -56,6 +57,7 @@ of this software and associated documentation files (the "Software"), to deal import org.datadog.jenkins.plugins.datadog.traces.write.Payload; import org.datadog.jenkins.plugins.datadog.traces.write.TraceWriteStrategy; import org.datadog.jenkins.plugins.datadog.traces.write.Track; +import org.jetbrains.annotations.NotNull; import org.junit.Assert; public class DatadogClientStub implements DatadogClient { @@ -304,21 +306,15 @@ public Payload serialize(BuildData buildData, Run run) { } } - @Nullable + @Nonnull @Override - public Payload serialize(PipelineStepData stepData, Run run) throws IOException, InterruptedException { + public @NotNull Payload serialize(PipelineStepData stepData, Run run) throws IOException, InterruptedException { if (isWebhook) { JSONObject json = new DatadogWebhookPipelineLogic().toJson(stepData, run); - if (json == null) { - return null; - } webhooks.add(json); return new Payload(json, Track.WEBHOOK); } else { TraceSpan span = new DatadogTracePipelineLogic().toSpan(stepData, run); - if (span == null) { - return null; - } traces.add(span); JSONObject json = new JsonTraceSpanMapper().map(span); return new Payload(json, Track.APM);