apache/beam · critical · IllegalArgumentException

API Key is required for writing events.

Error message

API Key is required for writing events.

What it means

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.

Solutions

  1. Call DatadogIO.write().withApiKey(yourApiKey) with the Datadog API key (not the APP key).
  2. Inject the key from a secure source (Secret Manager / pipeline options) and pass it explicitly to the sink.
  3. Validate non-null key in main() before launch to fail fast instead of at worker setup.

Example fix

// before
DatadogIO.write().withUrl(url); // apiKey null
// after
DatadogIO.write().withUrl(url).withApiKey(options.getDatadogApiKey());
Defensive patterns

Strategy: validation

Validate before calling

if (apiKey == null || apiKey.isEmpty()) {
  throw new IllegalArgumentException("Datadog API key required for writing events");
}

Try / catch

try { sink = DatadogIO.write().withUrl(url).withApiKey(key); } catch (IllegalArgumentException e) { LOG.error("Missing Datadog API key"); System.exit(2); }

Prevention

When it happens

Trigger: Applying DatadogIO.write() without withApiKey(), or passing a null ValueProvider/options value so apiKey() returns null in setup().

Common situations: 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.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/50f9c384fcfd1b44. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/io/datadog/src/main/java/org/apache/beam/sdk/io/datadog/DatadogEventWriter.java:154

  abstract Integer minBatchCount();

  @Nullable
  abstract Integer inputBatchCount();

  @Nullable
  abstract Long maxBufferSize();

  @Setup
  public void setup() {

    final String url = url();
    if (url == null) {
      throw new IllegalArgumentException("url is required for writing events.");
    }
    checkArgument(isValidUrlFormat(url), INVALID_URL_FORMAT_MESSAGE);
    final String apiKey = apiKey();
    if (apiKey == null) {
      throw new IllegalArgumentException("API Key is required for writing events.");
    }

    batchCount = MoreObjects.firstNonNull(inputBatchCount(), DEFAULT_BATCH_COUNT);
    LOG.info("Batch count set to: {}", batchCount);

    maxBufferSize = MoreObjects.firstNonNull(maxBufferSize(), MAX_BUFFER_SIZE);
    LOG.info("Max buffer size set to: {}", maxBufferSize);

    checkArgument(
        batchCount >= MoreObjects.firstNonNull(minBatchCount(), MIN_BATCH_COUNT),
        "batchCount must be greater than or equal to %s",
        minBatchCount());
    checkArgument(
        batchCount <= MAX_BATCH_COUNT,
        "batchCount must be less than or equal to %s",
        MAX_BATCH_COUNT);

    try {

View on GitHub (pinned to 12126d8942)