Skip to content

[K9VULN-12867] Add User-Agent header to rule fetch requests#889

Merged
colemaring merged 6 commits intomainfrom
cole.maring/K9VULN-12867-version-header
Apr 30, 2026
Merged

[K9VULN-12867] Add User-Agent header to rule fetch requests#889
colemaring merged 6 commits intomainfrom
cole.maring/K9VULN-12867-version-header

Conversation

@colemaring
Copy link
Copy Markdown
Contributor

@colemaring colemaring commented Apr 22, 2026

Motivation

When a bug is identified on a specific version of datadog-static-analyzer, there's no way to correlate API calls to a CLI version. See K9VULN-12867. This adds a User-Agent header to every outbound rule-fetch request so the backend can emit a metric by version.

Changes

  • Added User-Agent: datadog-static-analyzer/<semver>-<git-sha> header to all requests in make_request
  • Associated PR to emit metrics on the version based on the user agent.

Testing

Deployed static-analysis-api to staging to test this PR.

The following was ran to built the binary on a SHA to simulate release.yml. Otherwise, the user agent would show as datadog-static-analyzer/x.x.x-development

SHA=$(git rev-parse HEAD) && sed -i '' "s/development/$SHA/g" crates/static-analysis-kernel/src/constants.rs
~/.cargo/bin/cargo build --release --bin datadog-static-analyzer
./target/release/datadog-static-analyzer --version
git checkout crates/static-analysis-kernel/src/constants.rs

I ran the binary to generate the following trace (with this PR deployed to staging):
Screenshot 2026-04-23 at 2 05 28 PM

trace
metrics

Note

This wont apply to CWP since CWP uses a separate client to fetch rules.

@datadog-official
Copy link
Copy Markdown

datadog-official Bot commented Apr 22, 2026

🎯 Code Coverage (details)
Patch Coverage: 0.00%
Overall Coverage: 85.07% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 984d131 | Docs | Datadog PR Page | Give us feedback!

@colemaring colemaring marked this pull request as ready for review April 22, 2026 20:09
Copilot AI review requested due to automatic review settings April 22, 2026 20:09
@colemaring colemaring requested a review from a team as a code owner April 22, 2026 20:09
@colemaring colemaring requested a review from bahar-shah April 22, 2026 20:09
bahar-shah
bahar-shah previously approved these changes Apr 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds version-identifying User-Agent information to outbound requests made by the CLI when fetching static-analysis rules, enabling backend correlation/metrics by CLI version/revision.

Changes:

  • Add User-Agent: datadog-static-analyzer/<semver> (<git-sha>) header to requests built by make_request.
  • Introduce build_user_agent() helper and a small unit test for its formatting.
  • Add new CLI constants for the User-Agent header and product name.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/cli/src/datadog_utils.rs Builds and attaches a versioned User-Agent header to outgoing requests; adds a unit test.
crates/cli/src/constants.rs Defines User-Agent header key and product name constants used by the CLI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/cli/src/datadog_utils.rs Outdated
Comment thread crates/cli/src/datadog_utils.rs Outdated
jasonforal
jasonforal previously approved these changes Apr 23, 2026
Comment thread crates/cli/src/datadog_utils.rs Outdated
@colemaring colemaring force-pushed the cole.maring/K9VULN-12867-version-header branch from e598435 to be41153 Compare April 29, 2026 13:28
@colemaring colemaring force-pushed the cole.maring/K9VULN-12867-version-header branch from be41153 to 8944b97 Compare April 29, 2026 13:31
@colemaring colemaring merged commit f65f252 into main Apr 30, 2026
90 checks passed
@colemaring colemaring deleted the cole.maring/K9VULN-12867-version-header branch April 30, 2026 13:48
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.

4 participants