diff --git a/devtools/server/actors/network-monitor/network-observer.js b/devtools/server/actors/network-monitor/network-observer.js index 879fbbf90722..ab82347db1d7 100644 --- a/devtools/server/actors/network-monitor/network-observer.js +++ b/devtools/server/actors/network-monitor/network-observer.js @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; - +console.log("hello"); /** * NetworkObserver is the main class in DevTools to observe network requests * out of many events fired by the platform code. diff --git a/netwerk/protocol/http/EarlyHintPreloader.cpp b/netwerk/protocol/http/EarlyHintPreloader.cpp index e1fc25fd0ef2..4a3ed8117759 100644 --- a/netwerk/protocol/http/EarlyHintPreloader.cpp +++ b/netwerk/protocol/http/EarlyHintPreloader.cpp @@ -9,6 +9,8 @@ #include "mozilla/CORSMode.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/ReferrerInfo.h" +#include "mozilla/StaticPrefs_network.h" +#include "mozilla/glean/GleanMetrics.h" #include "mozilla/Logging.h" #include "nsAttrValue.h" #include "nsAttrValueInlines.h" @@ -154,6 +156,14 @@ void EarlyHintPreloader::MaybeCreateAndInsertPreload( nsAttrValue as; ParseAsValue(aHeader.mAs, as); + + ASDestination destination = static_cast(as.GetEnumValue()); + CollectResourcesTypeTelemetry(destination); + + if (!StaticPrefs::network_early_hints_enabled()) { + return; + } + if (as.GetEnumValue() == ASDestination::DESTINATION_INVALID) { // return early when it's definitly not an asset type we preload // would be caught later as well, e.g. when creating the PreloadHashKey @@ -378,4 +388,20 @@ EarlyHintPreloader::GetInterface(const nsIID& aIID, void** aResult) { return NS_ERROR_NO_INTERFACE; } +void EarlyHintPreloader::CollectResourcesTypeTelemetry( + ASDestination aASDestination) { + if (aASDestination == ASDestination::DESTINATION_FONT) { + glean::netwerk::early_hints.Get("font"_ns).Add(1); + } else if (aASDestination == ASDestination::DESTINATION_SCRIPT) { + glean::netwerk::early_hints.Get("script"_ns).Add(1); + } else if (aASDestination == ASDestination::DESTINATION_STYLE) { + glean::netwerk::early_hints.Get("stylesheet"_ns).Add(1); + } else if (aASDestination == ASDestination::DESTINATION_IMAGE) { + glean::netwerk::early_hints.Get("image"_ns).Add(1); + } else if (aASDestination == ASDestination::DESTINATION_FETCH) { + glean::netwerk::early_hints.Get("fetch"_ns).Add(1); + } else { + glean::netwerk::early_hints.Get("other"_ns).Add(1); + } +} } // namespace mozilla::net diff --git a/netwerk/protocol/http/EarlyHintPreloader.h b/netwerk/protocol/http/EarlyHintPreloader.h index 5a9db7f02102..0cfef5d30cb3 100644 --- a/netwerk/protocol/http/EarlyHintPreloader.h +++ b/netwerk/protocol/http/EarlyHintPreloader.h @@ -87,6 +87,7 @@ class EarlyHintPreloader final : public nsIStreamListener, nsIReferrerInfo* aReferrerInfo, nsICookieJarSettings* aCookieJarSettings); + static void CollectResourcesTypeTelemetry(ASDestination aASDestination); // keep opening uri to not preload cross origins on redirects for now nsCOMPtr mURI; nsCOMPtr mChannel; diff --git a/netwerk/protocol/http/EarlyHintsService.cpp b/netwerk/protocol/http/EarlyHintsService.cpp index 8e1f456c176d..15595837a411 100644 --- a/netwerk/protocol/http/EarlyHintsService.cpp +++ b/netwerk/protocol/http/EarlyHintsService.cpp @@ -12,7 +12,6 @@ #include "nsICookieJarSettings.h" #include "nsNetUtil.h" #include "nsString.h" -#include "mozilla/StaticPrefs_network.h" #include "nsIPrincipal.h" #include "nsILoadInfo.h" @@ -33,10 +32,6 @@ void EarlyHintsService::EarlyHint(const nsACString& aLinkHeader, mFirstEarlyHint.emplace(TimeStamp::NowLoRes()); } - if (!StaticPrefs::network_early_hints_enabled()) { - return; - } - nsCOMPtr triggeringPrincipal = aLoadInfo->TriggeringPrincipal(); nsCOMPtr cookieJarSettings; diff --git a/netwerk/protocol/http/metrics.yaml b/netwerk/protocol/http/metrics.yaml new file mode 100644 index 000000000000..b392fb57c292 --- /dev/null +++ b/netwerk/protocol/http/metrics.yaml @@ -0,0 +1,32 @@ +# 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 :: Networking: HTTP' + + +netwerk: + early_hints: + type: labeled_counter + labels: + - stylesheet + - fonts + - scripts + - fetch + - image + description: > + Counts the different type of resources that are sent for early hints. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1772124 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1772124 + notification_emails: + - necko@mozilla.com + - ddamjanovic@mozilla.com + expires: 109 diff --git a/toolkit/components/glean/metrics_index.py b/toolkit/components/glean/metrics_index.py index 96db3ba09630..5bc608f49410 100644 --- a/toolkit/components/glean/metrics_index.py +++ b/toolkit/components/glean/metrics_index.py @@ -20,6 +20,7 @@ metrics_yamls = [ "dom/media/metrics.yaml", "dom/metrics.yaml", "gfx/metrics.yaml", + "netwerk/protocol/http/metrics.yaml", "toolkit/components/extensions/metrics.yaml", "toolkit/components/glean/metrics.yaml", "toolkit/components/glean/tests/test_metrics.yaml",