@grafana/faro-web-sdk
Version:
Faro instrumentations, metas, transports for web.
39 lines • 2.14 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PerformanceInstrumentation = exports.performanceEntriesSubscription = void 0;
const faro_core_1 = require("@grafana/faro-core");
const navigation_1 = require("./navigation");
const performanceUtils_1 = require("./performanceUtils");
const resource_1 = require("./resource");
exports.performanceEntriesSubscription = new faro_core_1.Observable();
class PerformanceInstrumentation extends faro_core_1.BaseInstrumentation {
constructor() {
super(...arguments);
this.name = '@grafana/faro-web-sdk:instrumentation-performance';
this.version = faro_core_1.VERSION;
}
initialize() {
if (!(0, performanceUtils_1.performanceObserverSupported)()) {
this.logDebug('performance observer not supported. Disable performance instrumentation.');
return;
}
(0, performanceUtils_1.onDocumentReady)(() => __awaiter(this, void 0, void 0, function* () {
const pushEvent = this.api.pushEvent;
const { faroNavigationId } = yield (0, navigation_1.getNavigationTimings)(pushEvent);
if (faroNavigationId != null) {
(0, resource_1.observeResourceTimings)(faroNavigationId, pushEvent, exports.performanceEntriesSubscription);
}
}));
}
}
exports.PerformanceInstrumentation = PerformanceInstrumentation;
//# sourceMappingURL=instrumentation.js.map