iOS: User metrics should be in a namespace/prefixed with a namespace
Categories
(Data Platform and Tools :: Glean: SDK, defect, P3)
Tracking
(Not tracked)
People
(Reporter: janerik, Assigned: janerik)
Details
(Whiteboard: [telemetry:glean-rs:m9])
Attachments
(1 file)
In Kotlin we put all user-generated metrics into a specified namespace, so they won't ever clash with the user's code.
Swift unfortunately does not have namespaces.
For the category of metrics we use an otherwise empty enum (that can't be instantiated) and put metrics into statics inside.
However that might clash with user code when the category is already used.
One option would be to prepend GleanMetrics to all names.
| Assignee | ||
Updated•6 years ago
|
Comment 1•6 years ago
•
|
||
It should be possible to add the generated metrics to the base Glean class, using it like a namespace, by using extensions. According to the docs for extensions, we can add new nested types, which would mean we could generate something like:
extension Glean {
internal enum GleanInternalMetrics {
/// The name of the operating system.
static let os = StringMetricType(
category: "",
name: "os",
sendInPings: ["glean_client_info"],
lifetime: .application,
disabled: false
)
...
}
}
Or we could create a new base class like a struct/enum, but it would have to be named something other than Glean to prevent clashing with the Glean internal API class.
| Assignee | ||
Comment 2•6 years ago
|
||
Hm, that seems very sensible indeed.
If we generate the above, users would then call this code:
Glean.GleanInternalMetrics.os.set("foobar")
(obviously they wouldn't get the "internal" metrics, they should use proper naming)
Users can use a local type alias if they want:
typealias GleanInternalMetrics = Glean.GleanInternalMetrics
:dexter, heads up for what this would look like.
Comment 3•6 years ago
|
||
(In reply to Jan-Erik Rediger [:janerik] from comment #2)
Hm, that seems very sensible indeed.
If we generate the above, users would then call this code:Glean.GleanInternalMetrics.os.set("foobar")(obviously they wouldn't get the "internal" metrics, they should use proper naming)
Users can use a local type alias if they want:
typealias GleanInternalMetrics = Glean.GleanInternalMetrics:dexter, heads up for what this would look like.
This looks good to me, with a nit: in the Kotlin code we don't add metrics to the Glean class, but to the GleanMetrics namespace. So we'd need to extend a GleanMetrics object, for consistency and for matching the other platform. Ideally, we'd do the same on Desktop. See here.
| Assignee | ||
Comment 4•6 years ago
|
||
Fair enough, easy to do. We can just add an empty GleanMetrics object to Glean itself, which then gets extended by users.
| Assignee | ||
Updated•6 years ago
|
| Assignee | ||
Comment 5•6 years ago
|
||
| Assignee | ||
Updated•6 years ago
|
Description
•