diff --git a/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs b/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs index 4a7a7ddd91..54a04cc5ff 100644 --- a/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs +++ b/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs @@ -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 - string baseUserAgent = $"cosmos-netstandard-sdk/{clientVersion}" + Regex.Replace($"|{directVersion}|{this.clientId}|{processArchitecture}|{operatingSystem}|{runtimeFramework}|", @"[^0-9a-zA-Z\.\|\-]+", " "); - + string previewFlag = string.Empty; +#if PREVIEW + previewFlag = "P"; +#endif + string baseUserAgent = $"cosmos-netstandard-sdk/{clientVersion}" + previewFlag + Regex.Replace($"|{directVersion}|{this.clientId}|{processArchitecture}|{operatingSystem}|{runtimeFramework}|", @"[^0-9a-zA-Z\.\|\-]+", " "); if (!string.IsNullOrEmpty(regionConfiguration)) { baseUserAgent += $"{regionConfiguration}|"; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserAgentTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserAgentTests.cs index c0906969a5..4941e61f8a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserAgentTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserAgentTests.cs @@ -88,7 +88,11 @@ public void VerifyUserAgentContent() Assert.IsTrue(serialization.Contains(envInfo.ProcessArchitecture)); string[] values = serialization.Split('|'); - Assert.AreEqual($"cosmos-netstandard-sdk/{envInfo.ClientVersion}", values[0]); + string previewFlag = string.Empty; +#if PREVIEW + previewFlag = "P"; +#endif + Assert.AreEqual($"cosmos-netstandard-sdk/{envInfo.ClientVersion}" + previewFlag, values[0]); Assert.AreEqual(envInfo.DirectVersion, values[1]); Assert.AreEqual("0", values[2]); Assert.AreEqual(envInfo.ProcessArchitecture, values[3]); @@ -100,7 +104,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();