Skip to content

GitHub API calls skip OkHttp interceptors, so the OpenTelemetry Java agent records none #799

Closed

Description

@NoamGoren

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:

  1. 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.
  2. 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.
  3. Look for http.client.request.duration with server.address=api.github.com in 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?

Are you interested in contributing a fix?

Yes. I'll open a pull request that switches GitHubLoginFunction to OkHttpGitHubConnector, with tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions