Skip to content

fix(metrics): require DD_API_KEY for metrics submit command#75

Merged
platinummonkey merged 1 commit intomainfrom
fix/metrics-submit-require-api-key
Feb 17, 2026
Merged

fix(metrics): require DD_API_KEY for metrics submit command#75
platinummonkey merged 1 commit intomainfrom
fix/metrics-submit-require-api-key

Conversation

@platinummonkey
Copy link
Collaborator

Summary

The Datadog metrics intake API requires API key authentication — OAuth2 bearer tokens are not supported for metric submission. This PR adds a pre-emptive check that gives users (and agents) a clear, actionable error message when DD_API_KEY is not set, instead of failing later with a confusing auth error.

Changes

  • Add API key check at the start of runMetricsSubmit before client creation (cmd/metrics.go:833)
  • Use apiKeyClientFactory instead of getClient() to force API key auth, skipping OAuth (cmd/metrics.go:845)
  • Add TestRunMetricsSubmit_RequiresAPIKey test for the missing API key scenario (cmd/metrics_test.go:630)
  • Mock apiKeyClientFactory in setupMetricsTestClient helper for consistent test behavior (cmd/metrics_test.go:50)

Testing

  • All existing metrics tests pass
  • New test verifies the error message mentions DD_API_KEY and explains the requirement
  • Full test suite passes (go test ./...)

🤖 Generated with Claude Code

The Datadog metrics intake API does not support OAuth2 bearer tokens,
only API key authentication. Add a pre-emptive check before client
creation to give users a clear, actionable error message when DD_API_KEY
is not set, instead of a generic authentication failure.

- Check cfg.APIKey before creating the client
- Use apiKeyClientFactory to force API key auth (skip OAuth)
- Add dedicated test for missing API key scenario

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@platinummonkey platinummonkey requested a review from a team as a code owner February 17, 2026 23:27
@platinummonkey platinummonkey merged commit 9aead01 into main Feb 17, 2026
8 of 9 checks passed
@platinummonkey platinummonkey deleted the fix/metrics-submit-require-api-key branch February 17, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments