Skip to content

Handle sigterm better in instrumentation - #16631

Open
aug24 wants to merge 9 commits into
mainfrom
ac/jr/handle-sigterm-better-in-instrumentation
Open

Handle sigterm better in instrumentation#16631
aug24 wants to merge 9 commits into
mainfrom
ac/jr/handle-sigterm-better-in-instrumentation

Conversation

@aug24

@aug24 aug24 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What does this change?

First iteration on the original instrumentation is to handle SIGTERM in the instrumentation without closing the process.

Why?

The instrumentation should not be making actions which affect the main process.

How has this change been tested?

Screenshots

Before After
before after

@aug24
aug24 requested a review from a team as a code owner August 27, 2026 15:33
@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.

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

🚀 Image pushed to AWS ECR

Image digest: sha256:ff635656400e162bdf373b065d6202b75be18cd027e271d0ceb940e31100b0d5

🐛 Run the image locally

The following can be used to run the image locally:

# Refer to image using the immutable digest. Find alternatives below.
IMAGE_IDENTIFIER="@sha256:ff635656400e162bdf373b065d6202b75be18cd027e271d0ceb940e31100b0d5"

# Refer to image using branch tag
# IMAGE_IDENTIFIER=":branch-ac-jr-handle-sigterm-better-in-instrumentation"

# Refer to image using build tag
# IMAGE_IDENTIFIER=":build-30721"

# Refer to image via the GitHub commit SHA tag
# IMAGE_IDENTIFIER=":sha-b30ca953d77a6fe1e10c02e34c5519cf29ba34ef"

# Set environment variables for the AWS CLI
AWS_PROFILE="<A_PROFILE_FROM_JANUS>"
AWS_DEFAULT_REGION="eu-west-1"

IMAGE_ACCOUNT_ID=$(aws ssm get-parameter --name /organisation/accounts/deployTools --query "Parameter.Value" --output text)
REGISTRY="${IMAGE_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
IMAGE="${REGISTRY}/guardian/dotcom-rendering${IMAGE_IDENTIFIER}"

# Login to AWS ECR https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html
aws ecr get-login-password | docker login --username AWS --password-stdin $REGISTRY

# Pull the image
docker pull $IMAGE

# Run the image. You'll likely need to set additional flags. See https://docs.docker.com/reference/cli/docker/container/run.
docker run $IMAGE

From guardian/actions-publish-image.

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

@aug24
aug24 force-pushed the ac/jr/handle-sigterm-better-in-instrumentation branch from 7ff26c7 to d21039b Compare August 28, 2026 11:56
@aug24 aug24 added the feature Departmental tracking: work on a new feature label Aug 28, 2026
@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

@aug24 aug24 added dotcom-rendering run_chromatic Runs chromatic when label is applied labels Aug 28, 2026
@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label Aug 28, 2026

// Instrumentation is preloaded into the same process as the app server.
// It should react to process SIGTERM, but not own process/server lifecycle.
let shutdownPromise: Promise<void> | null = null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why null over undefined here?

@aug24 aug24 Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd consider null to be correct here. It's not that it's never been defined, it's that it is currently explicitly not (yet) set.

null is more like None.

If fetched using `aws xray batch-get-traces`, the trace document will contain a `Segment` field, which contains a
`Document` field. The `Document` field is a JSON string containing the trace data we want.

An example CLI request to view a single trace document as json is:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor: Would the DX of using xray improve if we add it to Grafana?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes - but that should be a job for another ticket, and might be worth discussing for cost reasons. There's a lot of data.

"throttle": false,
"http": {
"request": {
"url": "http://tag-page-rendering-jr.local.dev-gutools.co.uk/Article",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this domain correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not supposed to be prod or code data. It's representative.

@aug24 aug24 added the run_chromatic Runs chromatic when label is applied label Sep 1, 2026
@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label Sep 1, 2026
return shutdownPromise;
};

process.on('SIGTERM', () => {

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.

I could use more context to be able to review this change. Can you share a bit more about the thinking behind it? Is it a response to #16595 (comment) ?

A bit a context from my side. Originally I didn't add this SIGTERM handling as it's not in these docs https://opentelemetry.io/docs/languages/js/getting-started/nodejs/. I ended up adding it because I found it in https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-sdk-node/README.md . Truth be told I didn't think about it with much depth!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is in response to that comment. Then a bit of a discuss.

The instrumentation should take care of closing down the instrumentation. It would be a behavioural change for it to terminate the whole process. I'm not sure if anything in the server responds to sigterm at all, but whatever we currently do should not change here.

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

Labels

dotcom-rendering feature Departmental tracking: work on a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants