Socket
Socket
Sign inDemoInstall

@opentelemetry/instrumentation-document-load

Package Overview
Dependencies
Maintainers
4
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-document-load - npm Package Compare versions

Comparing version 0.22.0 to 0.23.0

111

build/esm/instrumentation.js

@@ -16,2 +16,17 @@ /*

*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { context, propagation, trace, ROOT_CONTEXT, } from '@opentelemetry/api';

@@ -28,3 +43,4 @@ import { otperformance, TRACE_PARENT_HEADER } from '@opentelemetry/core';

*/
export class DocumentLoadInstrumentation extends InstrumentationBase {
var DocumentLoadInstrumentation = /** @class */ (function (_super) {
__extends(DocumentLoadInstrumentation, _super);
/**

@@ -34,19 +50,22 @@ *

*/
constructor(config = {}) {
super('@opentelemetry/instrumentation-document-load', VERSION, config);
this.component = 'document-load';
this.version = '1';
this.moduleName = this.component;
function DocumentLoadInstrumentation(config) {
if (config === void 0) { config = {}; }
var _this = _super.call(this, '@opentelemetry/instrumentation-document-load', VERSION, config) || this;
_this.component = 'document-load';
_this.version = '1';
_this.moduleName = _this.component;
return _this;
}
init() { }
DocumentLoadInstrumentation.prototype.init = function () { };
/**
* callback to be executed when page is loaded
*/
_onDocumentLoaded() {
DocumentLoadInstrumentation.prototype._onDocumentLoaded = function () {
var _this = this;
// Timeout is needed as load event doesn't have yet the performance metrics for loadEnd.
// Support for event "loadend" is very limited and cannot be used
window.setTimeout(() => {
this._collectPerformance();
window.setTimeout(function () {
_this._collectPerformance();
});
}
};
/**

@@ -56,29 +75,31 @@ * Adds spans for all resources

*/
_addResourcesSpans(rootSpan) {
DocumentLoadInstrumentation.prototype._addResourcesSpans = function (rootSpan) {
var _this = this;
var _a, _b;
const resources = (_b = (_a = otperformance).getEntriesByType) === null || _b === void 0 ? void 0 : _b.call(_a, 'resource');
var resources = (_b = (_a = otperformance).getEntriesByType) === null || _b === void 0 ? void 0 : _b.call(_a, 'resource');
if (resources) {
resources.forEach(resource => {
this._initResourceSpan(resource, rootSpan);
resources.forEach(function (resource) {
_this._initResourceSpan(resource, rootSpan);
});
}
}
};
/**
* Collects information about performance and creates appropriate spans
*/
_collectPerformance() {
const metaElement = [...document.getElementsByTagName('meta')].find(e => e.getAttribute('name') === TRACE_PARENT_HEADER);
const entries = getPerformanceNavigationEntries();
const traceparent = (metaElement && metaElement.content) || '';
context.with(propagation.extract(ROOT_CONTEXT, { traceparent }), () => {
const rootSpan = this._startSpan(AttributeNames.DOCUMENT_LOAD, PTN.FETCH_START, entries);
DocumentLoadInstrumentation.prototype._collectPerformance = function () {
var _this = this;
var metaElement = Array.from(document.getElementsByTagName('meta')).find(function (e) { return e.getAttribute('name') === TRACE_PARENT_HEADER; });
var entries = getPerformanceNavigationEntries();
var traceparent = (metaElement && metaElement.content) || '';
context.with(propagation.extract(ROOT_CONTEXT, { traceparent: traceparent }), function () {
var rootSpan = _this._startSpan(AttributeNames.DOCUMENT_LOAD, PTN.FETCH_START, entries);
if (!rootSpan) {
return;
}
context.with(trace.setSpan(context.active(), rootSpan), () => {
const fetchSpan = this._startSpan(AttributeNames.DOCUMENT_FETCH, PTN.FETCH_START, entries);
context.with(trace.setSpan(context.active(), rootSpan), function () {
var fetchSpan = _this._startSpan(AttributeNames.DOCUMENT_FETCH, PTN.FETCH_START, entries);
if (fetchSpan) {
context.with(trace.setSpan(context.active(), fetchSpan), () => {
context.with(trace.setSpan(context.active(), fetchSpan), function () {
addSpanNetworkEvents(fetchSpan, entries);
this._endSpan(fetchSpan, PTN.RESPONSE_END, entries);
_this._endSpan(fetchSpan, PTN.RESPONSE_END, entries);
});

@@ -89,3 +110,3 @@ }

rootSpan.setAttribute(SemanticAttributes.HTTP_USER_AGENT, navigator.userAgent);
this._addResourcesSpans(rootSpan);
_this._addResourcesSpans(rootSpan);
addSpanNetworkEvent(rootSpan, PTN.FETCH_START, entries);

@@ -101,5 +122,5 @@ addSpanNetworkEvent(rootSpan, PTN.UNLOAD_EVENT_START, entries);

addSpanPerformancePaintEvents(rootSpan);
this._endSpan(rootSpan, PTN.LOAD_EVENT_END, entries);
_this._endSpan(rootSpan, PTN.LOAD_EVENT_END, entries);
});
}
};
/**

@@ -111,3 +132,3 @@ * Helper function for ending span

*/
_endSpan(span, performanceName, entries) {
DocumentLoadInstrumentation.prototype._endSpan = function (span, performanceName, entries) {
// span can be undefined when entries are missing the certain performance - the span will not be created

@@ -123,3 +144,3 @@ if (span) {

}
}
};
/**

@@ -130,4 +151,4 @@ * Creates and ends a span with network information about resource added as timed events

*/
_initResourceSpan(resource, parentSpan) {
const span = this._startSpan(AttributeNames.RESOURCE_FETCH, PTN.FETCH_START, resource, parentSpan);
DocumentLoadInstrumentation.prototype._initResourceSpan = function (resource, parentSpan) {
var span = this._startSpan(AttributeNames.RESOURCE_FETCH, PTN.FETCH_START, resource, parentSpan);
if (span) {

@@ -138,3 +159,3 @@ span.setAttribute(SemanticAttributes.HTTP_URL, resource.name);

}
}
};
/**

@@ -147,6 +168,6 @@ * Helper function for starting a span

*/
_startSpan(spanName, performanceName, entries, parentSpan) {
DocumentLoadInstrumentation.prototype._startSpan = function (spanName, performanceName, entries, parentSpan) {
if (hasKey(entries, performanceName) &&
typeof entries[performanceName] === 'number') {
const span = this.tracer.startSpan(spanName, {
var span = this.tracer.startSpan(spanName, {
startTime: entries[performanceName],

@@ -158,7 +179,7 @@ }, parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined);

return undefined;
}
};
/**
* executes callback {_onDocumentLoaded} when the page is loaded
*/
_waitForPageLoad() {
DocumentLoadInstrumentation.prototype._waitForPageLoad = function () {
if (window.document.readyState === 'complete') {

@@ -171,7 +192,7 @@ this._onDocumentLoaded();

}
}
};
/**
* implements enable function
*/
enable() {
DocumentLoadInstrumentation.prototype.enable = function () {
// remove previously attached load to avoid adding the same event twice

@@ -181,10 +202,12 @@ // in case of multiple enable calling.

this._waitForPageLoad();
}
};
/**
* implements disable function
*/
disable() {
DocumentLoadInstrumentation.prototype.disable = function () {
window.removeEventListener('load', this._onDocumentLoaded);
}
}
};
return DocumentLoadInstrumentation;
}(InstrumentationBase));
export { DocumentLoadInstrumentation };
//# sourceMappingURL=instrumentation.js.map

@@ -19,11 +19,11 @@ /*

import { EventNames } from './enums/EventNames';
export const getPerformanceNavigationEntries = () => {
export var getPerformanceNavigationEntries = function () {
var _a, _b;
const entries = {};
const performanceNavigationTiming = (_b = (_a = otperformance).getEntriesByType) === null || _b === void 0 ? void 0 : _b.call(_a, 'navigation')[0];
var entries = {};
var performanceNavigationTiming = (_b = (_a = otperformance).getEntriesByType) === null || _b === void 0 ? void 0 : _b.call(_a, 'navigation')[0];
if (performanceNavigationTiming) {
const keys = Object.values(PTN);
keys.forEach((key) => {
var keys = Object.values(PTN);
keys.forEach(function (key) {
if (hasKey(performanceNavigationTiming, key)) {
const value = performanceNavigationTiming[key];
var value = performanceNavigationTiming[key];
if (typeof value === 'number') {

@@ -37,9 +37,9 @@ entries[key] = value;

// // fallback to previous version
const perf = otperformance;
const performanceTiming = perf.timing;
if (performanceTiming) {
const keys = Object.values(PTN);
keys.forEach((key) => {
if (hasKey(performanceTiming, key)) {
const value = performanceTiming[key];
var perf = otperformance;
var performanceTiming_1 = perf.timing;
if (performanceTiming_1) {
var keys = Object.values(PTN);
keys.forEach(function (key) {
if (hasKey(performanceTiming_1, key)) {
var value = performanceTiming_1[key];
if (typeof value === 'number') {

@@ -54,11 +54,12 @@ entries[key] = value;

};
const performancePaintNames = {
var performancePaintNames = {
'first-paint': EventNames.FIRST_PAINT,
'first-contentful-paint': EventNames.FIRST_CONTENTFUL_PAINT,
};
export const addSpanPerformancePaintEvents = (span) => {
export var addSpanPerformancePaintEvents = function (span) {
var _a, _b;
const performancePaintTiming = (_b = (_a = otperformance).getEntriesByType) === null || _b === void 0 ? void 0 : _b.call(_a, 'paint');
var performancePaintTiming = (_b = (_a = otperformance).getEntriesByType) === null || _b === void 0 ? void 0 : _b.call(_a, 'paint');
if (performancePaintTiming) {
performancePaintTiming.forEach(({ name, startTime }) => {
performancePaintTiming.forEach(function (_a) {
var name = _a.name, startTime = _a.startTime;
if (hasKey(performancePaintNames, name)) {

@@ -65,0 +66,0 @@ span.addEvent(performancePaintNames[name], startTime);

@@ -1,2 +0,2 @@

export declare const VERSION = "0.22.0";
export declare const VERSION = "0.23.0";
//# sourceMappingURL=version.d.ts.map

@@ -17,3 +17,3 @@ /*

// this is autogenerated file, see scripts/version-update.js
export const VERSION = '0.22.0';
export var VERSION = '0.23.0';
//# sourceMappingURL=version.js.map

@@ -69,3 +69,3 @@ "use strict";

_collectPerformance() {
const metaElement = [...document.getElementsByTagName('meta')].find(e => e.getAttribute('name') === core_1.TRACE_PARENT_HEADER);
const metaElement = Array.from(document.getElementsByTagName('meta')).find(e => e.getAttribute('name') === core_1.TRACE_PARENT_HEADER);
const entries = utils_1.getPerformanceNavigationEntries();

@@ -72,0 +72,0 @@ const traceparent = (metaElement && metaElement.content) || '';

@@ -1,2 +0,2 @@

export declare const VERSION = "0.22.0";
export declare const VERSION = "0.23.0";
//# sourceMappingURL=version.d.ts.map

@@ -20,3 +20,3 @@ "use strict";

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.22.0';
exports.VERSION = '0.23.0';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/instrumentation-document-load",
"version": "0.22.0",
"version": "0.23.0",
"description": "OpenTelemetry document-load automatic instrumentation package.",

@@ -50,11 +50,11 @@ "main": "build/src/index.js",

"peerDependencies": {
"@opentelemetry/api": "^1.0.0"
"@opentelemetry/api": "^1.0.1"
},
"devDependencies": {
"@babel/core": "7.14.5",
"@opentelemetry/api": "1.0.0",
"@babel/core": "7.14.6",
"@opentelemetry/api": "1.0.1",
"@types/mocha": "8.2.2",
"@types/node": "14.17.3",
"@types/node": "14.17.4",
"@types/sinon": "10.0.2",
"@types/webpack-env": "1.16.0",
"@types/webpack-env": "1.16.1",
"babel-loader": "8.2.2",

@@ -76,3 +76,3 @@ "codecov": "3.8.2",

"ts-mocha": "8.0.0",
"typescript": "4.3.2",
"typescript": "4.3.5",
"webpack": "4.46.0",

@@ -83,9 +83,9 @@ "webpack-cli": "4.7.2",

"dependencies": {
"@opentelemetry/core": "^0.22.0",
"@opentelemetry/instrumentation": "^0.22.0",
"@opentelemetry/semantic-conventions": "^0.22.0",
"@opentelemetry/tracing": "^0.22.0",
"@opentelemetry/web": "^0.22.0"
"@opentelemetry/core": "^0.23.0",
"@opentelemetry/instrumentation": "^0.23.0",
"@opentelemetry/semantic-conventions": "^0.23.0",
"@opentelemetry/tracing": "^0.23.0",
"@opentelemetry/web": "^0.23.0"
},
"gitHead": "a52deeca96cdd7e8b75734094ed84de075e9517d"
"gitHead": "eea5f3ef0382c3c8f6d5aca796e3babf7ad4a6c8"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc