Skip to content

adding and passing logMarkers to (almost) all logging in media-api#4529

Merged
andrew-nowak merged 1 commit intomainfrom
an/media-api-log-markers
Sep 29, 2025
Merged

adding and passing logMarkers to (almost) all logging in media-api#4529
andrew-nowak merged 1 commit intomainfrom
an/media-api-log-markers

Conversation

@andrew-nowak
Copy link
Copy Markdown
Member

What does this change?

One of my occasional passes through a service, setting up better log markers and passing them to all the log statements that I can find. This time focusing on media-api.

(Of passing interest here, play does have an internal request-id, but it's a monotonically increasing integer starting from 1 for each instance, which means that those request-ids will be non-unique which isn't helpful for us :( BUT we should follow playframework/playframework#10273 where these may be switched to UUIDv7 in the future!)

How should a reviewer test this change?

Deploy to TEST and perform some interactions with media-api (searches, retrieving a single image, etc.). Is there a stable request ID, allowing you to find all the log messages associated with this request?

How can success be measured?

Who should look at this?

Tested? Documented?

  • locally by committer
  • locally by Guardian reviewer
  • on the Guardian's TEST environment
  • relevant documentation added or amended (if needed)

@andrew-nowak andrew-nowak requested a review from a team as a code owner September 23, 2025 17:03
Copy link
Copy Markdown
Contributor

@twrichards twrichards left a comment

Choose a reason for hiding this comment

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

brilliant stuff @andrew-nowak
code looks 👍
(I haven't tested on TEST, but I trust you have 🙏 )

elasticSearch.getImageById(id) flatMap {
case Some(image) if hasPermission(request.user, image) => {
val apiKey = request.user.accessor
logger.info(s"Download optimised image: $id from user: ${Authentication.getIdentity(request.user)}", apiKey, id)
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.

🫨 - was apiKey actually getting logged??

"user" -> r.user.accessor.identity
)
"requestId" -> RequestLoggingFilter.getRequestId(request)
) ++ RequestLoggingFilter.loggablePrincipal(request.user)
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.

😍

@gu-prout
Copy link
Copy Markdown

gu-prout Bot commented Sep 29, 2025

Seen on auth, usage, image-loader, metadata-editor, thrall, leases, cropper, collections, media-api, kahuna (merged by @andrew-nowak 8 minutes and 40 seconds ago) Please check your changes!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants