Skip to content

Commit 43eba0b

Browse files
authored
Merge pull request #1252 from cbos/prepare_for_opentelemetry
Use parent Call.Factory of OkHttpClient to be able to use OpenTelemetry
2 parents 87f33b9 + 1dfcdb3 commit 43eba0b

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,24 @@ on:
88
- feature/v2
99
pull_request:
1010
types: [opened, synchronize, reopened]
11+
12+
env:
13+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
14+
1115
jobs:
16+
checksecret:
17+
name: check if SONAR_TOKEN is set in github secrets
18+
runs-on: ubuntu-latest
19+
outputs:
20+
is_SONAR_TOKEN_set: ${{ steps.checksecret_job.outputs.is_SONAR_TOKEN_set }}
21+
steps:
22+
- name: Check whether unity activation requests should be done
23+
id: checksecret_job
24+
run: |
25+
echo "is_SONAR_TOKEN_set=${{ env.SONAR_TOKEN != '' }}" >> $GITHUB_OUTPUT
1226
build:
27+
needs: [checksecret]
28+
if: needs.checksecret.outputs.is_SONAR_TOKEN_set == 'true'
1329
name: Build
1430
runs-on: ubuntu-latest
1531
steps:
@@ -37,5 +53,4 @@ jobs:
3753
- name: Build and analyze
3854
env:
3955
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
40-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4156
run: ./gradlew build sonarqube --info

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
### Changed
13+
14+
## [2.0.21] - 2023-11-08
15+
16+
### Changed
17+
18+
- Changed CoreHttpProvider dependency from OkHttpClient to Call.Factory (parent interface implemented by OkHttpClient). This make usage of OpenTelemetry tracing possible.
19+
https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/okhttp/okhttp-3.0/library/README.md
20+
21+
```java
22+
private Call.Factory createTracedClient(OpenTelemetry openTelemetry, @Nonnull final IAuthenticationProvider auth) {
23+
return OkHttpTelemetry.builder(openTelemetry).build().newCallFactory(createClient(auth));
24+
}
25+
26+
private OkHttpClient createClient(@Nonnull final IAuthenticationProvider auth) {
27+
return HttpClients.createDefault(auth);
28+
}
29+
30+
// then create the GraphServiceClient
31+
IAuthenticationProvider authenticationProvider = ...;
32+
GraphServiceClient
33+
.builder(Call.Factory.class, Request.class)
34+
.httpClient(createTracedClient(openTelemetry, authenticationProvider))
35+
.authenticationProvider(authenticationProvider)
36+
.buildClient();
37+
```
38+
1239
## [2.0.20] - 2023-10-23
1340

1441
### Changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph
2525
mavenArtifactId = microsoft-graph-core
2626
mavenMajorVersion = 2
2727
mavenMinorVersion = 0
28-
mavenPatchVersion = 20
28+
mavenPatchVersion = 21
2929
mavenArtifactSuffix =
3030

3131
#These values are used to run functional tests

src/main/java/com/microsoft/graph/core/BaseClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.annotation.Nonnull;
4242

4343
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
44+
import okhttp3.Call;
4445
import okhttp3.OkHttpClient;
4546
import okhttp3.Request;
4647

@@ -185,7 +186,7 @@ private httpClientType getHttpClient() {
185186
@SuppressWarnings("unchecked")
186187
private IHttpProvider<nativeRequestType> getHttpProvider() {
187188
if(httpProvider == null) {
188-
return (IHttpProvider<nativeRequestType>)new CoreHttpProvider(getSerializer(), getLogger(), (OkHttpClient)getHttpClient());
189+
return (IHttpProvider<nativeRequestType>)new CoreHttpProvider(getSerializer(), getLogger(), (Call.Factory) getHttpClient());
189190
} else {
190191
return httpProvider;
191192
}

src/main/java/com/microsoft/graph/http/CoreHttpProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public class CoreHttpProvider implements IHttpProvider<Request> {
9898
private final ILogger logger;
9999

100100
/**
101-
* The OkHttpClient that handles all requests
101+
* The OkHttpClient(Call.Factory) that handles all requests
102102
*/
103-
private OkHttpClient corehttpClient;
103+
private Call.Factory corehttpClient;
104104

105105
/**
106106
* Creates the CoreHttpProvider
@@ -112,7 +112,7 @@ public class CoreHttpProvider implements IHttpProvider<Request> {
112112
@SuppressFBWarnings
113113
public CoreHttpProvider(@Nonnull final ISerializer serializer,
114114
@Nonnull final ILogger logger,
115-
@Nonnull final OkHttpClient httpClient) {
115+
@Nonnull final Call.Factory httpClient) {
116116
Objects.requireNonNull(logger, "parameter logger cannot be null");
117117
Objects.requireNonNull(serializer, "parameter serializer cannot be null");
118118
Objects.requireNonNull(httpClient, "parameter httpClient cannot be null");

0 commit comments

Comments
 (0)