Skip to content

Instrument Twirl template with a java agent#28895

Merged
alexduf merged 2 commits into
mainfrom
adu-instrumentation-poc
Jul 8, 2026
Merged

Instrument Twirl template with a java agent#28895
alexduf merged 2 commits into
mainfrom
adu-instrumentation-poc

Conversation

@alexduf

@alexduf alexduf commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

See #28909 and #28894

This was coded with the help of Opus 4.8. I don't think I could have cooked it this quick otherwise.

What is the value of this and can you measure success?

Can we measure which twirl template is being used in production? if so: success.

What does this change?

Instrument production artefacts at runtime in order to detect which twirl templates truly are used in a live environment. The instrumentation writes a json log line in a separate file each time a new template is encountered.

The logging implementation is voluntarily naive, it's inefficient but it's a trade-off for simplicity that I'm willing to accept because:

  • the number of log lines is going to be very small (< 200)
  • it will only be slowing down the first few requests
  • keeping this code as simple as technically feasible is key for maintainability

As of now this is only applied to the discussion service, and it will be generalised in this ticket

Screenshots

root@ip-10-0-1-41:/home/discussion/logs# tail -n10000 -f twirl-usage.log
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.discussionComments.discussionPage", "timestamp":"2026-07-03T08:57:23.164191162Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.comment", "timestamp":"2026-07-03T08:57:23.280691371Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.inlineSvg", "timestamp":"2026-07-03T08:57:23.317208482Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.commentBadges", "timestamp":"2026-07-03T08:57:23.451675149Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.commentPagination", "timestamp":"2026-07-03T08:57:23.808396215Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.pagination", "timestamp":"2026-07-03T08:57:23.83499089Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.reportComment", "timestamp":"2026-07-03T08:57:23.856467665Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.recommendationTooltip", "timestamp":"2026-07-03T08:57:23.872501405Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.mainLegacy", "timestamp":"2026-07-03T08:57:23.876149815Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.main", "timestamp":"2026-07-03T08:57:23.900311874Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.head", "timestamp":"2026-07-03T08:57:23.926315961Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.metaData", "timestamp":"2026-07-03T08:57:23.972617671Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.stylesheets", "timestamp":"2026-07-03T08:57:24.207628616Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.fontFaces", "timestamp":"2026-07-03T08:57:24.22786444Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.stylesheetLink", "timestamp":"2026-07-03T08:57:24.249071521Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.page.head.fixIEReferenceErrors", "timestamp":"2026-07-03T08:57:24.283257482Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.page.head.checkModuleSupport", "timestamp":"2026-07-03T08:57:24.299675049Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.inlineJSBlocking", "timestamp":"2026-07-03T08:57:24.32102723Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.commercial.topBanner", "timestamp":"2026-07-03T08:57:25.785808864Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.commercial.standardAd", "timestamp":"2026-07-03T08:57:25.81496349Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.commercial.adSlot", "timestamp":"2026-07-03T08:57:25.853580442Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.header", "timestamp":"2026-07-03T08:57:25.872392544Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.nav.userAccountDropdown", "timestamp":"2026-07-03T08:57:25.925532721Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.nav.editionPickerDropdown", "timestamp":"2026-07-03T08:57:25.953651679Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.nav.headerMenu", "timestamp":"2026-07-03T08:57:25.970834776Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.nav.editionPicker", "timestamp":"2026-07-03T08:57:26.052853344Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.nav.subNav", "timestamp":"2026-07-03T08:57:26.084050579Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.footer", "timestamp":"2026-07-03T08:57:26.11388966Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.email.signup.emailFooterLink", "timestamp":"2026-07-03T08:57:26.14095677Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.message", "timestamp":"2026-07-03T08:57:26.196277385Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.inlineJSNonBlocking", "timestamp":"2026-07-03T08:57:26.215546915Z[Etc/UTC]"}
{"marker":"TEMPLATE_FIRST_SEEN","template":"views.html.fragments.analytics.base", "timestamp":"2026-07-03T08:57:26.361353019Z[Etc/UTC]"}

Checklist

@alexduf alexduf added the maintenance Departmental tracking: maintenance work, not a fix or a feature label Jun 29, 2026
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@alexduf alexduf force-pushed the adu-instrumentation-poc branch 2 times, most recently from 166ec20 to de4a547 Compare June 30, 2026 09:04
This was coded with the help of Opus 4.8
@alexduf alexduf force-pushed the adu-instrumentation-poc branch from de4a547 to 2eebc6e Compare July 2, 2026 15:44
@alexduf alexduf changed the title Implement a PoC jvm agent Instrument Twirl template with a java agent Jul 2, 2026
@alexduf alexduf force-pushed the adu-instrumentation-poc branch 2 times, most recently from ff94120 to c1d12ab Compare July 3, 2026 08:17
@alexduf alexduf force-pushed the adu-instrumentation-poc branch 4 times, most recently from 55a982a to 55d8a0f Compare July 3, 2026 12:36
@alexduf

alexduf commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

I've also tested adding a "decoy" twirl template hidden behind an impossible condition (1+1 == 3) just to ensure that its name would not appear in the list (which would mean appearing simply for being referenced rather than executed). The test is conclusive.

@alexduf alexduf marked this pull request as ready for review July 3, 2026 12:37
@alexduf alexduf requested a review from a team as a code owner July 3, 2026 12:37
@alexduf alexduf merged commit 79281fd into main Jul 8, 2026
16 checks passed
@alexduf alexduf deleted the adu-instrumentation-poc branch July 8, 2026 07:14
@gu-prout

gu-prout Bot commented Jul 8, 2026

Copy link
Copy Markdown

Seen on ADMIN-PROD (merged by @alexduf 9 minutes and 10 seconds ago)

@gu-prout

gu-prout Bot commented Jul 8, 2026

Copy link
Copy Markdown

Seen on FRONTS-PROD (merged by @alexduf 9 minutes and 17 seconds ago)

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

Labels

maintenance Departmental tracking: maintenance work, not a fix or a feature Seen-on-ADMIN-PROD Seen-on-FRONTS-PROD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the agent on a single service Prototype code instrumentation

2 participants