Repository navigation
Description
Jenkins and plugins versions report
Environment
Jenkins: 2.504.3 (jenkins-test-harness, from the plugin's pom)
Java: 21.0.8 (Azul Zulu) and 25.0.5 (Eclipse Temurin)
---
github: master at 64a8675 (v1.47.0 plus two commits)
github-api: 1.330-492.v3941a_032db_2a_ (org.kohsuke:github-api 1.330)
okhttp-api: 4.12.0-195.vc02552c04ffd (OkHttp 4.12.0)
OpenTelemetry Java agent: 2.33.1
First seen on a CloudBees CI controller with the same agent version.
What Operating System are you using (both controller, and any agents involved in the problem)?
Linux controller (Kubernetes). Reproduced on macOS. It doesn't depend on the OS.
Reproduction steps
Smallest reproduction, with github-api 1.330 and the connector that GitHubLoginFunction uses:
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(chain -> {
System.out.println("interceptor saw " + chain.request().url());
return chain.proceed(chain.request());
})
.build();
GitHub github = new GitHubBuilder().withConnector(new OkHttpConnector(client)).build();
github.getRepository("jenkinsci/github-plugin");In Jenkins, with the OpenTelemetry Java agent:
- Start Jenkins with
-javaagent:opentelemetry-javaagent.jar -Dotel.instrumentation.common.default-enabled=false -Dotel.instrumentation.okhttp.enabled=true -Dotel.metrics.exporter=logging -Dotel.traces.exporter=none -Dotel.logs.exporter=none. - Add a GitHub server in Manage Jenkins > System > GitHub and click Test connection. Or let the plugin call GitHub another way: set a commit status, or manage hooks.
- Look for
http.client.request.durationwithserver.address=api.github.comin the agent's metric output.
Expected Results
The interceptor runs. The agent records the plugin's GitHub API calls like any other OkHttp call.
Actual Results
The interceptor never runs. The agent records nothing for the GitHub clients that GitHubLoginFunction creates (GitHubServerConfig.loginToGithub(), the cached clients of the configured servers, Test connection).
GitHubLoginFunction.connector returns the deprecated OkHttpConnector (GitHubLoginFunction.java#L119). It sends each request through github-api's ObsoleteUrlFactory, whose buildCall() clears the client's interceptors and network interceptors on every request (ObsoleteUrlFactory.java#L620-L626).
Anything else?
- github-api won't change
ObsoleteUrlFactory. ObsoleteUrlFactory overrides OkHttpClient’s interceptors hub4j/github-api#1262 reported the same thing in 2021 and was closed with "If you are usingOkHttpConnectorswitch toOkHttpGitHubConnector." - github-api 2.0 removes
OkHttpConnectorandObsoleteUrlFactory(hub4j/github-api@048b84b; neither is in 2.0-rc.7).OkHttpGitHubConnectorstays, so the plugin needs this switch for 2.0 anyway. - GitHub Branch Source has the same problem: GitHub API calls skip OkHttp interceptors, so the OpenTelemetry Java agent records none github-branch-source-plugin#1575.
Are you interested in contributing a fix?
Yes. I'll open a pull request that switches GitHubLoginFunction to OkHttpGitHubConnector, with tests.
Activity