Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PREVIEW] UserAgent: Adds flag to user agent string if preview SDK. #2960

Merged
merged 8 commits into from
Jan 6, 2022
Merged
5 changes: 4 additions & 1 deletion Microsoft.Azure.Cosmos/src/UserAgentContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ private string CreateBaseUserAgentString(

// Regex replaces all special characters with empty space except . - | since they do not cause format exception for the user agent string.
// Do not change the cosmos-netstandard-sdk as it is required for reporting
#if PREVIEW
string baseUserAgent = $"cosmos-netstandard-sdk/{clientVersion}" + "P" + Regex.Replace($"|{directVersion}|{this.clientId}|{processArchitecture}|{operatingSystem}|{runtimeFramework}|", @"[^0-9a-zA-Z\.\|\-]+", " ");
j82w marked this conversation as resolved.
Show resolved Hide resolved
SchintaMicrosoft marked this conversation as resolved.
Show resolved Hide resolved
#else
string baseUserAgent = $"cosmos-netstandard-sdk/{clientVersion}" + Regex.Replace($"|{directVersion}|{this.clientId}|{processArchitecture}|{operatingSystem}|{runtimeFramework}|", @"[^0-9a-zA-Z\.\|\-]+", " ");

#endif
if (!string.IsNullOrEmpty(regionConfiguration))
{
baseUserAgent += $"{regionConfiguration}|";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ public void VerifyUserAgentContent()

Assert.IsTrue(serialization.Contains(envInfo.ProcessArchitecture));
string[] values = serialization.Split('|');

#if PREVIEW
Assert.AreEqual($"cosmos-netstandard-sdk/{envInfo.ClientVersion}" + "P", values[0]);
#else
Assert.AreEqual($"cosmos-netstandard-sdk/{envInfo.ClientVersion}", values[0]);
#endif
Assert.AreEqual(envInfo.DirectVersion, values[1]);
Assert.AreEqual("0", values[2]);
Assert.AreEqual(envInfo.ProcessArchitecture, values[3]);
Expand All @@ -100,7 +105,7 @@ public void VerifyUserAgentContent()
public async Task VerifyUserAgentWithRegionConfiguration()
{
string databaseName = Guid.NewGuid().ToString();
string containerName = Guid.NewGuid().ToString();
string containerName = Guid.NewGuid().ToString();

{
CosmosClientOptions cosmosClientOptions = new CosmosClientOptions();
Expand Down