Skip to content

Commit

Permalink
Add max payload size check for webhook requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog committed Jan 30, 2024
1 parent 8a654da commit 88b5e10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -556,6 +558,10 @@ private void sendSpansToWebhook(Collection<Payload> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -515,6 +517,10 @@ private void sendSpans(Collection<Payload> 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");
Expand Down

0 comments on commit 88b5e10

Please sign in to comment.