Skip to content

feat: Add headers to understand who responded#16384

Merged
akash1810 merged 4 commits into
mainfrom
aa/response-header
Jul 16, 2026
Merged

feat: Add headers to understand who responded#16384
akash1810 merged 4 commits into
mainfrom
aa/response-header

Conversation

@akash1810

@akash1810 akash1810 commented Jul 15, 2026

Copy link
Copy Markdown
Member

What does this change?

This change adds two headers to each response:

  • X-Gu-Backend-App which represents which app is running (tag-page-rendering, article-rendering, etc.)
  • X-Gu-Backend-App-Target-Group which represents which target group served the request (EC2 or ECS)

One use-case for this is in the "run DCR on ECS" project (see also #16321).

This is similar to guardian/frontend.

X-Gu-Backend-App is already removed for reader requests within Fastly. X-Gu-Backend-App-Target-Group is removed in https://github.com/guardian/fastly-edge-cache/pull/1199.

Why?

As part of @guardian/devx-reliability-and-ops's project to run DCR on AWS, we'll be splitting traffic between the current EC2 target group and the new ECS target group. This header helps to distinguish what infrastructure responded.

How has this change been tested?

After deploying to CODE and following the steps listed in #16377, we can see the new headers:

curl -s "https://www.theguardian.com/tone/minutebyminute.json?dcr=true" | \
  curl -s -X POST https://tag-page-rendering.code.dev-guardianapis.com/TagPage \
    -H "Content-Type: application/json" \
    -d @- -D - -o /dev/null

HTTP/2 200
date: Wed, 15 Jul 2026 10:13:41 GMT
content-type: text/html; charset=utf-8
content-length: 365212
x-gu-backend-app: tag-page-rendering
x-gu-backend-app-target-group: ec2
x-powered-by: Express
link: <https://assets.guim.co.uk/polyfill.io/v3/polyfill.min.js?rum=0&features=es6%2Ces7%2Ces2017%2Ces2018%2Ces2019%2Cdefault-3.6%2CHTMLPictureElement%2CIntersectionObserver%2CIntersectionObserverEntry%2CURLSearchParams%2Cfetch%2CNodeList.prototype.forEach%2Cnavigator.sendBeacon%2Cperformance.now%2CPromise.allSettled&flags=gated&callback=guardianPolyfilled&unknown=polyfill&cacheClear=1>; rel=prefetch,<https://assets-code.guim.co.uk/assets/frameworks.client.web.6b19980dfdb962b2f0d0.js>; rel=prefetch,<https://assets-code.guim.co.uk/assets/index.client.web.b98149db4bc4f45b7f3c.js>; rel=prefetch,<https://assets.guim.co.uk/commercial/454fa0f267b7fb516298/graun.standalone.commercial.js>; rel=prefetch,
etag: W/"5929c-f+HFJg+uAM7mWBRL5skzmVOMj+Q"
vary: Accept-Encoding

@akash1810 akash1810 added the feature Departmental tracking: work on a new feature label Jul 15, 2026
@akash1810
akash1810 requested a review from a team as a code owner July 15, 2026 09:01
@github-actions

Copy link
Copy Markdown

Hello 👋! When you're ready to run Chromatic, please apply the run_chromatic label to this PR.

You will need to reapply the label each time you want to run Chromatic.

Click here to see the Chromatic project.

@akash1810
akash1810 force-pushed the aa/response-header branch from 9a64caa to bddbffc Compare July 15, 2026 09:23
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

@akash1810 akash1810 added the run_chromatic Runs chromatic when label is applied label Jul 15, 2026
@akash1810 akash1810 changed the title feat: Add a response header to understand who responded feat: Add a header to understand who responded Jul 15, 2026
@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label Jul 15, 2026
@akash1810
akash1810 force-pushed the aa/response-header branch 2 times, most recently from 1b99e65 to 1d85b94 Compare July 15, 2026 13:27
Comment thread dotcom-rendering/src/server/server.dev.ts Outdated
Comment thread dotcom-rendering/src/server/server.prod.ts Outdated
@akash1810
akash1810 requested a review from arelra July 15, 2026 14:01
@akash1810 akash1810 changed the title feat: Add a header to understand who responded feat: Add headers to understand who responded Jul 15, 2026
@akash1810
akash1810 force-pushed the aa/response-header branch 2 times, most recently from 0f02936 to 127c7a2 Compare July 15, 2026 14:19
@akash1810
akash1810 requested a review from Copilot July 15, 2026 15:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a reusable Express middleware to stamp responses with backend-identification headers so downstream tooling can tell which DCR app and which infrastructure target group (EC2 vs ECS) served a request. This supports traffic-splitting/verification work (e.g., ECS rollout) by making the responder visible in each HTTP response.

Changes:

  • Introduce responseHeaderMiddleware that sets X-Gu-Backend-App and X-Gu-Backend-App-Target-Group.
  • Register the middleware in both production and development servers so headers are applied to responses.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
dotcom-rendering/src/server/server.prod.ts Registers the new response-header middleware for prod server responses.
dotcom-rendering/src/server/server.dev.ts Registers the new response-header middleware for dev renderer routes.
dotcom-rendering/src/server/lib/header-middleware.ts Implements the middleware and environment-derived header values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dotcom-rendering/src/server/lib/header-middleware.ts Outdated
Comment thread dotcom-rendering/src/server/lib/header-middleware.ts
@akash1810
akash1810 force-pushed the aa/response-header branch from b846f91 to 8a0393c Compare July 16, 2026 08:03
Comment thread dotcom-rendering/src/server/lib/header-middleware.ts Outdated
@akash1810
akash1810 force-pushed the aa/response-header branch 2 times, most recently from 7d762ad to d432382 Compare July 16, 2026 11:38
akash1810 and others added 4 commits July 16, 2026 12:53
This change adds two headers to each response:
- `X-Gu-Backend-App` which represents which app is running (tag-page-rendering, article-rendering, etc.)
- `X-Gu-Backend-App-Target-Group` which represents which target group served the request (EC2 or ECS)

One use-case for this is in the "run DCR on ECS" project.

This is similar to `guardian/frontend`, see https://github.com/guardian/frontend/blob/0cbc1c8448d6afb74eab75903b16a224fbcf1114/common/app/http/Filters.scala#L49-L62.
Other places in the repository fallback to "rendering".

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@akash1810
akash1810 force-pushed the aa/response-header branch from d432382 to 43ec374 Compare July 16, 2026 11:53
@akash1810 akash1810 added the run_chromatic Runs chromatic when label is applied label Jul 16, 2026
@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label Jul 16, 2026
@akash1810
akash1810 merged commit 82c2848 into main Jul 16, 2026
36 checks passed
@akash1810
akash1810 deleted the aa/response-header branch July 16, 2026 12:04
@gu-prout

gu-prout Bot commented Jul 16, 2026

Copy link
Copy Markdown

Seen on PROD (merged by @akash1810 13 minutes and 24 seconds ago) Please check your changes!

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

Labels

feature Departmental tracking: work on a new feature Seen-on-PROD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants