{"record":{"id":"3e26d7b5beee8ecd","repo":"apache/beam","slug":"datadog-write-failed-with-status-code-d-s","errorCode":null,"errorMessage":"Datadog write failed with status code %d: %s","messagePattern":"Datadog write failed with status code (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/datadog/src/main/java/org/apache/beam/sdk/io/datadog/DatadogWriteSchemaTransformProvider.java","lineNumber":286,"sourceCode":"                  .build());\n        } else {\n          throw new RuntimeException(e);\n        }\n      }\n    }\n  }\n\n  /**\n   * A {@link DoFn} that throws a {@link RuntimeException} when a write error is encountered,\n   * causing the pipeline to fail. This is the default error handling behavior when no error output\n   * is configured.\n   */\n  static class FailOnWriteErrorFn extends DoFn<DatadogWriteError, Void> {\n    @ProcessElement\n    public void processElement(@Element DatadogWriteError error) {\n      String message = error.statusMessage();\n      if (error.statusCode() != null) {\n        throw new RuntimeException(\n            String.format(\n                \"Datadog write failed with status code %d: %s\", error.statusCode(), message));\n      } else {\n        throw new RuntimeException(\"Datadog write failed: \" + message);\n      }\n    }\n  }\n}\n","sourceCodeStart":268,"sourceCodeEnd":295,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/datadog/src/main/java/org/apache/beam/sdk/io/datadog/DatadogWriteSchemaTransformProvider.java#L268-L295","documentation":"FailOnWriteErrorFn is the default failure handler of the Datadog SchemaTransform write. When a DatadogWriteError carries a non-null statusCode, processElement throws a RuntimeException embedding the HTTP status code and Datadog's status message, aborting the pipeline element.","triggerScenarios":"Datadog API responds with an HTTP error (e.g. 403 invalid API key, 429 rate limit, 413 payload too large) while writing events, and the default fail-on-error behavior is active.","commonSituations":"Expired or wrong Datadog API key, exceeding the intake events limit (402/429), or sending events larger than Datadog's size limit.","solutions":["Verify the Datadog API key and app key are valid and have write permissions.","Check the status code in the message: 429/402 means rate/quota limits — add batching or reduce event rate.","Implement a custom failure handler (e.g. via a dead-letter output or retry sink) instead of the default FailOnWriteErrorFn.","Retry with backoff for transient 5xx status codes."],"exampleFix":"// before\n.write(); // default: throws on any Datadog error\n// after\n.apply(\"DatadogWrite\", DatadogIO.write().withApi(...).withFailureSignal(...)); // route errors to a dead-letter PCollection","handlingStrategy":"try-catch","validationCode":"// Pre-flight: validate API key\nHttpURLConnection c = (HttpURLConnection) new URL(datadogUrl + \"/api/v1/validate\").openConnection();\nc.setRequestProperty(\"DD-API-KEY\", apiKey);\nif (c.getResponseCode() != 200) throw new IllegalStateException(\"Invalid Datadog API key\");","typeGuard":"static boolean isRetryable(Integer statusCode) {\n  return statusCode != null && (statusCode >= 500 || statusCode == 429);\n}","tryCatchPattern":"try {\n  write.apply(datadogTransform);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Datadog write failed with status code 4\")) {\n    // fix credentials/payload; not retryable\n  } else {\n    // retry with backoff\n  }\n}","preventionTips":["Validate API/app keys before launching the pipeline.","Respect Datadog intake limits; batch and rate-limit events.","Route failures to a dead-letter PCollection instead of the default fail-fast handler."],"tags":["java","apache-beam","datadog","http-error"],"backgroundTag":"http-error-response","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}