Skip to content

Commit c27770a

Browse files
authored
Add User-Agent Header to gRPC Metadata (#417)
1 parent 33ec0d7 commit c27770a

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## (Unreleased)
44

5-
- - Add automatic retry on gateway timeout in `GrpcDurableTaskClient.WaitForInstanceCompletionAsync` in [#412](https://github.com/microsoft/durabletask-dotnet/pull/412))
5+
- Add automatic retry on gateway timeout in `GrpcDurableTaskClient.WaitForInstanceCompletionAsync` in ([#412](https://github.com/microsoft/durabletask-dotnet/pull/412))
66
- Add specific logging for NotFound error on worker connection by @halspang in ([#413](https://github.com/microsoft/durabletask-dotnet/pull/413))
7-
7+
- Add user agent header to gRPC called in ([#417](https://github.com/microsoft/durabletask-dotnet/pull/417))
88

99
## v1.10.0
1010

src/Client/AzureManaged/DurableTaskSchedulerClientOptions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Azure.Identity;
77
using Grpc.Core;
88
using Grpc.Net.Client;
9-
using Grpc.Net.Client.Configuration;
9+
using Microsoft.DurableTask;
1010

1111
namespace Microsoft.DurableTask;
1212

@@ -96,6 +96,9 @@ this.Credential is not null
9696
async (context, metadata) =>
9797
{
9898
metadata.Add("taskhub", taskHubName);
99+
100+
// Add user agent header with durabletask-dotnet and DLL version from util
101+
metadata.Add("user-agent", $"{DurableTaskUserAgentUtil.GetUserAgent()}");
99102
if (cache == null)
100103
{
101104
return;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Diagnostics;
5+
6+
namespace Microsoft.DurableTask;
7+
8+
/// <summary>
9+
/// Utility class for generating the user agent string for the Durable Task SDK.
10+
/// </summary>
11+
public static class DurableTaskUserAgentUtil
12+
{
13+
/// <summary>
14+
/// The name of the SDK used in the user agent string.
15+
/// </summary>
16+
const string SdkName = "durabletask-dotnet";
17+
18+
/// <summary>
19+
/// The version of the SDK used in the user agent string.
20+
/// </summary>
21+
static readonly string PackageVersion = FileVersionInfo.GetVersionInfo(typeof(DurableTaskUserAgentUtil).Assembly.Location).FileVersion;
22+
23+
/// <summary>
24+
/// Generates the user agent string for the Durable Task SDK based on a fixed name and the package version.
25+
/// </summary>
26+
/// <returns>The user agent string.</returns>
27+
public static string GetUserAgent()
28+
{
29+
return $"{SdkName}/{PackageVersion?.ToString() ?? "unknown"}";
30+
}
31+
}

src/Worker/AzureManaged/DurableTaskSchedulerWorkerOptions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Azure.Identity;
77
using Grpc.Core;
88
using Grpc.Net.Client;
9-
using Grpc.Net.Client.Configuration;
9+
using Microsoft.DurableTask;
1010

1111
namespace Microsoft.DurableTask;
1212

@@ -102,6 +102,8 @@ this.Credential is not null
102102
async (context, metadata) =>
103103
{
104104
metadata.Add("taskhub", taskHubName);
105+
// Add user agent header with durabletask-dotnet and DLL version from util
106+
metadata.Add("user-agent", $"{DurableTaskUserAgentUtil.GetUserAgent()}");
105107
metadata.Add("workerid", this.WorkerId);
106108
if (cache == null)
107109
{

0 commit comments

Comments
 (0)