Skip to content

Conversation

@anthonyshull
Copy link
Contributor

@anthonyshull anthonyshull commented Aug 5, 2025

You can add a decorator to any function. That function will then be tracked for usage. Works for public and private functions.

@decorate track()
def foo, do: nil

You can also track all functions in a module.

@decorate_all track()

Visit the dashboard at /dashboard/usage and you'll see all tracked functions that haven't been called since the last deployment.

@moduledoc "Behavior for mode hub pages."

use DotcomWeb, :controller
use Dotcom.Gettext.Sigils
Copy link
Contributor Author

@anthonyshull anthonyshull Aug 5, 2025

Choose a reason for hiding this comment

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

📓 I just moved what was in DotcomWeb, :controller into this module because it broke when trying to add the decorator. I have no idea what this module does, but it looks old.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The mode hub pages are /schedules/(bus|ferry|commuter-rail|subway), each using a separate controller which implements this behavior!

RUN apk add libssl3

COPY --from=builder /home/_build /home/_build
COPY --from=builder /tmp/.functions /tmp/.functions
Copy link
Contributor Author

Choose a reason for hiding this comment

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

📓 We have to build the list of functions at compile time. We use the file in the tmp directory so that it survives the image build process.

@anthonyshull anthonyshull marked this pull request as ready for review August 5, 2025 20:31
@anthonyshull anthonyshull requested a review from a team as a code owner August 5, 2025 20:31
dont track on test

run hourly

gettext

change from logging to live dashboard

dont count hits

remove config

simplify

docs

add some more info

track function use with a decorator

small changes

format

docs and cleanup

use priv

delete, create, and modify file

dont use priv

try a non hidden file

use tmp dir

controllers

gettext extract

only include in non test envs

revert pot

extract

full extract

revert pot
Inside of the `quote`, we tell the agent to remove the registered function.
"""
def track(body, context) do
write_context!(context)
Copy link
Contributor Author

@anthonyshull anthonyshull Aug 7, 2025

Choose a reason for hiding this comment

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

📓 This is run at compile time. It adds the function information to a file.

write_context!(context)

quote do
DotcomWeb.Usage.Functions.remove_context([
Copy link
Contributor Author

@anthonyshull anthonyshull Aug 7, 2025

Choose a reason for hiding this comment

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

📓 This is run when the function is executed. It removes the function from the list of all tracked functions.

Copy link
Collaborator

@thecristen thecristen left a comment

Choose a reason for hiding this comment

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

at least on dev-blue it looks like it works great!

|> CSV.decode!(headers: false)
|> Enum.to_list()
|> Enum.reduce(%{}, fn identifier, acc ->
Map.put(acc, :erlang.phash2(identifier), identifier)
Copy link
Collaborator

Choose a reason for hiding this comment

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

hashing feels unnecessary here and I'm scarred from that one time we ran into a duplicate hash 😆

@anthonyshull anthonyshull merged commit d293d40 into main Aug 7, 2025
28 checks passed
@anthonyshull anthonyshull deleted the ags/function-tracker branch August 7, 2025 17:35
@thecristen thecristen removed the dev-blue Deploy to dev-blue label Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants