Skip to content

Conversation

@EspenAlbert
Copy link
Collaborator

@EspenAlbert EspenAlbert commented Nov 10, 2025

Description

Adds provider_meta support to all data sources (TPF and SDKv2) for module usage tracking via User-Agent headers. Follows the same pattern as resources (PR #3618).

  • Created datasource_base.go for data source analytics in TPF
  • Added SetClient() method pattern matching resources
  • Shared asUserAgentExtraFromProviderMeta() between resources and data sources

Link to any related issue(s): CLOUDP-340210

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

Adds provider_meta support to all data sources (TPF and SDKv2) for module usage tracking via User-Agent headers. Follows the same pattern as resources (PR #3618).

- Created datasource_base.go for data source analytics in TPF
- Added SetClient() method pattern matching resources
- Shared asUserAgentExtraFromProviderMeta() between resources and data sources
@EspenAlbert EspenAlbert marked this pull request as ready for review November 10, 2025 15:23
@EspenAlbert EspenAlbert requested a review from a team as a code owner November 10, 2025 15:23
Copilot AI review requested due to automatic review settings November 10, 2025 15:23
Copy link
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

This PR adds provider_meta support to all data sources (both TPF and SDKv2) to enable module usage tracking via User-Agent headers, following the same pattern previously implemented for resources.

Key changes:

  • Created new datasource_base.go file for TPF data source analytics tracking
  • Extended NewAnalyticsResourceSDKv2 to support both resources and data sources via isDataSource parameter
  • Refactored User-Agent extra logic into shared asUserAgentExtraFromProviderMeta function

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/provider/provider_sdk2.go Wraps SDKv2 data sources with analytics support and updates resource wrapping to pass isDataSource=false
internal/provider/provider.go Wraps TPF data sources with analytics support using new AnalyticsDataSourceFunc
internal/config/user_agent.go Adds userAgentNameValueDataSource helper to format data source names with "data." prefix
internal/config/resource_base_sdkv2.go Extracts analytics logic into shared updateContextWithProviderMetaSDKv2 function supporting both resources and data sources
internal/config/resource_base.go Refactors to use shared asUserAgentExtraFromProviderMeta function and removes DSCommon (moved to datasource_base.go)
internal/config/datasource_base.go New file implementing DSCommon with analytics wrapper pattern for TPF data sources

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

// When embedded, the data source's own Schema method is used
}

func (d *DSCommon) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
Copy link
Member

Choose a reason for hiding this comment

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

should we have some tests or will be (indirectly) tested with all acc tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct, tested indirectly.

Copy link
Member

@AgustinBettati AgustinBettati left a comment

Choose a reason for hiding this comment

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

LGTM

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.

5 participants