diff --git a/dom/quota/QuotaCommon.cpp b/dom/quota/QuotaCommon.cpp index a05d52ee3ca1..5f4883ea3b9e 100644 --- a/dom/quota/QuotaCommon.cpp +++ b/dom/quota/QuotaCommon.cpp @@ -14,12 +14,10 @@ #include "mozilla/ErrorNames.h" #include "mozilla/MozPromise.h" #include "mozilla/Logging.h" -#include "mozilla/Telemetry.h" -#include "mozilla/TelemetryComms.h" -#include "mozilla/TelemetryEventEnums.h" #include "mozilla/TextUtils.h" #include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/dom/quota/ScopedLogExtraInfo.h" +#include "mozilla/glean/GleanMetrics.h" #include "nsIConsoleService.h" #include "nsIFile.h" #include "nsServiceManagerUtils.h" @@ -55,8 +53,6 @@ RefPtr CreateAndRejectBoolPromiseFromQMResult( namespace dom::quota { -using namespace mozilla::Telemetry; - namespace { #ifdef DEBUG @@ -554,75 +550,59 @@ void LogError(const nsACString& aExpr, const Maybe aMaybeRv, // (accidentally) added because they would have to be added to Events.yaml // under "dom.quota.try" which would require a data review. - auto extra = Some([&] { - auto res = CopyableTArray{}; - res.SetCapacity(9); - - res.AppendElement(EventExtraEntry{ - "context"_ns, - MOZ_NO_VALIDATE( - contextTainted, - "Context has been data-reviewed for telemetry transmission.")}); + mozilla::glean::dom_quota_try::ErrorStepExtra extra; + extra.context = Some(MOZ_NO_VALIDATE( + contextTainted, + "Context has been data-reviewed for telemetry transmission.")); # ifdef QM_ERROR_STACKS_ENABLED - if (!frameIdString.IsEmpty()) { - res.AppendElement( - EventExtraEntry{"frame_id"_ns, nsCString{frameIdString}}); - } + if (!frameIdString.IsEmpty()) { + extra.frameId = Some(frameIdString); + } - if (!processIdString.IsEmpty()) { - res.AppendElement( - EventExtraEntry{"process_id"_ns, nsCString{processIdString}}); - } + if (!processIdString.IsEmpty()) { + extra.processId = Some(processIdString); + } # endif - if (!rvName.IsEmpty()) { - res.AppendElement(EventExtraEntry{"result"_ns, nsCString{rvName}}); - } + if (!rvName.IsEmpty()) { + extra.result = Some(rvName); + } - // Here, we are generating thread local sequence number and thread Id - // information which could be useful for summarizing and categorizing - // log statistics in QM_TRY stack propagation scripts. Since, this is - // a thread local object, we do not need to worry about data races. - static MOZ_THREAD_LOCAL(uint32_t) sSequenceNumber; + // Here, we are generating thread local sequence number and thread Id + // information which could be useful for summarizing and categorizing + // log statistics in QM_TRY stack propagation scripts. Since, this is + // a thread local object, we do not need to worry about data races. + static MOZ_THREAD_LOCAL(uint32_t) sSequenceNumber; - // This would be initialized once, all subsequent calls would be a no-op. - MOZ_ALWAYS_TRUE(sSequenceNumber.init()); + // This would be initialized once, all subsequent calls would be a no-op. + MOZ_ALWAYS_TRUE(sSequenceNumber.init()); - // sequence number should always starts at number 1. - // `sSequenceNumber` gets initialized to 0; so we have to increment here. - const auto newSeqNum = sSequenceNumber.get() + 1; - const auto threadId = - mozilla::baseprofiler::profiler_current_thread_id().ToNumber(); + // sequence number should always starts at number 1. + // `sSequenceNumber` gets initialized to 0; so we have to increment here. + const auto newSeqNum = sSequenceNumber.get() + 1; + const auto threadId = baseprofiler::profiler_current_thread_id().ToNumber(); - const auto threadIdAndSequence = - (static_cast(threadId) << 32) | (newSeqNum & 0xFFFFFFFF); + const auto threadIdAndSequence = + (static_cast(threadId) << 32) | (newSeqNum & 0xFFFFFFFF); - res.AppendElement( - EventExtraEntry{"seq"_ns, IntToCString(threadIdAndSequence)}); + extra.seq = Some(threadIdAndSequence); - sSequenceNumber.set(newSeqNum); + sSequenceNumber.set(newSeqNum); - res.AppendElement(EventExtraEntry{"severity"_ns, severityString}); + extra.severity = Some(severityString); - res.AppendElement( - EventExtraEntry{"source_file"_ns, nsCString(sourceFileRelativePath)}); + extra.sourceFile = Some(sourceFileRelativePath); - res.AppendElement( - EventExtraEntry{"source_line"_ns, IntToCString(aSourceFileLine)}); + extra.sourceLine = Some(aSourceFileLine); # ifdef QM_ERROR_STACKS_ENABLED - if (!stackIdString.IsEmpty()) { - res.AppendElement( - EventExtraEntry{"stack_id"_ns, nsCString{stackIdString}}); - } + if (!stackIdString.IsEmpty()) { + extra.stackId = Some(stackIdString); + } # endif - return res; - }()); - - Telemetry::RecordEvent(Telemetry::EventID::DomQuotaTry_Error_Step, - Nothing(), extra); + glean::dom_quota_try::error_step.Record(Some(extra)); } # endif } diff --git a/dom/quota/metrics.yaml b/dom/quota/metrics.yaml new file mode 100644 index 000000000000..3865fcf0ae6c --- /dev/null +++ b/dom/quota/metrics.yaml @@ -0,0 +1,71 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Adding a new metric? We have docs for that! +# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html + +--- +$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0 +$tags: + - 'Core :: Storage: Quota Manager' + +dom.quota.try: + error_step: + type: event + description: > + An event recorded on an error of the quota manager or its clients. + Since errors are usually propagated up the call chain, all such + propagation steps are recorded for an error. This is only active + during specific contexts, in particular during storage + initialization. No dynamic data is included in the event beyond the + error code which will be added through Bug 1670555. + This event was generated to correspond to the Legacy Telemetry event + dom.quota.try.error#step. + bugs: + - https://bugzil.la/1665088 + data_reviews: + - https://bugzil.la/1665088 + notification_emails: + - jvarga@mozilla.com + - storage-telemetry@mozilla.com + expires: never + extra_keys: + context: + description: > + The context in which the error occurred, e.g. during a storage initialization. + Telemetry events are only emitted for selected contexts. + type: string + frame_id: + description: > + Optionally, the frame within stack_id. + type: string + process_id: + description: > + Optionally, the process in which the error occured. + type: string + result: + description: > + Optionally, the name of the error that occurred. + type: string + seq: + description: > + Sequence number. + type: quantity + severity: + description: > + One of WARNING or ERROR. + type: string + source_file: + description: > + The name of the source code file where the error occurred. + type: string + source_line: + description: > + The line within source_file where the error occurred. + type: quantity + stack_id: + description: > + Optionally, the stack within process_id. + type: string + telemetry_mirror: DomQuotaTry_Error_Step diff --git a/toolkit/components/glean/metrics_index.py b/toolkit/components/glean/metrics_index.py index a54eea484932..685cfad6e711 100644 --- a/toolkit/components/glean/metrics_index.py +++ b/toolkit/components/glean/metrics_index.py @@ -26,6 +26,7 @@ gecko_metrics = [ "dom/metrics.yaml", "dom/notification/metrics.yaml", "dom/performance/metrics.yaml", + "dom/quota/metrics.yaml", "dom/security/metrics.yaml", "dom/webauthn/metrics.yaml", "gfx/metrics.yaml",