Add correlation id header to outgoing requests

What does this MR do?

Add a correlation id header to outgoing requests

  • The correlation ID is used to track the request and response cycle, but we are relying on the correlation ID from the response In a case where the response never reaches the runner from the backend we have no way to track where the request was lost through the logs.

Local testing confirms that if a correlation ID is set in the request, it will be used by the backend, but in case a new one is generated on the backend, we will use it in our logging, and if empty, we will use the one from the request.

* [HTTP/2] [1] OPENED stream for https://gitlab.com/api/v4/jobs/request
* [HTTP/2] [1] [:method: POST]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: gitlab.com]
* [HTTP/2] [1] [:path: /api/v4/jobs/request]
* [HTTP/2] [1] [user-agent: curl/8.7.1]
* [HTTP/2] [1] [accept: */*]
* [HTTP/2] [1] [x-request-id: random string]
> POST /api/v4/jobs/request HTTP/2
> Host: gitlab.com
> User-Agent: curl/8.7.1
> Accept: */*
> X-Request-ID: random string
> 
* Request completely sent off
< HTTP/2 400 
< date: Sat, 26 Jul 2025 04:05:31 GMT
< content-type: application/json
< content-length: 28
< cf-ray: 965104e7a9ee566e-EWR
< cf-cache-status: DYNAMIC
< cache-control: no-cache
< strict-transport-security: max-age=31536000
< vary: Origin
< content-security-policy: default-src 'none'
< gitlab-ci-builds-polling: yes
< gitlab-lb: haproxy-main-47-lb-gprd
< gitlab-sv: api-gke-us-east1-c
< nel: {"max_age": 0}
< referrer-policy: strict-origin-when-cross-origin
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-gitlab-meta: {"correlation_id":"randomstring","version":"1"}
< x-request-id: randomstring

Here the logs where we got an error response from the backend, but no correlation ID, making it difficult to trace the request on the backend.

Why was this MR needed?

To increase the traceability of a request made by the runner.

What's the best way to test this MR?

go run . run to see active logs and go test ./network/... to test changes.

What are the relevant issue numbers?

#4285 (closed)

Merge request reports

Loading