{"record":{"id":"50f9c384fcfd1b44","repo":"apache/beam","slug":"api-key-is-required-for-writing-events","errorCode":null,"errorMessage":"API Key is required for writing events.","messagePattern":"API Key is required for writing events\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"critical","filePath":"sdks/java/io/datadog/src/main/java/org/apache/beam/sdk/io/datadog/DatadogEventWriter.java","lineNumber":154,"sourceCode":"  abstract Integer minBatchCount();\n\n  @Nullable\n  abstract Integer inputBatchCount();\n\n  @Nullable\n  abstract Long maxBufferSize();\n\n  @Setup\n  public void setup() {\n\n    final String url = url();\n    if (url == null) {\n      throw new IllegalArgumentException(\"url is required for writing events.\");\n    }\n    checkArgument(isValidUrlFormat(url), INVALID_URL_FORMAT_MESSAGE);\n    final String apiKey = apiKey();\n    if (apiKey == null) {\n      throw new IllegalArgumentException(\"API Key is required for writing events.\");\n    }\n\n    batchCount = MoreObjects.firstNonNull(inputBatchCount(), DEFAULT_BATCH_COUNT);\n    LOG.info(\"Batch count set to: {}\", batchCount);\n\n    maxBufferSize = MoreObjects.firstNonNull(maxBufferSize(), MAX_BUFFER_SIZE);\n    LOG.info(\"Max buffer size set to: {}\", maxBufferSize);\n\n    checkArgument(\n        batchCount >= MoreObjects.firstNonNull(minBatchCount(), MIN_BATCH_COUNT),\n        \"batchCount must be greater than or equal to %s\",\n        minBatchCount());\n    checkArgument(\n        batchCount <= MAX_BATCH_COUNT,\n        \"batchCount must be less than or equal to %s\",\n        MAX_BATCH_COUNT);\n\n    try {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/datadog/src/main/java/org/apache/beam/sdk/io/datadog/DatadogEventWriter.java#L136-L172","documentation":"DatadogEventWriter.setup() throws IllegalArgumentException when no API key is configured, because authenticating to the Datadog events API is mandatory. The key must be provided via DatadogIO.write().withApiKey(...) (or options) before the writer runs; this check executes at @Setup on each worker bundle.","triggerScenarios":"Applying DatadogIO.write() without withApiKey(), or passing a null ValueProvider/options value so apiKey() returns null in setup().","commonSituations":"API key kept only in local env vars that don't exist on Dataflow workers; key supplied via a runtime parameter not wired into the sink; key accidentally omitted when migrating from read to write transforms.","solutions":["Call DatadogIO.write().withApiKey(yourApiKey) with the Datadog API key (not the APP key).","Inject the key from a secure source (Secret Manager / pipeline options) and pass it explicitly to the sink.","Validate non-null key in main() before launch to fail fast instead of at worker setup."],"exampleFix":"// before\nDatadogIO.write().withUrl(url); // apiKey null\n// after\nDatadogIO.write().withUrl(url).withApiKey(options.getDatadogApiKey());","handlingStrategy":"validation","validationCode":"if (apiKey == null || apiKey.isEmpty()) {\n  throw new IllegalArgumentException(\"Datadog API key required for writing events\");\n}","typeGuard":null,"tryCatchPattern":"try { sink = DatadogIO.write().withUrl(url).withApiKey(key); } catch (IllegalArgumentException e) { LOG.error(\"Missing Datadog API key\"); System.exit(2); }","preventionTips":["Provide the API key via secure pipeline options or Secret Manager, then pass it with withApiKey(...).","Distinguish API key from APP key; only the API key authenticates event writes.","Fail fast on null/blank keys during local dry-runs before submitting to runners."],"tags":["java","beam-io","datadog","api-key","authentication"],"backgroundTag":"missing-api-key","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"}