Skip to content

Commit 14718a5

Browse files
committed
User agent fix
1 parent 53d7064 commit 14718a5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Extensions/Cosmos/Cosmos.DataTransfer.CosmosExtension/CosmosDataSinkExtension.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Globalization;
55
using System.Reflection;
66
using System.Text;
7+
using System.Text.RegularExpressions;
78
using Cosmos.DataTransfer.Interfaces;
89
using Microsoft.Azure.Cosmos;
910
using Microsoft.Extensions.Configuration;
@@ -33,8 +34,8 @@ public async Task WriteAsync(IAsyncEnumerable<IDataItem> dataItems, IConfigurati
3334

3435
var entryAssembly = Assembly.GetEntryAssembly();
3536
bool isShardedImport = false;
36-
string sourceName = dataSource.DisplayName;
37-
string sinkName = DisplayName;
37+
string sourceName = StripSpecialChars(dataSource.DisplayName);
38+
string sinkName = StripSpecialChars(DisplayName);
3839
string userAgentString = string.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}-{3}{4}",
3940
entryAssembly == null ? "dtr" : entryAssembly.GetName().Name,
4041
Assembly.GetExecutingAssembly().GetName().Version,
@@ -119,6 +120,11 @@ void ReportCount(int i)
119120
logger.LogInformation("Added {AddedCount} total records in {TotalSeconds}s", addedCount, $"{timer.ElapsedMilliseconds / 1000.0:F2}");
120121
}
121122

123+
private static string StripSpecialChars(string displayName)
124+
{
125+
return Regex.Replace(displayName, "[^\\w]", "", RegexOptions.Compiled);
126+
}
127+
122128
private static AsyncRetryPolicy GetRetryPolicy(int maxRetryCount, int initialRetryDuration)
123129
{
124130
int retryDelayBaseMs = initialRetryDuration / 2;

0 commit comments

Comments
 (0)