Skip to content

Cosmos: Add user agent tracking for azure-cosmos-encryption SDK#48505

Open
kushagraThapar wants to merge 4 commits intoAzure:mainfrom
kushagraThapar:kushagra/encryption-sdk-user-agent
Open

Cosmos: Add user agent tracking for azure-cosmos-encryption SDK#48505
kushagraThapar wants to merge 4 commits intoAzure:mainfrom
kushagraThapar:kushagra/encryption-sdk-user-agent

Conversation

@kushagraThapar
Copy link
Member

@kushagraThapar kushagraThapar commented Mar 21, 2026

Summary

The azure-cosmos-encryption library currently wraps the core CosmosAsyncClient without appending its own identifier to the user agent string. This makes it impossible to track encryption SDK adoption, version distribution, or customer usage through telemetry (e.g., ComputeRequest5M, DailyUserAgentSummary).

This PR adds user agent tracking by appending azure-cosmos-encryption/{version} to the existing user agent suffix when the encryption client is constructed. It also GA's the deleteAllItemsByPartitionKey API.

Changes

azure-cosmos-encryption:

  • Added azure-cosmos-encryption.properties resource file (Maven-filtered name and version, same pattern as azure-cosmos-kafka-connect.properties)
  • Added PROPERTIES_FILE_NAME, CURRENT_VERSION, CURRENT_NAME, and USER_AGENT_SUFFIX constants in Constants.java using CoreUtils.getProperties()
  • In CosmosEncryptionAsyncClient constructor, append the encryption SDK suffix via CosmosBridgeInternal.getAsyncDocumentClient().appendUserAgentSuffix()
  • GA'd deleteAllItemsByPartitionKey API in CosmosEncryptionAsyncContainer and CosmosEncryptionContainer — the core SDK API has been public, but the encryption wrappers were still package-private

azure-cosmos:

  • Added appendUserAgentSuffix(String) method to AsyncDocumentClient interface and RxDocumentClientImpl — appends to the existing UserAgentContainer suffix, preserving any customer-set suffix

Resulting User Agent

azsdk-java-cosmos/4.79.0 Linux/6.6 JRE/21.0.9 <customer-suffix> azure-cosmos-encryption/2.28.0

Why This Approach

The encryption SDK takes an already-built CosmosAsyncClient — it doesn't own the CosmosClientBuilder. Unlike Spark/Kafka/Spring which call CosmosClientBuilder.userAgentSuffix() before building, we need to append to the UserAgentContainer after construction. This is non-breaking — existing customers get tracking automatically with no code changes.

Testing

  • Unit tests added in CosmosEncryptionAsyncClientUnitTest:
    • encryptionClientAppendsUserAgentSuffix — verifies appendUserAgentSuffix is called with the correct suffix during construction
    • encryptionUserAgentSuffixContainsVersionInfo — verifies properties file is loaded and suffix format is correct
    • encryptionClientHandlesAppendFailureGracefully — verifies client construction succeeds even if UA append fails
  • Unit test added in UserAgentContainerTest:
    • appendUserAgentSuffix — verifies suffix append behavior with empty and existing suffixes

The azure-cosmos-encryption library wraps the core CosmosAsyncClient
without appending its own identifier to the user agent string, making
it impossible to track encryption SDK adoption through telemetry.

Changes:
- Add azure-cosmos-encryption.properties resource file with
  artifactId and version (Maven-filtered at build time)
- Add USER_AGENT_SUFFIX constant in Constants.java that reads the
  properties via CoreUtils.getProperties() (same pattern as Kafka
  connector)
- Add appendUserAgentSuffix() method to AsyncDocumentClient interface
  and RxDocumentClientImpl to allow appending to the UserAgentContainer
  after client construction
- Call appendUserAgentSuffix() in CosmosEncryptionAsyncClient
  constructor to append 'azure-cosmos-encryption/{version}' to the
  existing user agent

The resulting user agent will look like:
azsdk-java-cosmos/4.x.x OS/ver JRE/ver <customer-suffix> azure-cosmos-encryption/2.x.y

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kushagraThapar kushagraThapar marked this pull request as ready for review March 21, 2026 15:32
@kushagraThapar kushagraThapar requested review from a team and kirankumarkolli as code owners March 21, 2026 15:32
Copilot AI review requested due to automatic review settings March 21, 2026 15:32
- Add 3 unit tests in CosmosEncryptionAsyncClientUnitTest verifying
  user agent suffix append, properties loading, and graceful failure
- Add unit test in UserAgentContainerTest for append suffix behavior
- Add changelog entries for azure-cosmos and azure-cosmos-encryption
- GA deleteAllItemsByPartitionKey in CosmosEncryptionAsyncContainer
  and CosmosEncryptionContainer (core SDK API is already public)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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

Adds telemetry-friendly user-agent suffixing so azure-cosmos-encryption usage/version can be tracked even when wrapping an already-constructed CosmosAsyncClient.

Changes:

  • Add an appendUserAgentSuffix(String) API on the internal AsyncDocumentClient and implement it in RxDocumentClientImpl.
  • Add Maven-filtered azure-cosmos-encryption.properties and constants to derive azure-cosmos-encryption/{version} at runtime.
  • Append the encryption SDK user-agent suffix when CosmosEncryptionAsyncClient is constructed.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java Implements appendUserAgentSuffix by appending onto UserAgentContainer suffix.
sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java Adds new appendUserAgentSuffix(String) method to the internal client interface.
sdk/cosmos/azure-cosmos-encryption/src/main/resources/azure-cosmos-encryption.properties Adds filtered name/version resource used to build the encryption UA suffix.
sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/implementation/Constants.java Loads name/version from properties and builds USER_AGENT_SUFFIX.
sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionAsyncClient.java Appends encryption UA suffix to the wrapped Cosmos client during construction.

- Make appendUserAgentSuffix a default no-op method on
  AsyncDocumentClient interface for binary compatibility
- Add de-duplication check to prevent suffix growth when multiple
  encryption clients wrap the same CosmosAsyncClient
- Preserve feature flags (|F...) by re-applying them via
  addUserAgentSuffix after setSuffix overwrites the user agent
- Enhance UserAgentContainerTest to cover feature flag preservation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@xinlian12
Copy link
Member

@sdkReviewAgent-2

@xinlian12
Copy link
Member

PR Review Agent — Starting review...

…geFeed

- Fix dedup: use token-based matching instead of substring contains()
  to avoid false positives (e.g. 2.28.0 matching 2.28.0-beta.1)
- Cache properties map and use getOrDefault() for defensive fallback
  if properties file is missing at runtime
- GA queryChangeFeed in CosmosEncryptionAsyncContainer and
  CosmosEncryptionContainer (core SDK API is already public)
- Update changelog to include queryChangeFeed GA

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Member

@aayush3011 aayush3011 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants