Skip to content

Feat/custom user agent#14

Merged
platinummonkey merged 4 commits into
mainfrom
feat/custom-user-agent
Feb 10, 2026
Merged

Feat/custom user agent#14
platinummonkey merged 4 commits into
mainfrom
feat/custom-user-agent

Conversation

@amaskara-dd
Copy link
Copy Markdown
Contributor

@amaskara-dd amaskara-dd commented Feb 10, 2026

What does this PR do?

Use a custom user agent to track requests coming from pup

Checklist

  • The code change follows the project conventions (see CONTRIBUTING.md)
  • Tests have been added/updated (if applicable)
  • Documentation has been updated (if applicable)
  • All CI checks pass
  • Code coverage is maintained or improved

amaskara-dd and others added 2 commits February 10, 2026 04:54
Set custom User-Agent header to identify API requests as coming from pup CLI
rather than the generic datadog-api-client-go library. This enables better
tracking and analytics of pup CLI usage in Datadog API logs.

Changes:
- Added getUserAgent() function that formats user agent as "pup/<version> (go <version>; os <os>; arch <arch>)"
- Set configuration.UserAgent in New() for datadog API client (pkg/client/client.go:77)
- Set User-Agent header in RawRequest() for raw HTTP requests (pkg/client/client.go:139)
- Imported runtime package for OS/arch information
- Imported internal/version package for pup version

The user agent will now identify requests as:
  pup/dev (go go1.21.0; os darwin; arch arm64)

This applies to both:
1. API calls through the datadog-api-client-go library
2. Raw HTTP requests through the RawRequest method

The format matches datadog-api-client-go's getUserAgent() implementation,
using the same structure: "<tool>/<version> (go <version>; os <os>; arch <arch>)"

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive unit tests to verify custom User-Agent header is correctly
set in both API client and raw HTTP requests.

Changes:
- Added TestGetUserAgent() to verify user agent format (pkg/client/client_test.go:494)
- Added TestRawRequest_UserAgentHeader() to verify header in raw requests (pkg/client/client_test.go:537)
- Added TestNew_SetsCustomUserAgent() to verify client configuration (pkg/client/client_test.go:603)
- Added runtime and internal/version imports for testing

Test results show User-Agent is correctly set as:
  pup/dev (go go1.25.0; os darwin; arch arm64)

All tests pass:
✓ TestGetUserAgent - verifies format and content
✓ TestRawRequest_UserAgentHeader - verifies header in HTTP requests
✓ TestNew_SetsCustomUserAgent - verifies client configuration

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@amaskara-dd amaskara-dd requested a review from a team as a code owner February 10, 2026 10:03
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 10, 2026

📊 Test Coverage Report

Overall Coverage: 75.5% Coverage

Threshold: 80% ❌

Coverage by Package
## Coverage by Package

- github.com/DataDog/pup/pkg/auth/callback/server.go:40: 81.2%
- github.com/DataDog/pup/pkg/auth/dcr/client.go:28: 100.0%
- github.com/DataDog/pup/pkg/auth/dcr/types.go:24: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/client.go:22: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/pkce.go:24: 85.7%
- github.com/DataDog/pup/pkg/auth/storage/factory.go:53: 94.7%
- github.com/DataDog/pup/pkg/auth/storage/keychain.go:44: 42.9%
- github.com/DataDog/pup/pkg/auth/storage/storage.go:58: 71.4%
- github.com/DataDog/pup/pkg/auth/types/types.go:23: 100.0%
- github.com/DataDog/pup/pkg/client/client.go:33: 94.4%
- github.com/DataDog/pup/pkg/config/config.go:22: 100.0%
- github.com/DataDog/pup/pkg/formatter/formatter.go:31: 100.0%
- github.com/DataDog/pup/pkg/util/time.go:20: 95.8%

## Summary

total:								(statements)		75.5%

📈 Coverage Status: ❌ FAILED - Coverage below minimum threshold

Updated for commit 48c4990

…nt tests

Replace redundant unit tests with comprehensive integration tests that verify
the User-Agent header is set through the entire request flow.

Changes:
- Removed TestRawRequest_UserAgentHeader() - redundant with integration test
- Removed TestNew_SetsCustomUserAgent() - redundant with integration tests
- Added TestClient_IntegrationUserAgentInRawRequest() - integration test that
  verifies User-Agent is set when using RawRequest() method (client_test.go:538)
- Added TestClient_IntegrationUserAgentInAPIClient() - integration test that
  captures actual API client requests using custom HTTP transport to verify
  User-Agent header is used (client_test.go:628)
- Added captureTransport helper type to intercept HTTP requests
- Added datadogV1 import for testing with monitors API

Final test suite:
✓ TestGetUserAgent() - unit test for getUserAgent() function
✓ TestClient_IntegrationUserAgentInRawRequest() - integration test for RawRequest
✓ TestClient_IntegrationUserAgentInAPIClient() - integration test for API client

These integration tests verify the complete flow from New() through actual
HTTP requests, ensuring User-Agent is properly configured and used.

Coverage maintained at 90.7%

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@amaskara-dd amaskara-dd marked this pull request as draft February 10, 2026 10:32
Remove TestClient_IntegrationUserAgentInRawRequest() - it was simulating
the implementation instead of testing the actual method.

RawRequest() just calls getUserAgent() on line 139, which is already
covered by TestGetUserAgent() and TestClient_IntegrationUserAgentInAPIClient().

Coverage maintained at 90.7%

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@amaskara-dd amaskara-dd marked this pull request as ready for review February 10, 2026 10:46
@platinummonkey platinummonkey merged commit 1dd3632 into main Feb 10, 2026
4 checks passed
@platinummonkey platinummonkey deleted the feat/custom-user-agent branch February 10, 2026 12:09
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.

2 participants