Bug 1683132 - Include nsresult value in telemetry events. r=dom-workers-and-storage-reviewers,janv

Differential Revision: https://phabricator.services.mozilla.com/D100089
This commit is contained in:
Simon Giesecke 2020-12-21 09:32:12 +00:00
Родитель 27565d419d
Коммит 33fc668a0e
3 изменённых файлов: 25 добавлений и 15 удалений

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

@ -8,6 +8,7 @@
#include "mozIStorageConnection.h"
#include "mozIStorageStatement.h"
#include "mozilla/ErrorNames.h"
#include "mozilla/Logging.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryComms.h"
@ -286,9 +287,20 @@ void ScopedLogExtraInfo::AddInfo() {
#endif
void LogError(const nsLiteralCString& aModule, const nsACString& aExpr,
const nsACString& aSourceFile, int32_t aSourceLine) {
const nsACString& aSourceFile, int32_t aSourceLine,
Maybe<nsresult> aRv) {
nsAutoCString extraInfosString;
const char* rvName = nullptr;
if (aRv) {
rvName = mozilla::GetStaticErrorName(*aRv);
extraInfosString.AppendPrintf(
"failed with "
"result 0x%" PRIX32 "%s%s%s",
static_cast<uint32_t>(*aRv), rvName ? " (" : "", rvName ? rvName : "",
rvName ? ")" : "");
}
#ifdef QM_ENABLE_SCOPED_LOG_EXTRA_INFO
const auto& extraInfos = ScopedLogExtraInfo::GetExtraInfoMap();
for (const auto& item : extraInfos) {
@ -338,6 +350,10 @@ void LogError(const nsLiteralCString& aModule, const nsACString& aExpr,
res.AppendElement(EventExtraEntry{
"context"_ns, nsPromiseFlatCString{*contextIt->second}});
if (rvName) {
res.AppendElement(EventExtraEntry{"result"_ns, nsCString{rvName}});
}
return res;
}());

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

@ -16,9 +16,9 @@
#include "mozIStorageStatement.h"
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/ErrorNames.h"
#include "mozilla/Likely.h"
#include "mozilla/MacroArgs.h"
#include "mozilla/Maybe.h"
#include "mozilla/Result.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/ThreadLocal.h"
@ -1017,7 +1017,8 @@ CreateAndExecuteSingleStepStatement(mozIStorageConnection& aConnection,
const nsACString& aStatementString);
void LogError(const nsLiteralCString& aModule, const nsACString& aExpr,
const nsACString& aSourceFile, int32_t aSourceLine);
const nsACString& aSourceFile, int32_t aSourceLine,
Maybe<nsresult> aRv);
#ifdef DEBUG
Result<bool, nsresult> WarnIfFileIsUnknown(nsIFile& aFile,
@ -1088,21 +1089,13 @@ struct MOZ_STACK_CLASS ScopedLogExtraInfo {
const char* aSourceFile, \
int32_t aSourceLine) { \
if constexpr (std::is_same_v<T, nsresult>) { \
const char* name = mozilla::GetStaticErrorName(aRv); \
const auto msg = nsPrintfCString{ \
"%s failed with " \
"result 0x%" PRIX32 "%s%s%s", \
aExpr, \
static_cast<uint32_t>(aRv), \
name ? " (" : "", \
name ? name : "", \
name ? ")" : ""}; \
mozilla::dom::quota::LogError( \
module, msg, nsDependentCString(aSourceFile), aSourceLine); \
mozilla::dom::quota::LogError(module, nsDependentCString(aExpr), \
nsDependentCString(aSourceFile), \
aSourceLine, Some(aRv)); \
} else { \
mozilla::dom::quota::LogError(module, nsDependentCString(aExpr), \
nsDependentCString(aSourceFile), \
aSourceLine); \
aSourceLine, Nothing{}); \
} \
}
#else

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

@ -2597,5 +2597,6 @@ dom.quota.try:
extra_keys:
context: The context in which the error occurred, e.g. during a storage initialization. Telemetry events are only emitted for selected contexts.
module: The module (quota manager or one of its clients) where the error occured.
result: Optionally, the name of the error that occurred.
source_file: The name of the source code file where the error occured.
source_line: The line within source_file where the error occured.