Generate documents(wiki) for Telemetry pings automatically
It's pain to align Telemetry Pings (UI pings especially) in the wiki page and the TelemetryEvent.create() calls in TelemetryWrapper class. Can we automate it? Or even create commit/pr for the change automatically?
I don't familiar with Java annotation processing. But I think this may be a good use case for it.
It'll be great if we can
- Just adding annotations on current code (without rewriting anything) and generate the doc from there.. or
- Find a new way to write Telemetry pings ( This is less sexy)
For 1. The worse case is to add (redundant) attributes (action, method, object..etc) in annotations and generate the doc from there(like JavaDoc). The best is we can let the processor find out all the elements (function params in TelemetryEvent.create )automatically(similar to @CheckForReshult ).
Again I'm a super newbie in annotation processing, so anyone is free to make this happen. I'll also use my personal time to study it.
┆Issue is synchronized with this Jira Task
Some time ago I was looking at using annotations for telemetry, like Hugo does for logging: https://github.com/JakeWharton/hugo
A problem with that is that not all probes contain static data. Some of them (especially the ones with extras):
- https://github.com/mozilla-mobile/focus-android/blob/master/app/src/main/java/org/mozilla/focus/telemetry/TelemetryWrapper.kt#L750-L755
Or they are used in conditionals. We'd need to move things to separate methods in order to annotate them: https://github.com/mozilla-mobile/focus-android/blob/master/app/src/main/java/org/mozilla/focus/activity/MainActivity.java#L188-L198
Just to log my naive WIP implementation https://github.com/mozilla-tw/Rocket/pull/2480
I'd definitely look into hugo and think deeper.
This looks pretty cool, Nevin!
Maybe we could launch this as a new additional(!) API and then see how it works in the wild.
@TelemetryDoc(
action = Category.ACTION,
method = Method.CHANGE,
object = Object.FIRSTRUN,
value = Value.TURBO,
extras = {
@TelemetryExtra(name = Extra.TO, value = "true")
})
Do you know if it's possible to only add static values here (like "true") or can the values come from variables too?
After looking at Hugo, base my current understanding if we want some values to be generated from "variables", they'll only be available at "runtime". That means we need to write another class to call all the methods we need, and use reflection to get their parameters. It's technically doable, and we don't even need annotation to do that (Just log every calls to TelemetryPing.create).
This route is not impossible. But I need to think more about pros and cons.
Here's my WIP PR https://github.com/mozilla-tw/Rocket/pull/2725
This is how the annotation looks like: https://github.com/mozilla-tw/Rocket/pull/2725/files#diff-73cd5ee1feacc0fc807fe2a24e83bc13R303
This is how the markdown output looks like: https://github.com/mozilla-tw/Rocket/blob/6c8f98ee6988089c123310540382127e790b86ea/Telemetry.md
That's pretty cool, Nevin!
I wonder if the annotation could cause the event to be sent at runtime?
- This would avoid duplicating the code for a probe
- We could get rid of methods in TelemetryWrapper and use annotations in our code.
For example instead of this..
@TelemetryDoc(
name = "App is started by intent",
action = Category.ACTION,
method = Method.INTENT_URL,
`object` = Object.APP,
value = "",
extras = [])
@JvmStatic
fun browseIntentEvent() {
EventBuilder(Category.ACTION, Method.INTENT_URL, Object.APP).queue()
}
we annotate our code directly (without anything in TelemetryWrapper and it sends the event + is used for generating the doc.
@TelemetryEvent(
action = Category.ACTION
method = Method.INTENT_URL,
`object` = Object.APP
doc = "App is started by intent"
)
fun handleBrowseIntent(intent: Intent) {
...
}
Do you think that would be possible with a runtime annotation?
Unfortunately that wouldn't help in situations where there's dynamic data in the event, e.g. toggleFirstRunPageEvent() :(
The service-telemetry is deprecated.