diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index c7b367340..02a328912 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -8,8 +8,24 @@ on: - feature/v2 pull_request: types: [opened, synchronize, reopened] + +env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + jobs: + checksecret: + name: check if SONAR_TOKEN is set in github secrets + runs-on: ubuntu-latest + outputs: + is_SONAR_TOKEN_set: ${{ steps.checksecret_job.outputs.is_SONAR_TOKEN_set }} + steps: + - name: Check whether unity activation requests should be done + id: checksecret_job + run: | + echo "is_SONAR_TOKEN_set=${{ env.SONAR_TOKEN != '' }}" >> $GITHUB_OUTPUT build: + needs: [checksecret] + if: needs.checksecret.outputs.is_SONAR_TOKEN_set == 'true' name: Build runs-on: ubuntu-latest steps: @@ -37,5 +53,4 @@ jobs: - name: Build and analyze env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: ./gradlew build sonarqube --info diff --git a/CHANGELOG.md b/CHANGELOG.md index 27061f84c..b040e5bcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +### Changed + +## [2.0.21] - 2023-11-08 + +### Changed + +- Changed CoreHttpProvider dependency from OkHttpClient to Call.Factory (parent interface implemented by OkHttpClient). This make usage of OpenTelemetry tracing possible. + https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/okhttp/okhttp-3.0/library/README.md + +```java + private Call.Factory createTracedClient(OpenTelemetry openTelemetry, @Nonnull final IAuthenticationProvider auth) { + return OkHttpTelemetry.builder(openTelemetry).build().newCallFactory(createClient(auth)); + } + + private OkHttpClient createClient(@Nonnull final IAuthenticationProvider auth) { + return HttpClients.createDefault(auth); + } + + // then create the GraphServiceClient + IAuthenticationProvider authenticationProvider = ...; + GraphServiceClient + .builder(Call.Factory.class, Request.class) + .httpClient(createTracedClient(openTelemetry, authenticationProvider)) + .authenticationProvider(authenticationProvider) + .buildClient(); +``` + ## [2.0.20] - 2023-10-23 ### Changed diff --git a/gradle.properties b/gradle.properties index c270067b9..11030eaf9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph mavenArtifactId = microsoft-graph-core mavenMajorVersion = 2 mavenMinorVersion = 0 -mavenPatchVersion = 20 +mavenPatchVersion = 21 mavenArtifactSuffix = #These values are used to run functional tests diff --git a/src/main/java/com/microsoft/graph/core/BaseClient.java b/src/main/java/com/microsoft/graph/core/BaseClient.java index cbdbac4e7..27382a382 100644 --- a/src/main/java/com/microsoft/graph/core/BaseClient.java +++ b/src/main/java/com/microsoft/graph/core/BaseClient.java @@ -41,6 +41,7 @@ import javax.annotation.Nonnull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import okhttp3.Call; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -185,7 +186,7 @@ private httpClientType getHttpClient() { @SuppressWarnings("unchecked") private IHttpProvider getHttpProvider() { if(httpProvider == null) { - return (IHttpProvider)new CoreHttpProvider(getSerializer(), getLogger(), (OkHttpClient)getHttpClient()); + return (IHttpProvider)new CoreHttpProvider(getSerializer(), getLogger(), (Call.Factory) getHttpClient()); } else { return httpProvider; } diff --git a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java index 7dea22c18..31f357643 100644 --- a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java +++ b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java @@ -98,9 +98,9 @@ public class CoreHttpProvider implements IHttpProvider { private final ILogger logger; /** - * The OkHttpClient that handles all requests + * The OkHttpClient(Call.Factory) that handles all requests */ - private OkHttpClient corehttpClient; + private Call.Factory corehttpClient; /** * Creates the CoreHttpProvider @@ -112,7 +112,7 @@ public class CoreHttpProvider implements IHttpProvider { @SuppressFBWarnings public CoreHttpProvider(@Nonnull final ISerializer serializer, @Nonnull final ILogger logger, - @Nonnull final OkHttpClient httpClient) { + @Nonnull final Call.Factory httpClient) { Objects.requireNonNull(logger, "parameter logger cannot be null"); Objects.requireNonNull(serializer, "parameter serializer cannot be null"); Objects.requireNonNull(httpClient, "parameter httpClient cannot be null");