Bug 1448945 - Allow underscore in category, method and extra keys of event. r=chutten
authorJan-Erik Rediger <jrediger@mozilla.com>
Tue, 10 Apr 2018 13:05:39 +0200
changeset 467821 350a522001fae5494569ea4f8eec6b4556776505
parent 467820 c8fb850a6d66e28f51870e03a4d04b253fd53557
child 467822 efb850288b07e0fba98cce31f45bdd20f1ca0124
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1448945
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1448945 - Allow underscore in category, method and extra keys of event. r=chutten According to the documnetation[1] category and method are identifiers, thus an underscore is allowed. It's less clear for extra keys, but underscores are already used there. The documentation is adjusted accordingly. [1]: https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/events.html#limits MozReview-Commit-ID: 9pUsDNXCY8m
toolkit/components/telemetry/TelemetryEvent.cpp
toolkit/components/telemetry/docs/collection/events.rst
--- a/toolkit/components/telemetry/TelemetryEvent.cpp
+++ b/toolkit/components/telemetry/TelemetryEvent.cpp
@@ -976,17 +976,17 @@ nsresult
 TelemetryEvent::RegisterEvents(const nsACString& aCategory,
                                JS::Handle<JS::Value> aEventData,
                                bool aBuiltin,
                                JSContext* cx)
 {
   MOZ_ASSERT(XRE_IsParentProcess(),
              "Events can only be registered in the parent process");
 
-  if (!IsValidIdentifierString(aCategory, 30, true, false)) {
+  if (!IsValidIdentifierString(aCategory, 30, true, true)) {
     JS_ReportErrorASCII(cx, "Category parameter should match the identifier pattern.");
     return NS_ERROR_INVALID_ARG;
   }
 
   if (!aEventData.isObject()) {
     JS_ReportErrorASCII(cx, "Event data parameter should be an object");
     return NS_ERROR_INVALID_ARG;
   }
@@ -1060,17 +1060,17 @@ TelemetryEvent::RegisterEvents(const nsA
         return NS_ERROR_FAILURE;
       }
 
       recordOnRelease = temp.toBoolean();
     }
 
     // Validate methods.
     for (auto& method : methods) {
-      if (!IsValidIdentifierString(method, kMaxMethodNameByteLength, false, false)) {
+      if (!IsValidIdentifierString(method, kMaxMethodNameByteLength, false, true)) {
         JS_ReportErrorASCII(cx, "Method names should match the identifier pattern.");
         return NS_ERROR_INVALID_ARG;
       }
     }
 
     // Validate objects.
     for (auto& object : objects) {
       if (!IsValidIdentifierString(object, kMaxObjectNameByteLength, false, true)) {
@@ -1080,17 +1080,17 @@ TelemetryEvent::RegisterEvents(const nsA
     }
 
     // Validate extra keys.
     if (extra_keys.Length() > kMaxExtraKeyCount) {
       JS_ReportErrorASCII(cx, "No more than 10 extra keys can be registered.");
       return NS_ERROR_INVALID_ARG;
     }
     for (auto& key : extra_keys) {
-      if (!IsValidIdentifierString(key, kMaxExtraKeyNameByteLength, false, false)) {
+      if (!IsValidIdentifierString(key, kMaxExtraKeyNameByteLength, false, true)) {
         JS_ReportErrorASCII(cx, "Extra key names should match the identifier pattern.");
         return NS_ERROR_INVALID_ARG;
       }
     }
 
     // Append event infos to be registered.
     for (auto& method : methods) {
       for (auto& object : objects) {
--- a/toolkit/components/telemetry/docs/collection/events.rst
+++ b/toolkit/components/telemetry/docs/collection/events.rst
@@ -38,17 +38,17 @@ Each event is of the form:
 
 Where the individual fields are:
 
 - ``timestamp``: ``Number``, positive integer. This is the time in ms when the event was recorded, relative to the main process start time.
 - ``category``: ``String``, identifier. The category is a group name for events and helps to avoid name conflicts.
 - ``method``: ``String``, identifier. This describes the type of event that occurred, e.g. ``click``, ``keydown`` or ``focus``.
 - ``object``: ``String``, identifier. This is the object the event occurred on, e.g. ``reload_button`` or ``urlbar``.
 - ``value``: ``String``, optional, may be ``null``. This is a user defined value, providing context for the event.
-- ``extra``: ``Object``, optional, may be ``null``. This is an object of the form ``{"key": "value", ...}``, both keys and values need to be strings. This is used for events where additional richer context is needed.
+- ``extra``: ``Object``, optional, may be ``null``. This is an object of the form ``{"key": "value", ...}``, both keys and values need to be strings, keys are identifiers. This is used for events where additional richer context is needed.
 
 .. _eventlimits:
 
 Limits
 ------
 
 Each ``String`` marked as an identifier is restricted to the following regex pattern: ``^[:alpha:][:alnum:_.]*[:alnum:]$``.