diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java index 9c591cb5..cf0562ae 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogAgentClient.java @@ -66,6 +66,8 @@ of this software and associated documentation files (the "Software"), to deal */ public class DatadogAgentClient implements DatadogClient { + private static final int PAYLOAD_SIZE_LIMIT = 5 * 1024 * 1024; // 5 MB + private static volatile DatadogAgentClient instance = null; // Used to determine if the instance failed last validation last time, so // we do not keep retrying to create the instance and logging the same error @@ -556,6 +558,10 @@ private void sendSpansToWebhook(Collection spans) { } byte[] body = span.getJson().toString().getBytes(StandardCharsets.UTF_8); + if (body.length > PAYLOAD_SIZE_LIMIT) { + logger.severe("Dropping span because payload size (" + body.length + ") exceeds the allowed limit of " + PAYLOAD_SIZE_LIMIT); + continue; + } // webhook intake does not support batch requests logger.fine("Sending webhook"); diff --git a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogApiClient.java b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogApiClient.java index 2573dbe1..288137cf 100644 --- a/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogApiClient.java +++ b/src/main/java/org/datadog/jenkins/plugins/datadog/clients/DatadogApiClient.java @@ -59,6 +59,8 @@ of this software and associated documentation files (the "Software"), to deal */ public class DatadogApiClient implements DatadogClient { + private static final int PAYLOAD_SIZE_LIMIT = 5 * 1024 * 1024; // 5 MB + private static volatile DatadogApiClient instance = null; // Used to determine if the instance failed last validation last time, so // we do not keep retrying to create the instance and logging the same error @@ -515,6 +517,10 @@ private void sendSpans(Collection spans) { } byte[] body = span.getJson().toString().getBytes(StandardCharsets.UTF_8); + if (body.length > PAYLOAD_SIZE_LIMIT) { + logger.severe("Dropping span because payload size (" + body.length + ") exceeds the allowed limit of " + PAYLOAD_SIZE_LIMIT); + continue; + } // webhook intake does not support batch requests logger.fine("Sending webhook");