Bug 1918226 - Use Glean APIs for dom.quota.try.error#step r=janv

Differential Revision: https://phabricator.services.mozilla.com/D221489
This commit is contained in:
Chris H-C 2024-09-20 18:42:58 +00:00
Родитель 223708e03f
Коммит 2023bfa52d
3 изменённых файлов: 108 добавлений и 56 удалений

Просмотреть файл

@ -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<BoolPromise> CreateAndRejectBoolPromiseFromQMResult(
namespace dom::quota {
using namespace mozilla::Telemetry;
namespace {
#ifdef DEBUG
@ -554,30 +550,23 @@ void LogError(const nsACString& aExpr, const Maybe<nsresult> 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<EventExtraEntry>{};
res.SetCapacity(9);
res.AppendElement(EventExtraEntry{
"context"_ns,
MOZ_NO_VALIDATE(
mozilla::glean::dom_quota_try::ErrorStepExtra extra;
extra.context = Some(MOZ_NO_VALIDATE(
contextTainted,
"Context has been data-reviewed for telemetry transmission.")});
"Context has been data-reviewed for telemetry transmission."));
# ifdef QM_ERROR_STACKS_ENABLED
if (!frameIdString.IsEmpty()) {
res.AppendElement(
EventExtraEntry{"frame_id"_ns, nsCString{frameIdString}});
extra.frameId = Some(frameIdString);
}
if (!processIdString.IsEmpty()) {
res.AppendElement(
EventExtraEntry{"process_id"_ns, nsCString{processIdString}});
extra.processId = Some(processIdString);
}
# endif
if (!rvName.IsEmpty()) {
res.AppendElement(EventExtraEntry{"result"_ns, nsCString{rvName}});
extra.result = Some(rvName);
}
// Here, we are generating thread local sequence number and thread Id
@ -592,37 +581,28 @@ void LogError(const nsACString& aExpr, const Maybe<nsresult> aMaybeRv,
// 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();
const auto threadId = baseprofiler::profiler_current_thread_id().ToNumber();
const auto threadIdAndSequence =
(static_cast<uint64_t>(threadId) << 32) | (newSeqNum & 0xFFFFFFFF);
res.AppendElement(
EventExtraEntry{"seq"_ns, IntToCString(threadIdAndSequence)});
extra.seq = Some(threadIdAndSequence);
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}});
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
}

71
dom/quota/metrics.yaml Normal file
Просмотреть файл

@ -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

Просмотреть файл

@ -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",