-
Notifications
You must be signed in to change notification settings - Fork 16
Tracks functions by way of a decorator #2682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| @moduledoc "Behavior for mode hub pages." | ||
|
|
||
| use DotcomWeb, :controller | ||
| use Dotcom.Gettext.Sigils |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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
f643144 to
ea41534
Compare
| Inside of the `quote`, we tell the agent to remove the registered function. | ||
| """ | ||
| def track(body, context) do | ||
| write_context!(context) |
There was a problem hiding this comment.
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([ |
There was a problem hiding this comment.
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.
thecristen
left a comment
There was a problem hiding this 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) |
There was a problem hiding this comment.
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 😆
You can add a decorator to any function. That function will then be tracked for usage. Works for public and private functions.
You can also track all functions in a module.
Visit the dashboard at
/dashboard/usageand you'll see all tracked functions that haven't been called since the last deployment.