Skip to content

Commit 4954477

Browse files
authored
Add User-Agent Header to gRPC Metadata (#213)
1 parent 7fcd449 commit 4954477

File tree

7 files changed

+87
-3
lines changed

7 files changed

+87
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## placeholder
2+
* Add User-Agent Header to gRPC Metadata ([#213](https://github.com/microsoft/durabletask-java/pull/213))
3+
## v1.5.0-preview.1
24
* Update protobuf definitions to include new properties in OrchestratorRequest and update source commit hash ([#214](https://github.com/microsoft/durabletask-java/pull/214))
3-
## v1.5.1.preview
45
* DTS Support ([#201](https://github.com/microsoft/durabletask-java/pull/201))
56
* Add automatic proto file download and commit hash tracking during build ([#207](https://github.com/microsoft/durabletask-java/pull/207))
67
* Fix infinite loop when use continueasnew after wait external event ([#183](https://github.com/microsoft/durabletask-java/pull/183))

azuremanaged/build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,26 @@ spotbugsTest {
152152
}
153153
}
154154

155+
// Add this after the plugins block
156+
def generatedSourcesDir = file("$buildDir/generated/sources/version/java/main")
157+
158+
sourceSets {
159+
main {
160+
java {
161+
srcDirs += generatedSourcesDir
162+
}
163+
}
164+
}
165+
166+
task generateVersionInfo(type: Copy) {
167+
from 'src/main/resources/VersionInfo.java.template'
168+
into generatedSourcesDir
169+
expand(version: project.version)
170+
rename { 'VersionInfo.java' }
171+
}
172+
173+
compileJava.dependsOn generateVersionInfo
174+
175+
tasks.named('sourcesJar') {
176+
dependsOn generateVersionInfo
177+
}

azuremanaged/src/main/java/com/microsoft/durabletask/azuremanaged/DurableTaskSchedulerClientOptions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ public void start(ClientCall.Listener<RespT> responseListener, Metadata headers)
226226
taskHubName
227227
);
228228

229+
headers.put(
230+
Metadata.Key.of("user-agent", Metadata.ASCII_STRING_MARSHALLER),
231+
DurableTaskUserAgentUtil.getUserAgent()
232+
);
233+
229234
// Add authorization token if credentials are configured
230235
if (finalTokenCache != null) {
231236
String token = finalTokenCache.getToken().getToken();

azuremanaged/src/main/java/com/microsoft/durabletask/azuremanaged/DurableTaskSchedulerWorkerOptions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ public void start(ClientCall.Listener<RespT> responseListener, Metadata headers)
235235
taskHubName
236236
);
237237

238+
headers.put(
239+
Metadata.Key.of("user-agent", Metadata.ASCII_STRING_MARSHALLER),
240+
DurableTaskUserAgentUtil.getUserAgent()
241+
);
242+
238243
// Add authorization token if credentials are configured
239244
if (finalTokenCache != null) {
240245
String token = finalTokenCache.getToken().getToken();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.durabletask.azuremanaged;
5+
6+
/**
7+
* Utility class for generating the user agent string for the Durable Task SDK.
8+
*/
9+
public final class DurableTaskUserAgentUtil {
10+
/**
11+
* The name of the SDK used in the user agent string.
12+
*/
13+
private static final String SDK_NAME = "durabletask-java";
14+
15+
private DurableTaskUserAgentUtil() {
16+
// Private constructor to prevent instantiation
17+
}
18+
19+
/**
20+
* Generates the user agent string for the Durable Task SDK based on a fixed name and the package version.
21+
*
22+
* @return The user agent string.
23+
*/
24+
public static String getUserAgent() {
25+
return String.format("%s/%s", SDK_NAME, VersionInfo.VERSION);
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.durabletask.azuremanaged;
5+
6+
/**
7+
* Auto-generated version information for the Durable Task SDK.
8+
* This file is generated during the build process.
9+
*/
10+
public final class VersionInfo {
11+
/**
12+
* The version of the SDK.
13+
*/
14+
public static final String VERSION = "${version}";
15+
16+
private VersionInfo() {
17+
// Private constructor to prevent instantiation
18+
}
19+
}

samples/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
plugins {
22
id 'org.springframework.boot' version '2.5.2'
33
id 'java'
4-
id 'application'
54
}
65

76
group 'io.durabletask'
87
version = '0.1.0'
98
def grpcVersion = '1.59.0'
109
archivesBaseName = 'durabletask-samples'
1110

12-
application {
11+
bootJar {
12+
mainClass = 'io.durabletask.samples.WebApplication'
13+
}
14+
15+
task runWebAppToDurableTaskSchedulerSample(type: JavaExec) {
16+
classpath = sourceSets.main.runtimeClasspath
1317
mainClass = 'io.durabletask.samples.WebAppToDurableTaskSchedulerSample'
1418
}
1519

0 commit comments

Comments
 (0)