{"id":311,"date":"2021-07-22T14:37:07","date_gmt":"2021-07-22T14:37:07","guid":{"rendered":"https:\/\/blog.mozilla.org\/data\/?p=311"},"modified":"2021-07-22T14:37:07","modified_gmt":"2021-07-22T14:37:07","slug":"this-week-in-glean-firefox-telemetry-is-to-glean-as-c-is-to-rust","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/data\/2021\/07\/22\/this-week-in-glean-firefox-telemetry-is-to-glean-as-c-is-to-rust\/","title":{"rendered":"This Week in Glean: Firefox Telemetry is to Glean as C++ is to Rust"},"content":{"rendered":"<p><em>(\u201cThis Week in Glean\u201d is a series of blog posts that the Glean Team at Mozilla is using to try to communicate better about our work. They could be release notes, documentation, hopes, dreams, or whatever: so long as it is inspired by Glean. You can find an<\/em><a href=\"https:\/\/mozilla.github.io\/glean\/book\/appendix\/twig.html\"><em> index of all TWiG posts online<\/em><\/a><em>.)<\/em><\/p>\n<p>I had this goofy idea that, like <a href=\"https:\/\/www.rust-lang.org\/\">Rust<\/a>, the <a href=\"https:\/\/mozilla.github.io\/glean\/book\/index.html\">Glean SDKs<\/a> (and <a href=\"https:\/\/telemetry.mozilla.org\/\">Ecosystem<\/a>) aim to bring safety and higher-level thought to their domain. This is in comparison to how, like C++, <a href=\"https:\/\/firefox-source-docs.mozilla.org\/toolkit\/components\/telemetry\/index.html\">Firefox Telemetry<\/a> is built out of flexible primitives that assume you very much know what you\u2019re doing and cannot (will not?) provide any clues in its design as to how to do things properly.<\/p>\n<p>I have these goofy thoughts a lot. I\u2019m a goofy guy. But the more I thought about it, the more the comparison seemed apt.<\/p>\n<p>In Glean wherever we can we intentionally forbid behaviour we cannot guarantee is safe (e.g. we <a href=\"https:\/\/firefox-source-docs.mozilla.org\/toolkit\/components\/glean\/dev\/ipc.html#forbidding-non-commutative-operations\">forbid non-commutative operations in FOG IPC<\/a>, we <a href=\"https:\/\/mozilla.github.io\/glean\/book\/reference\/metrics\/counter.html#recorded-errors\">forbid decrementing counters<\/a>). And in situations where we need to permit perhaps-unsafe data practices, we do it in tightly-scoped areas that are identified as unsafe (e.g. if a timing_distribution uses <a href=\"https:\/\/github.com\/mozilla\/glean\/blob\/main\/glean-core\/src\/metrics\/timing_distribution.rs#L327\">accumulate_raw_samples_nanos<\/a> you know to look at its data with more skepticism).<\/p>\n<p>In Glean we encourage instrumentors to think at a higher level (e.g. <a href=\"https:\/\/mozilla.github.io\/glean\/book\/reference\/metrics\/memory_distribution.html\">memory_distribution<\/a> instead of a <a href=\"https:\/\/firefox-source-docs.mozilla.org\/toolkit\/components\/telemetry\/collection\/histograms.html\">Histogram<\/a> of unknown buckets and samples) thereby permitting Glean to identify errors early (e.g. you <a href=\"https:\/\/mozilla.github.io\/glean\/book\/reference\/metrics\/timespan.html#recorded-errors\">can\u2019t start a timespan twice<\/a>) and allowing Glean to do clever things about it (e.g. in our tooling we know counter metrics are interesting when summed, but quantity metrics are not). Speaking of those errors, we are able to forbid error-prone behaviour through design and use of language features (e.g. In languages with type systems we can prevent you from collecting the wrong type of data) and when the error is only detectable at runtime we can <a href=\"https:\/\/mozilla.github.io\/glean\/book\/user\/metrics\/error-reporting.html\">report it<\/a> with a high degree of specificity to make it easier to diagnose.<\/p>\n<p>There are more analogues, but the metaphor gets strained. (( I mean, I guess a timing_distribution\u2019s `TimerId` is kinda the closest thing to a borrow checker we have? Maybe? )) So I should probably stop here.<\/p>\n<p>Now, those of you paying attention might have already seen this relationship. After all, as we all know, <a href=\"https:\/\/github.com\/mozilla\/glean\/tree\/main\/glean-core\">glean-core<\/a> (which underpins most of the Glean SDKs regardless of language) is actually written in Rust whereas Firefox Telemetry\u2019s core of <a href=\"https:\/\/firefox-source-docs.mozilla.org\/toolkit\/components\/telemetry\/collection\/histograms.html\">Histograms<\/a>, <a href=\"https:\/\/firefox-source-docs.mozilla.org\/toolkit\/components\/telemetry\/collection\/scalars.html\">Scalars<\/a>, and <a href=\"https:\/\/firefox-source-docs.mozilla.org\/toolkit\/components\/telemetry\/collection\/events.html\">Events<\/a> is written in C++. Maybe we shouldn\u2019t be too surprised when the language the system is written in happens to be reflected in the top-level design.<\/p>\n<p>But! glean-core was (for a long time) <a href=\"https:\/\/github.com\/mozilla\/glean\/releases\/tag\/v19.0.0\">written in Kotlin<\/a> from stem to stern. So maybe it\u2019s not due to language determinism and is more to do with thoughtful design, careful change processes, and a <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=1619259\">list of principles<\/a> we hold to firmly as the number of supported languages and metric types continues to grow.<\/p>\n<p>I certainly don\u2019t know. I\u2019m just goofing around.<\/p>\n<p>:chutten<\/p>\n<p>(( This is a syndicated copy of <a href=\"https:\/\/chuttenblog.wordpress.com\/2021\/07\/22\/this-week-in-glean-firefox-telemetry-is-to-glean-as-c-is-to-rust\/\">the original blog post<\/a>. ))<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(\u201cThis Week in Glean\u201d is a series of blog posts that the Glean Team at Mozilla is using to try to communicate better about our work. They could be release &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/data\/2021\/07\/22\/this-week-in-glean-firefox-telemetry-is-to-glean-as-c-is-to-rust\/\">Read more<\/a><\/p>\n","protected":false},"author":1437,"featured_media":197,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[448297],"tags":[448322,540,525,30,448297,16179,3969],"coauthors":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/posts\/311"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/users\/1437"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/comments?post=311"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/posts\/311\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/media\/197"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/media?parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/categories?post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/tags?post=311"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.mozilla.org\/data\/wp-json\/wp\/v2\/coauthors?post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}