@safaricom-mxl/web-sdk 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.cjs +21 -20
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.cjs.map +1 -1
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.js +17 -16
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.js.map +1 -1
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.cjs +32 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.cjs.map +1 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.d.cts +29 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.d.cts.map +1 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.d.ts +29 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.d.ts.map +1 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.js +31 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.js.map +1 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.cjs +34 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.cjs.map +1 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.d.cts +34 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.d.cts.map +1 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.d.ts +34 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.d.ts.map +1 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.js +31 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.js.map +1 -0
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.cjs +5 -5
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.cjs.map +1 -1
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.d.cts +1 -1
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.d.cts.map +1 -1
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.d.ts +1 -1
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.d.ts.map +1 -1
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.js +2 -1
- package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.js.map +1 -1
- package/dist/mxl-web-sdk.js +2 -2
- package/dist/mxl-web-sdk.js.map +1 -1
- package/dist/resources/sdkConstants.cjs +1 -1
- package/dist/resources/sdkConstants.cjs.map +1 -1
- package/dist/resources/sdkConstants.d.cts +1 -1
- package/dist/resources/sdkConstants.d.ts +1 -1
- package/dist/resources/sdkConstants.js +1 -1
- package/dist/resources/sdkConstants.js.map +1 -1
- package/dist/sdk/initSDK.cjs +1 -2
- package/dist/sdk/initSDK.cjs.map +1 -1
- package/dist/sdk/initSDK.d.cts.map +1 -1
- package/dist/sdk/initSDK.d.ts.map +1 -1
- package/dist/sdk/initSDK.js +1 -2
- package/dist/sdk/initSDK.js.map +1 -1
- package/package.json +14 -15
|
@@ -4,12 +4,13 @@ const require_constants_attributes = require("../../../constants/attributes.cjs"
|
|
|
4
4
|
const require_instrumentations_MXLInstrumentationBase_MXLInstrumentationBase = require("../../MXLInstrumentationBase/MXLInstrumentationBase.cjs");
|
|
5
5
|
const require_utils_performanceObserver_performanceObserver = require("../../../utils/performanceObserver/performanceObserver.cjs");
|
|
6
6
|
require("./enums/AttributeNames.cjs");
|
|
7
|
+
require("./enums/PerformanceTimingNames.cjs");
|
|
8
|
+
const require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents = require("./networkEvents.cjs");
|
|
7
9
|
const require_instrumentations_document_load_DocumentLoadInstrumentation_utils = require("./utils.cjs");
|
|
8
10
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
9
11
|
let _opentelemetry_core = require("@opentelemetry/core");
|
|
10
12
|
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
11
13
|
let _opentelemetry_instrumentation = require("@opentelemetry/instrumentation");
|
|
12
|
-
let _opentelemetry_sdk_trace_web = require("@opentelemetry/sdk-trace-web");
|
|
13
14
|
let _opentelemetry_semantic_conventions_incubating = require("@opentelemetry/semantic-conventions/incubating");
|
|
14
15
|
//#region src/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.ts
|
|
15
16
|
const ATTR_HTTP_RESPONSE_DELIVERY_TYPE = "http.response.delivery_type";
|
|
@@ -81,21 +82,21 @@ var DocumentLoadInstrumentation = class extends require_instrumentations_MXLInst
|
|
|
81
82
|
const entries = require_instrumentations_document_load_DocumentLoadInstrumentation_utils.getPerformanceNavigationEntries();
|
|
82
83
|
const traceparent = metaElement?.content || "";
|
|
83
84
|
_opentelemetry_api.context.with(_opentelemetry_api.propagation.extract(_opentelemetry_api.ROOT_CONTEXT, { traceparent }), () => {
|
|
84
|
-
const rootSpan = this._startSpan("documentLoad",
|
|
85
|
+
const rootSpan = this._startSpan("documentLoad", "fetchStart", entries);
|
|
85
86
|
if (!rootSpan) {
|
|
86
87
|
this._diag.warn("navigation entry has no fetchStart, document load will not be collected");
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
90
|
_opentelemetry_api.context.with(_opentelemetry_api.trace.setSpan(_opentelemetry_api.context.active(), rootSpan), () => {
|
|
90
|
-
const fetchSpan = this._startSpan("documentFetch",
|
|
91
|
+
const fetchSpan = this._startSpan("documentFetch", "fetchStart", entries);
|
|
91
92
|
if (fetchSpan) {
|
|
92
93
|
fetchSpan.setAttribute(_opentelemetry_semantic_conventions_incubating.ATTR_URL_FULL, location.href);
|
|
93
94
|
_opentelemetry_api.context.with(_opentelemetry_api.trace.setSpan(_opentelemetry_api.context.active(), fetchSpan), () => {
|
|
94
|
-
|
|
95
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvents(fetchSpan, entries, this.getConfig().ignoreNetworkEvents);
|
|
95
96
|
this._addResourceAttributesToSpan(fetchSpan, entries);
|
|
96
97
|
this._addNavigationTimingAttributesToSpan(fetchSpan, entries);
|
|
97
98
|
this._addCustomAttributesOnSpan(fetchSpan, this.getConfig().applyCustomAttributesOnSpan?.documentFetch);
|
|
98
|
-
this._endSpan(fetchSpan,
|
|
99
|
+
this._endSpan(fetchSpan, "responseEnd", entries);
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
});
|
|
@@ -104,19 +105,19 @@ var DocumentLoadInstrumentation = class extends require_instrumentations_MXLInst
|
|
|
104
105
|
rootSpan.setAttribute(_opentelemetry_semantic_conventions_incubating.ATTR_USER_AGENT_ORIGINAL, navigator.userAgent);
|
|
105
106
|
this._addResourcesSpans(rootSpan);
|
|
106
107
|
if (!this.getConfig().ignoreNetworkEvents) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvent(rootSpan, "fetchStart", entries);
|
|
109
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvent(rootSpan, "unloadEventStart", entries);
|
|
110
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvent(rootSpan, "unloadEventEnd", entries);
|
|
111
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvent(rootSpan, "domInteractive", entries);
|
|
112
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvent(rootSpan, "domContentLoadedEventStart", entries);
|
|
113
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvent(rootSpan, "domContentLoadedEventEnd", entries);
|
|
114
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvent(rootSpan, "domComplete", entries);
|
|
115
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvent(rootSpan, "loadEventStart", entries);
|
|
116
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvent(rootSpan, "loadEventEnd", entries);
|
|
116
117
|
}
|
|
117
118
|
if (!this.getConfig().ignorePerformancePaintEvents) require_instrumentations_document_load_DocumentLoadInstrumentation_utils.addSpanPerformancePaintEvents(rootSpan, this.perf);
|
|
118
119
|
this._addCustomAttributesOnSpan(rootSpan, this.getConfig().applyCustomAttributesOnSpan?.documentLoad);
|
|
119
|
-
this._endSpan(rootSpan,
|
|
120
|
+
this._endSpan(rootSpan, "loadEventEnd", entries);
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
123
|
/**
|
|
@@ -126,7 +127,7 @@ var DocumentLoadInstrumentation = class extends require_instrumentations_MXLInst
|
|
|
126
127
|
* @param entries
|
|
127
128
|
*/
|
|
128
129
|
_endSpan(span, performanceName, entries) {
|
|
129
|
-
if (span) if (
|
|
130
|
+
if (span) if (require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.hasKey(entries, performanceName) && typeof entries[performanceName] === "number") span.end(this.perf.epochMillisFromOriginOffset(entries[performanceName]));
|
|
130
131
|
else span.end();
|
|
131
132
|
}
|
|
132
133
|
/**
|
|
@@ -135,14 +136,14 @@ var DocumentLoadInstrumentation = class extends require_instrumentations_MXLInst
|
|
|
135
136
|
* @param parentSpan
|
|
136
137
|
*/
|
|
137
138
|
_initResourceSpan(resource, parentSpan) {
|
|
138
|
-
const span = this._startSpan("resourceFetch",
|
|
139
|
+
const span = this._startSpan("resourceFetch", "fetchStart", resource, parentSpan);
|
|
139
140
|
if (!span) return;
|
|
140
141
|
span.setAttribute(_opentelemetry_semantic_conventions_incubating.ATTR_URL_FULL, resource.name);
|
|
141
|
-
|
|
142
|
+
require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.addSpanNetworkEvents(span, resource, this.getConfig().ignoreNetworkEvents);
|
|
142
143
|
this._addResourceAttributesToSpan(span, resource);
|
|
143
144
|
this._addResourceDiagnosticAttributes(span, resource);
|
|
144
145
|
this._addCustomAttributesOnResourceSpan(span, resource, this.getConfig().applyCustomAttributesOnSpan?.resourceFetch);
|
|
145
|
-
this._endSpan(span,
|
|
146
|
+
this._endSpan(span, "responseEnd", resource);
|
|
146
147
|
}
|
|
147
148
|
/**
|
|
148
149
|
* Helper function for starting a span
|
|
@@ -152,7 +153,7 @@ var DocumentLoadInstrumentation = class extends require_instrumentations_MXLInst
|
|
|
152
153
|
* @param parentSpan
|
|
153
154
|
*/
|
|
154
155
|
_startSpan(spanName, performanceName, entries, parentSpan) {
|
|
155
|
-
if (
|
|
156
|
+
if (require_instrumentations_document_load_DocumentLoadInstrumentation_networkEvents.hasKey(entries, performanceName) && typeof entries[performanceName] === "number") return this.tracer.startSpan(spanName, { startTime: this.perf.epochMillisFromOriginOffset(entries[performanceName]) }, parentSpan ? _opentelemetry_api.trace.setSpan(_opentelemetry_api.context.active(), parentSpan) : void 0);
|
|
156
157
|
}
|
|
157
158
|
/**
|
|
158
159
|
* Adds custom attributes to span if configured
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentLoadInstrumentation.cjs","names":["MXLInstrumentationBase","TRACE_PARENT_HEADER","getPerformanceNavigationEntries","propagation","ROOT_CONTEXT","PerformanceTimingNames","trace","context","ATTR_URL_FULL","KEY_MXL_TYPE","ATTR_USER_AGENT_ORIGINAL","ATTR_HTTP_RESPONSE_STATUS_CODE","ATTR_HTTP_RESPONSE_BODY_SIZE","ATTR_HTTP_RESPONSE_SIZE","KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS","createPerformanceObserver"],"sources":["../../../../src/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.ts"],"sourcesContent":["/*\n * Adapted from OpenTelemetry document-load instrumentation\n * https://github.com/open-telemetry/opentelemetry-js-contrib/tree/cc7eff47e2e7bad7678241b766753d5bd6dbc85f/packages/instrumentation-document-load\n *\n * Additional PerformanceResourceTiming attributes collected:\n * - entry_type, initiator_type\n * - decoded_body_size, http.response.body.size, http.response.size\n * - delivery_type (Chromium only)\n * - render_blocking_status (Chromium only)\n * - http.response.status_code (no Safari support)\n *\n * Custom diagnostic attributes added to identify resource loading issues:\n * - http.response.cors_opaque - CORS-restricted resource (opaque response)\n * - http.response.cache_revalidated - 304 Not Modified response\n * - http.request.incomplete - Request started but didn't complete (network error, aborted)\n * - http.request.prevented - Request never started (blocked by CSP, browser, extension)\n *\n * Navigation-only attributes added to the document fetch span:\n * - browser.navigation_timing.type\n * - browser.navigation_timing.not_restored_reasons\n */\n\nimport type { Span } from '@opentelemetry/api';\nimport { ROOT_CONTEXT, context, propagation, trace } from '@opentelemetry/api';\nimport { TRACE_PARENT_HEADER } from '@opentelemetry/core';\nimport { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport type { PerformanceEntries } from '@opentelemetry/sdk-trace-web';\nimport {\n PerformanceTimingNames,\n addSpanNetworkEvent,\n addSpanNetworkEvents,\n hasKey,\n} from '@opentelemetry/sdk-trace-web';\nimport { ATTR_HTTP_RESPONSE_STATUS_CODE } from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_HTTP_RESPONSE_BODY_SIZE,\n ATTR_HTTP_RESPONSE_SIZE,\n ATTR_URL_FULL,\n ATTR_USER_AGENT_ORIGINAL,\n} from '@opentelemetry/semantic-conventions/incubating';\nimport {\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n KEY_MXL_TYPE,\n MXL_TYPES,\n} from '../../../constants/attributes';\nimport { createPerformanceObserver } from '../../../utils/performanceObserver/performanceObserver';\nimport { MXLInstrumentationBase } from '../../MXLInstrumentationBase/MXLInstrumentationBase';\nimport { AttributeNames } from './enums/AttributeNames';\nimport type {\n DocumentLoadCustomAttributeFunction,\n DocumentLoadInstrumentationConfig,\n ResourceFetchCustomAttributeFunction,\n} from './types';\nimport type {\n MXLPerformanceNavigationEntries,\n MXLPerformanceResourceTiming,\n} from './utils';\nimport {\n addSpanPerformancePaintEvents,\n getPerformanceNavigationEntries,\n} from './utils';\n\ntype ResourceSpanData = {\n deliveryType?: 'cache' | '';\n initiatorType?: string;\n renderBlockingStatus?: 'blocking' | 'non-blocking';\n responseStatus?: number;\n encodedBodySize?: number;\n transferSize?: number;\n decodedBodySize?: number;\n};\n\n// PerformanceResourceTiming attribute names\nconst ATTR_HTTP_RESPONSE_DELIVERY_TYPE = 'http.response.delivery_type';\nconst ATTR_HTTP_RESPONSE_DECODED_BODY_SIZE = 'http.response.decoded_body_size';\nconst ATTR_HTTP_REQUEST_INITIATOR_TYPE = 'http.request.initiator_type';\nconst ATTR_HTTP_REQUEST_RENDER_BLOCKING_STATUS =\n 'http.request.render_blocking_status';\n\n// Diagnostic attribute names\nconst ATTR_HTTP_RESPONSE_CORS_OPAQUE = 'http.response.cors_opaque'; // CORS-restricted resource (opaque response)\nconst ATTR_HTTP_RESPONSE_CACHE_REVALIDATED = 'http.response.cache_revalidated'; // 304 Not Modified response\nconst ATTR_HTTP_REQUEST_INCOMPLETE = 'http.request.incomplete'; // Request started but didn't complete\nconst ATTR_HTTP_REQUEST_PREVENTED = 'http.request.prevented'; // Request never started (blocked)\nconst ATTR_BROWSER_NAVIGATION_TIMING_TYPE = 'browser.navigation_timing.type';\n\nexport class DocumentLoadInstrumentation extends MXLInstrumentationBase<DocumentLoadInstrumentationConfig> {\n private _navigationObserver: PerformanceObserver | null = null;\n private _performanceCollected = false;\n\n public constructor({\n diag,\n perf,\n enabled,\n applyCustomAttributesOnSpan,\n ignorePerformancePaintEvents = false,\n ignoreNetworkEvents = false,\n }: DocumentLoadInstrumentationConfig = {}) {\n super({\n config: {\n applyCustomAttributesOnSpan,\n enabled,\n ignoreNetworkEvents,\n ignorePerformancePaintEvents,\n },\n diag,\n instrumentationName: 'DocumentLoadInstrumentation',\n instrumentationVersion: '1.0.0',\n perf,\n });\n\n if (this._config.enabled) {\n this.enable();\n }\n }\n\n /**\n * Adds spans for all resources\n * @param rootSpan\n */\n private _addResourcesSpans(rootSpan: Span): void {\n const resources: MXLPerformanceResourceTiming[] =\n performance.getEntriesByType('resource');\n resources.forEach((resource) => {\n this._initResourceSpan(resource, rootSpan);\n });\n }\n\n /**\n * The one navigation entry per document is mutated in place as the load\n * progresses, so collecting early would end the documentLoad span at time\n * origin. Returning early leaves the observer subscribed for a later\n * notification.\n */\n private _collectIfLoadEventFinished(): void {\n if (this._performanceCollected || !this._isLoadEventFinished()) {\n return;\n }\n\n // Latched before collecting so a throw part way through cannot emit a\n // second set of spans on a later trigger.\n this._performanceCollected = true;\n\n try {\n this._collectPerformance();\n } catch (error) {\n this._diag.error('failed to collect the document load', error);\n } finally {\n this._disconnectObserver();\n }\n }\n\n // LoadEventEnd is written only after every load handler returns. WebKit\n // reports no entry at all for about:blank, popups and srcdoc iframes.\n private _isLoadEventFinished(): boolean {\n const [navigationTiming] = performance.getEntriesByType('navigation');\n return (\n ((navigationTiming as PerformanceNavigationTiming | undefined)\n ?.loadEventEnd ?? 0) > 0\n );\n }\n\n private _disconnectObserver(): void {\n this._navigationObserver?.disconnect();\n this._navigationObserver = null;\n }\n\n /**\n * Collects information about performance and creates appropriate spans\n */\n private _collectPerformance(): void {\n const metaElement = [...document.getElementsByTagName('meta')].find(\n (e) => e.getAttribute('name') === TRACE_PARENT_HEADER,\n );\n const entries = getPerformanceNavigationEntries();\n const traceparent = metaElement?.content || '';\n context.with(propagation.extract(ROOT_CONTEXT, { traceparent }), () => {\n const rootSpan = this._startSpan(\n AttributeNames.DOCUMENT_LOAD,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n if (!rootSpan) {\n this._diag.warn(\n 'navigation entry has no fetchStart, document load will not be collected',\n );\n return;\n }\n context.with(trace.setSpan(context.active(), rootSpan), () => {\n const fetchSpan = this._startSpan(\n AttributeNames.DOCUMENT_FETCH,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n if (fetchSpan) {\n fetchSpan.setAttribute(ATTR_URL_FULL, location.href);\n context.with(trace.setSpan(context.active(), fetchSpan), () => {\n addSpanNetworkEvents(\n fetchSpan,\n entries,\n this.getConfig().ignoreNetworkEvents,\n );\n this._addResourceAttributesToSpan(fetchSpan, entries);\n this._addNavigationTimingAttributesToSpan(fetchSpan, entries);\n this._addCustomAttributesOnSpan(\n fetchSpan,\n this.getConfig().applyCustomAttributesOnSpan?.documentFetch,\n );\n this._endSpan(\n fetchSpan,\n PerformanceTimingNames.RESPONSE_END,\n entries,\n );\n });\n }\n });\n\n rootSpan.setAttribute(KEY_MXL_TYPE, MXL_TYPES.DocumentLoad);\n rootSpan.setAttribute(ATTR_URL_FULL, location.href);\n rootSpan.setAttribute(ATTR_USER_AGENT_ORIGINAL, navigator.userAgent);\n\n this._addResourcesSpans(rootSpan);\n\n if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.UNLOAD_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.UNLOAD_EVENT_END,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_INTERACTIVE,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_END,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_COMPLETE,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.LOAD_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.LOAD_EVENT_END,\n entries,\n );\n }\n\n if (!this.getConfig().ignorePerformancePaintEvents) {\n addSpanPerformancePaintEvents(rootSpan, this.perf);\n }\n\n this._addCustomAttributesOnSpan(\n rootSpan,\n this.getConfig().applyCustomAttributesOnSpan?.documentLoad,\n );\n this._endSpan(rootSpan, PerformanceTimingNames.LOAD_EVENT_END, entries);\n });\n }\n\n /**\n * Helper function for ending a span\n * @param span\n * @param performanceName name of performance entry for end time\n * @param entries\n */\n private _endSpan(\n span: Span | undefined,\n performanceName: string,\n entries: PerformanceEntries,\n ) {\n // Span can be undefined when entries are missing the required performance timing - no span will be created\n if (span) {\n if (\n hasKey(entries, performanceName) &&\n typeof entries[performanceName] === 'number'\n ) {\n span.end(\n this.perf.epochMillisFromOriginOffset(entries[performanceName]),\n );\n } else {\n span.end();\n }\n }\n }\n\n /**\n * Creates and ends a span with network information about a resource added as timed events\n * @param resource\n * @param parentSpan\n */\n private _initResourceSpan(\n resource: MXLPerformanceResourceTiming,\n parentSpan: Span,\n ) {\n const span = this._startSpan(\n AttributeNames.RESOURCE_FETCH,\n PerformanceTimingNames.FETCH_START,\n resource,\n parentSpan,\n );\n if (!span) {\n return;\n }\n\n span.setAttribute(ATTR_URL_FULL, resource.name);\n addSpanNetworkEvents(span, resource, this.getConfig().ignoreNetworkEvents);\n\n this._addResourceAttributesToSpan(span, resource);\n this._addResourceDiagnosticAttributes(span, resource);\n\n this._addCustomAttributesOnResourceSpan(\n span,\n resource,\n this.getConfig().applyCustomAttributesOnSpan?.resourceFetch,\n );\n this._endSpan(span, PerformanceTimingNames.RESPONSE_END, resource);\n }\n\n /**\n * Helper function for starting a span\n * @param spanName name of span\n * @param performanceName name of performance entry for time start\n * @param entries\n * @param parentSpan\n */\n private _startSpan(\n spanName: string,\n performanceName: string,\n entries: PerformanceEntries,\n parentSpan?: Span,\n ): Span | undefined {\n if (\n hasKey(entries, performanceName) &&\n typeof entries[performanceName] === 'number'\n ) {\n const span = this.tracer.startSpan(\n spanName,\n {\n startTime: this.perf.epochMillisFromOriginOffset(\n entries[performanceName],\n ),\n },\n parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined,\n );\n return span;\n }\n return undefined;\n }\n\n /**\n * Adds custom attributes to span if configured\n * Used for both documentFetch and documentLoad spans\n */\n private _addCustomAttributesOnSpan(\n span: Span,\n applyCustomAttributesOnSpan:\n | DocumentLoadCustomAttributeFunction\n | undefined,\n ) {\n if (applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () => {\n applyCustomAttributesOnSpan(span);\n },\n (error) => {\n if (!error) {\n return;\n }\n\n this._diag.error('addCustomAttributesOnSpan', error);\n },\n true,\n );\n }\n }\n\n private _addResourceAttributesToSpan(\n span: Span,\n resource: ResourceSpanData,\n ): void {\n span.setAttribute(KEY_MXL_TYPE, MXL_TYPES.ResourceFetch);\n\n if (resource.deliveryType) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_DELIVERY_TYPE,\n resource.deliveryType,\n );\n }\n\n if (resource.initiatorType) {\n span.setAttribute(\n ATTR_HTTP_REQUEST_INITIATOR_TYPE,\n resource.initiatorType,\n );\n }\n\n if (resource.renderBlockingStatus) {\n span.setAttribute(\n ATTR_HTTP_REQUEST_RENDER_BLOCKING_STATUS,\n resource.renderBlockingStatus,\n );\n }\n\n if (resource.responseStatus) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n resource.responseStatus,\n );\n }\n\n if (resource.encodedBodySize !== undefined) {\n span.setAttribute(ATTR_HTTP_RESPONSE_BODY_SIZE, resource.encodedBodySize);\n }\n\n if (resource.transferSize !== undefined) {\n span.setAttribute(ATTR_HTTP_RESPONSE_SIZE, resource.transferSize);\n }\n\n if (resource.decodedBodySize !== undefined) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_DECODED_BODY_SIZE,\n resource.decodedBodySize,\n );\n }\n }\n\n private _addNavigationTimingAttributesToSpan(\n span: Span,\n entries: MXLPerformanceNavigationEntries,\n ): void {\n if (entries.type) {\n span.setAttribute(ATTR_BROWSER_NAVIGATION_TIMING_TYPE, entries.type);\n }\n\n if (entries.notRestoredReasons?.length) {\n span.setAttribute(\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n entries.notRestoredReasons,\n );\n }\n }\n\n /**\n * Adds custom attributes to resource span if configured\n */\n private _addCustomAttributesOnResourceSpan(\n span: Span,\n resource: MXLPerformanceResourceTiming,\n applyCustomAttributesOnSpan:\n | ResourceFetchCustomAttributeFunction\n | undefined,\n ) {\n if (applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () => {\n applyCustomAttributesOnSpan(span, resource);\n },\n (error) => {\n if (!error) {\n return;\n }\n\n this._diag.error('addCustomAttributesOnResourceSpan', error);\n },\n true,\n );\n }\n }\n\n private _hasNoSizeData(resource: MXLPerformanceResourceTiming): boolean {\n return (\n resource.transferSize === 0 &&\n resource.decodedBodySize === 0 &&\n resource.encodedBodySize === 0\n );\n }\n\n private _hasTimingData(resource: MXLPerformanceResourceTiming): boolean {\n return resource.fetchStart > 0 && resource.responseEnd > 0;\n }\n\n private _isCorsRestricted(resource: MXLPerformanceResourceTiming): boolean {\n return this._hasNoSizeData(resource) && this._hasTimingData(resource);\n }\n\n private _isFetchIncomplete(resource: MXLPerformanceResourceTiming): boolean {\n return (\n this._hasNoSizeData(resource) &&\n resource.fetchStart > 0 &&\n resource.responseEnd === 0\n );\n }\n\n private _isFetchPrevented(resource: MXLPerformanceResourceTiming): boolean {\n return this._hasNoSizeData(resource) && resource.fetchStart === 0;\n }\n\n /**\n * Detect cache validation (304 Not Modified responses)\n *\n * 304 responses show transferSize of ~300 bytes (headers only, no body).\n * Use deliveryType to distinguish from cache hits: 'cache' = no network, otherwise = 304.\n *\n * Spec: https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-transfersize\n */\n private _isCacheValidated(resource: MXLPerformanceResourceTiming): boolean {\n // DeliveryType is Chromium only, so an engine without it never reads 'cache'.\n return resource.transferSize === 300 && resource.deliveryType !== 'cache';\n }\n\n /**\n * Add diagnostic attributes to identify resource loading issues\n *\n * Diagnostic attributes help identify why resources may have incomplete timing data:\n * - CORS restrictions (opaque responses without Timing-Allow-Origin header)\n * - Cache revalidation (304 Not Modified responses)\n * - Request incomplete (started but didn't complete - network error, aborted)\n * - Request prevented (never started - blocked by CSP, browser, extension)\n *\n * The size and timing fields read below are always numbers: a cross-origin\n * resource with no Timing-Allow-Origin reports them as 0 rather than omitting\n * them, and a resource only reaches here once it has produced a span, which\n * required a numeric fetchStart.\n */\n private _addResourceDiagnosticAttributes(\n span: Span,\n resource: MXLPerformanceResourceTiming,\n ): void {\n if (this._isCorsRestricted(resource)) {\n span.setAttribute(ATTR_HTTP_RESPONSE_CORS_OPAQUE, true);\n } else if (this._isFetchIncomplete(resource)) {\n span.setAttribute(ATTR_HTTP_REQUEST_INCOMPLETE, true);\n } else if (this._isFetchPrevented(resource)) {\n span.setAttribute(ATTR_HTTP_REQUEST_PREVENTED, true);\n }\n\n if (this._isCacheValidated(resource)) {\n span.setAttribute(ATTR_HTTP_RESPONSE_CACHE_REVALIDATED, true);\n }\n }\n\n protected override onEnable(): void {\n // An unbuffered subscription registered after the load event is never\n // notified, so collect straight away instead of observing. Deferred a\n // microtask because under registerGlobally: false the tracer provider\n // arrives later in this same task, and earlier spans reach a no-op tracer.\n if (this._isLoadEventFinished()) {\n queueMicrotask(() => {\n if (this._isEnabled) {\n this._collectIfLoadEventFinished();\n }\n });\n return;\n }\n\n // Buffered must stay false: mid-load, WebKit answers a buffered\n // subscription with the unfinished entry and counts it as the observer's\n // one notification, so the finalized entry never arrives.\n this._navigationObserver = createPerformanceObserver(\n 'navigation',\n () => {\n this._collectIfLoadEventFinished();\n },\n { buffered: false, diag: this._diag },\n );\n\n if (!this._navigationObserver) {\n this._diag.warn(\n 'navigation entries are not observable, document load will not be collected',\n );\n }\n }\n\n protected override onDisable(): void {\n this._disconnectObserver();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAyEA,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,mCAAmC;AACzC,MAAM,2CACJ;AAGF,MAAM,iCAAiC;AACvC,MAAM,uCAAuC;AAC7C,MAAM,+BAA+B;AACrC,MAAM,8BAA8B;AACpC,MAAM,sCAAsC;AAE5C,IAAa,8BAAb,cAAiDA,uEAAAA,uBAA0D;CACzG,sBAA0D;CAC1D,wBAAgC;CAEhC,YAAmB,EACjB,MACA,MACA,SACA,6BACA,+BAA+B,OAC/B,sBAAsB,UACe,EAAE,EAAE;AACzC,QAAM;GACJ,QAAQ;IACN;IACA;IACA;IACA;IACD;GACD;GACA,qBAAqB;GACrB,wBAAwB;GACxB;GACD,CAAC;AAEF,MAAI,KAAK,QAAQ,QACf,MAAK,QAAQ;;;;;;CAQjB,mBAA2B,UAAsB;AAE7C,cAAY,iBAAiB,WACtB,CAAC,SAAS,aAAa;AAC9B,QAAK,kBAAkB,UAAU,SAAS;IAC1C;;;;;;;;CASJ,8BAA4C;AAC1C,MAAI,KAAK,yBAAyB,CAAC,KAAK,sBAAsB,CAC5D;AAKF,OAAK,wBAAwB;AAE7B,MAAI;AACF,QAAK,qBAAqB;WACnB,OAAO;AACd,QAAK,MAAM,MAAM,uCAAuC,MAAM;YACtD;AACR,QAAK,qBAAqB;;;CAM9B,uBAAwC;EACtC,MAAM,CAAC,oBAAoB,YAAY,iBAAiB,aAAa;AACrE,UACI,kBACE,gBAAgB,KAAK;;CAI7B,sBAAoC;AAClC,OAAK,qBAAqB,YAAY;AACtC,OAAK,sBAAsB;;;;;CAM7B,sBAAoC;EAClC,MAAM,cAAc,CAAC,GAAG,SAAS,qBAAqB,OA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,qBAAqB"}
|
|
1
|
+
{"version":3,"file":"DocumentLoadInstrumentation.cjs","names":["MXLInstrumentationBase","TRACE_PARENT_HEADER","getPerformanceNavigationEntries","propagation","ROOT_CONTEXT","trace","context","ATTR_URL_FULL","KEY_MXL_TYPE","ATTR_USER_AGENT_ORIGINAL","hasKey","ATTR_HTTP_RESPONSE_STATUS_CODE","ATTR_HTTP_RESPONSE_BODY_SIZE","ATTR_HTTP_RESPONSE_SIZE","KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS","createPerformanceObserver"],"sources":["../../../../src/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.ts"],"sourcesContent":["/*\n * Adapted from OpenTelemetry document-load instrumentation\n * https://github.com/open-telemetry/opentelemetry-js-contrib/tree/cc7eff47e2e7bad7678241b766753d5bd6dbc85f/packages/instrumentation-document-load\n *\n * Additional PerformanceResourceTiming attributes collected:\n * - entry_type, initiator_type\n * - decoded_body_size, http.response.body.size, http.response.size\n * - delivery_type (Chromium only)\n * - render_blocking_status (Chromium only)\n * - http.response.status_code (no Safari support)\n *\n * Custom diagnostic attributes added to identify resource loading issues:\n * - http.response.cors_opaque - CORS-restricted resource (opaque response)\n * - http.response.cache_revalidated - 304 Not Modified response\n * - http.request.incomplete - Request started but didn't complete (network error, aborted)\n * - http.request.prevented - Request never started (blocked by CSP, browser, extension)\n *\n * Navigation-only attributes added to the document fetch span:\n * - browser.navigation_timing.type\n * - browser.navigation_timing.not_restored_reasons\n */\n\nimport type { Span } from '@opentelemetry/api';\nimport { ROOT_CONTEXT, context, propagation, trace } from '@opentelemetry/api';\nimport { TRACE_PARENT_HEADER } from '@opentelemetry/core';\nimport { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport { ATTR_HTTP_RESPONSE_STATUS_CODE } from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_HTTP_RESPONSE_BODY_SIZE,\n ATTR_HTTP_RESPONSE_SIZE,\n ATTR_URL_FULL,\n ATTR_USER_AGENT_ORIGINAL,\n} from '@opentelemetry/semantic-conventions/incubating';\nimport {\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n KEY_MXL_TYPE,\n MXL_TYPES,\n} from '../../../constants/attributes';\nimport { createPerformanceObserver } from '../../../utils/performanceObserver/performanceObserver';\nimport { MXLInstrumentationBase } from '../../MXLInstrumentationBase/MXLInstrumentationBase';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { PerformanceTimingNames } from './enums/PerformanceTimingNames';\nimport type { PerformanceEntries } from './networkEvents';\nimport {\n addSpanNetworkEvent,\n addSpanNetworkEvents,\n hasKey,\n} from './networkEvents';\nimport type {\n DocumentLoadCustomAttributeFunction,\n DocumentLoadInstrumentationConfig,\n ResourceFetchCustomAttributeFunction,\n} from './types';\nimport type {\n MXLPerformanceNavigationEntries,\n MXLPerformanceResourceTiming,\n} from './utils';\nimport {\n addSpanPerformancePaintEvents,\n getPerformanceNavigationEntries,\n} from './utils';\n\ntype ResourceSpanData = {\n deliveryType?: 'cache' | '';\n initiatorType?: string;\n renderBlockingStatus?: 'blocking' | 'non-blocking';\n responseStatus?: number;\n encodedBodySize?: number;\n transferSize?: number;\n decodedBodySize?: number;\n};\n\n// PerformanceResourceTiming attribute names\nconst ATTR_HTTP_RESPONSE_DELIVERY_TYPE = 'http.response.delivery_type';\nconst ATTR_HTTP_RESPONSE_DECODED_BODY_SIZE = 'http.response.decoded_body_size';\nconst ATTR_HTTP_REQUEST_INITIATOR_TYPE = 'http.request.initiator_type';\nconst ATTR_HTTP_REQUEST_RENDER_BLOCKING_STATUS =\n 'http.request.render_blocking_status';\n\n// Diagnostic attribute names\nconst ATTR_HTTP_RESPONSE_CORS_OPAQUE = 'http.response.cors_opaque'; // CORS-restricted resource (opaque response)\nconst ATTR_HTTP_RESPONSE_CACHE_REVALIDATED = 'http.response.cache_revalidated'; // 304 Not Modified response\nconst ATTR_HTTP_REQUEST_INCOMPLETE = 'http.request.incomplete'; // Request started but didn't complete\nconst ATTR_HTTP_REQUEST_PREVENTED = 'http.request.prevented'; // Request never started (blocked)\nconst ATTR_BROWSER_NAVIGATION_TIMING_TYPE = 'browser.navigation_timing.type';\n\nexport class DocumentLoadInstrumentation extends MXLInstrumentationBase<DocumentLoadInstrumentationConfig> {\n private _navigationObserver: PerformanceObserver | null = null;\n private _performanceCollected = false;\n\n public constructor({\n diag,\n perf,\n enabled,\n applyCustomAttributesOnSpan,\n ignorePerformancePaintEvents = false,\n ignoreNetworkEvents = false,\n }: DocumentLoadInstrumentationConfig = {}) {\n super({\n config: {\n applyCustomAttributesOnSpan,\n enabled,\n ignoreNetworkEvents,\n ignorePerformancePaintEvents,\n },\n diag,\n instrumentationName: 'DocumentLoadInstrumentation',\n instrumentationVersion: '1.0.0',\n perf,\n });\n\n if (this._config.enabled) {\n this.enable();\n }\n }\n\n /**\n * Adds spans for all resources\n * @param rootSpan\n */\n private _addResourcesSpans(rootSpan: Span): void {\n const resources: MXLPerformanceResourceTiming[] =\n performance.getEntriesByType('resource');\n resources.forEach((resource) => {\n this._initResourceSpan(resource, rootSpan);\n });\n }\n\n /**\n * The one navigation entry per document is mutated in place as the load\n * progresses, so collecting early would end the documentLoad span at time\n * origin. Returning early leaves the observer subscribed for a later\n * notification.\n */\n private _collectIfLoadEventFinished(): void {\n if (this._performanceCollected || !this._isLoadEventFinished()) {\n return;\n }\n\n // Latched before collecting so a throw part way through cannot emit a\n // second set of spans on a later trigger.\n this._performanceCollected = true;\n\n try {\n this._collectPerformance();\n } catch (error) {\n this._diag.error('failed to collect the document load', error);\n } finally {\n this._disconnectObserver();\n }\n }\n\n // LoadEventEnd is written only after every load handler returns. WebKit\n // reports no entry at all for about:blank, popups and srcdoc iframes.\n private _isLoadEventFinished(): boolean {\n const [navigationTiming] = performance.getEntriesByType('navigation');\n return (\n ((navigationTiming as PerformanceNavigationTiming | undefined)\n ?.loadEventEnd ?? 0) > 0\n );\n }\n\n private _disconnectObserver(): void {\n this._navigationObserver?.disconnect();\n this._navigationObserver = null;\n }\n\n /**\n * Collects information about performance and creates appropriate spans\n */\n private _collectPerformance(): void {\n const metaElement = [...document.getElementsByTagName('meta')].find(\n (e) => e.getAttribute('name') === TRACE_PARENT_HEADER,\n );\n const entries = getPerformanceNavigationEntries();\n const traceparent = metaElement?.content || '';\n context.with(propagation.extract(ROOT_CONTEXT, { traceparent }), () => {\n const rootSpan = this._startSpan(\n AttributeNames.DOCUMENT_LOAD,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n if (!rootSpan) {\n this._diag.warn(\n 'navigation entry has no fetchStart, document load will not be collected',\n );\n return;\n }\n context.with(trace.setSpan(context.active(), rootSpan), () => {\n const fetchSpan = this._startSpan(\n AttributeNames.DOCUMENT_FETCH,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n if (fetchSpan) {\n fetchSpan.setAttribute(ATTR_URL_FULL, location.href);\n context.with(trace.setSpan(context.active(), fetchSpan), () => {\n addSpanNetworkEvents(\n fetchSpan,\n entries,\n this.getConfig().ignoreNetworkEvents,\n );\n this._addResourceAttributesToSpan(fetchSpan, entries);\n this._addNavigationTimingAttributesToSpan(fetchSpan, entries);\n this._addCustomAttributesOnSpan(\n fetchSpan,\n this.getConfig().applyCustomAttributesOnSpan?.documentFetch,\n );\n this._endSpan(\n fetchSpan,\n PerformanceTimingNames.RESPONSE_END,\n entries,\n );\n });\n }\n });\n\n rootSpan.setAttribute(KEY_MXL_TYPE, MXL_TYPES.DocumentLoad);\n rootSpan.setAttribute(ATTR_URL_FULL, location.href);\n rootSpan.setAttribute(ATTR_USER_AGENT_ORIGINAL, navigator.userAgent);\n\n this._addResourcesSpans(rootSpan);\n\n if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.UNLOAD_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.UNLOAD_EVENT_END,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_INTERACTIVE,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_END,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_COMPLETE,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.LOAD_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.LOAD_EVENT_END,\n entries,\n );\n }\n\n if (!this.getConfig().ignorePerformancePaintEvents) {\n addSpanPerformancePaintEvents(rootSpan, this.perf);\n }\n\n this._addCustomAttributesOnSpan(\n rootSpan,\n this.getConfig().applyCustomAttributesOnSpan?.documentLoad,\n );\n this._endSpan(rootSpan, PerformanceTimingNames.LOAD_EVENT_END, entries);\n });\n }\n\n /**\n * Helper function for ending a span\n * @param span\n * @param performanceName name of performance entry for end time\n * @param entries\n */\n private _endSpan(\n span: Span | undefined,\n performanceName: string,\n entries: PerformanceEntries,\n ) {\n // Span can be undefined when entries are missing the required performance timing - no span will be created\n if (span) {\n if (\n hasKey(entries, performanceName) &&\n typeof entries[performanceName] === 'number'\n ) {\n span.end(\n this.perf.epochMillisFromOriginOffset(entries[performanceName]),\n );\n } else {\n span.end();\n }\n }\n }\n\n /**\n * Creates and ends a span with network information about a resource added as timed events\n * @param resource\n * @param parentSpan\n */\n private _initResourceSpan(\n resource: MXLPerformanceResourceTiming,\n parentSpan: Span,\n ) {\n const span = this._startSpan(\n AttributeNames.RESOURCE_FETCH,\n PerformanceTimingNames.FETCH_START,\n resource,\n parentSpan,\n );\n if (!span) {\n return;\n }\n\n span.setAttribute(ATTR_URL_FULL, resource.name);\n addSpanNetworkEvents(span, resource, this.getConfig().ignoreNetworkEvents);\n\n this._addResourceAttributesToSpan(span, resource);\n this._addResourceDiagnosticAttributes(span, resource);\n\n this._addCustomAttributesOnResourceSpan(\n span,\n resource,\n this.getConfig().applyCustomAttributesOnSpan?.resourceFetch,\n );\n this._endSpan(span, PerformanceTimingNames.RESPONSE_END, resource);\n }\n\n /**\n * Helper function for starting a span\n * @param spanName name of span\n * @param performanceName name of performance entry for time start\n * @param entries\n * @param parentSpan\n */\n private _startSpan(\n spanName: string,\n performanceName: string,\n entries: PerformanceEntries,\n parentSpan?: Span,\n ): Span | undefined {\n if (\n hasKey(entries, performanceName) &&\n typeof entries[performanceName] === 'number'\n ) {\n const span = this.tracer.startSpan(\n spanName,\n {\n startTime: this.perf.epochMillisFromOriginOffset(\n entries[performanceName],\n ),\n },\n parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined,\n );\n return span;\n }\n return undefined;\n }\n\n /**\n * Adds custom attributes to span if configured\n * Used for both documentFetch and documentLoad spans\n */\n private _addCustomAttributesOnSpan(\n span: Span,\n applyCustomAttributesOnSpan:\n | DocumentLoadCustomAttributeFunction\n | undefined,\n ) {\n if (applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () => {\n applyCustomAttributesOnSpan(span);\n },\n (error) => {\n if (!error) {\n return;\n }\n\n this._diag.error('addCustomAttributesOnSpan', error);\n },\n true,\n );\n }\n }\n\n private _addResourceAttributesToSpan(\n span: Span,\n resource: ResourceSpanData,\n ): void {\n span.setAttribute(KEY_MXL_TYPE, MXL_TYPES.ResourceFetch);\n\n if (resource.deliveryType) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_DELIVERY_TYPE,\n resource.deliveryType,\n );\n }\n\n if (resource.initiatorType) {\n span.setAttribute(\n ATTR_HTTP_REQUEST_INITIATOR_TYPE,\n resource.initiatorType,\n );\n }\n\n if (resource.renderBlockingStatus) {\n span.setAttribute(\n ATTR_HTTP_REQUEST_RENDER_BLOCKING_STATUS,\n resource.renderBlockingStatus,\n );\n }\n\n if (resource.responseStatus) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n resource.responseStatus,\n );\n }\n\n if (resource.encodedBodySize !== undefined) {\n span.setAttribute(ATTR_HTTP_RESPONSE_BODY_SIZE, resource.encodedBodySize);\n }\n\n if (resource.transferSize !== undefined) {\n span.setAttribute(ATTR_HTTP_RESPONSE_SIZE, resource.transferSize);\n }\n\n if (resource.decodedBodySize !== undefined) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_DECODED_BODY_SIZE,\n resource.decodedBodySize,\n );\n }\n }\n\n private _addNavigationTimingAttributesToSpan(\n span: Span,\n entries: MXLPerformanceNavigationEntries,\n ): void {\n if (entries.type) {\n span.setAttribute(ATTR_BROWSER_NAVIGATION_TIMING_TYPE, entries.type);\n }\n\n if (entries.notRestoredReasons?.length) {\n span.setAttribute(\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n entries.notRestoredReasons,\n );\n }\n }\n\n /**\n * Adds custom attributes to resource span if configured\n */\n private _addCustomAttributesOnResourceSpan(\n span: Span,\n resource: MXLPerformanceResourceTiming,\n applyCustomAttributesOnSpan:\n | ResourceFetchCustomAttributeFunction\n | undefined,\n ) {\n if (applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () => {\n applyCustomAttributesOnSpan(span, resource);\n },\n (error) => {\n if (!error) {\n return;\n }\n\n this._diag.error('addCustomAttributesOnResourceSpan', error);\n },\n true,\n );\n }\n }\n\n private _hasNoSizeData(resource: MXLPerformanceResourceTiming): boolean {\n return (\n resource.transferSize === 0 &&\n resource.decodedBodySize === 0 &&\n resource.encodedBodySize === 0\n );\n }\n\n private _hasTimingData(resource: MXLPerformanceResourceTiming): boolean {\n return resource.fetchStart > 0 && resource.responseEnd > 0;\n }\n\n private _isCorsRestricted(resource: MXLPerformanceResourceTiming): boolean {\n return this._hasNoSizeData(resource) && this._hasTimingData(resource);\n }\n\n private _isFetchIncomplete(resource: MXLPerformanceResourceTiming): boolean {\n return (\n this._hasNoSizeData(resource) &&\n resource.fetchStart > 0 &&\n resource.responseEnd === 0\n );\n }\n\n private _isFetchPrevented(resource: MXLPerformanceResourceTiming): boolean {\n return this._hasNoSizeData(resource) && resource.fetchStart === 0;\n }\n\n /**\n * Detect cache validation (304 Not Modified responses)\n *\n * 304 responses show transferSize of ~300 bytes (headers only, no body).\n * Use deliveryType to distinguish from cache hits: 'cache' = no network, otherwise = 304.\n *\n * Spec: https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-transfersize\n */\n private _isCacheValidated(resource: MXLPerformanceResourceTiming): boolean {\n // DeliveryType is Chromium only, so an engine without it never reads 'cache'.\n return resource.transferSize === 300 && resource.deliveryType !== 'cache';\n }\n\n /**\n * Add diagnostic attributes to identify resource loading issues\n *\n * Diagnostic attributes help identify why resources may have incomplete timing data:\n * - CORS restrictions (opaque responses without Timing-Allow-Origin header)\n * - Cache revalidation (304 Not Modified responses)\n * - Request incomplete (started but didn't complete - network error, aborted)\n * - Request prevented (never started - blocked by CSP, browser, extension)\n *\n * The size and timing fields read below are always numbers: a cross-origin\n * resource with no Timing-Allow-Origin reports them as 0 rather than omitting\n * them, and a resource only reaches here once it has produced a span, which\n * required a numeric fetchStart.\n */\n private _addResourceDiagnosticAttributes(\n span: Span,\n resource: MXLPerformanceResourceTiming,\n ): void {\n if (this._isCorsRestricted(resource)) {\n span.setAttribute(ATTR_HTTP_RESPONSE_CORS_OPAQUE, true);\n } else if (this._isFetchIncomplete(resource)) {\n span.setAttribute(ATTR_HTTP_REQUEST_INCOMPLETE, true);\n } else if (this._isFetchPrevented(resource)) {\n span.setAttribute(ATTR_HTTP_REQUEST_PREVENTED, true);\n }\n\n if (this._isCacheValidated(resource)) {\n span.setAttribute(ATTR_HTTP_RESPONSE_CACHE_REVALIDATED, true);\n }\n }\n\n protected override onEnable(): void {\n // An unbuffered subscription registered after the load event is never\n // notified, so collect straight away instead of observing. Deferred a\n // microtask because under registerGlobally: false the tracer provider\n // arrives later in this same task, and earlier spans reach a no-op tracer.\n if (this._isLoadEventFinished()) {\n queueMicrotask(() => {\n if (this._isEnabled) {\n this._collectIfLoadEventFinished();\n }\n });\n return;\n }\n\n // Buffered must stay false: mid-load, WebKit answers a buffered\n // subscription with the unfinished entry and counts it as the observer's\n // one notification, so the finalized entry never arrives.\n this._navigationObserver = createPerformanceObserver(\n 'navigation',\n () => {\n this._collectIfLoadEventFinished();\n },\n { buffered: false, diag: this._diag },\n );\n\n if (!this._navigationObserver) {\n this._diag.warn(\n 'navigation entries are not observable, document load will not be collected',\n );\n }\n }\n\n protected override onDisable(): void {\n this._disconnectObserver();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyEA,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,mCAAmC;AACzC,MAAM,2CACJ;AAGF,MAAM,iCAAiC;AACvC,MAAM,uCAAuC;AAC7C,MAAM,+BAA+B;AACrC,MAAM,8BAA8B;AACpC,MAAM,sCAAsC;AAE5C,IAAa,8BAAb,cAAiDA,uEAAAA,uBAA0D;CACzG,sBAA0D;CAC1D,wBAAgC;CAEhC,YAAmB,EACjB,MACA,MACA,SACA,6BACA,+BAA+B,OAC/B,sBAAsB,UACe,EAAE,EAAE;AACzC,QAAM;GACJ,QAAQ;IACN;IACA;IACA;IACA;IACD;GACD;GACA,qBAAqB;GACrB,wBAAwB;GACxB;GACD,CAAC;AAEF,MAAI,KAAK,QAAQ,QACf,MAAK,QAAQ;;;;;;CAQjB,mBAA2B,UAAsB;AAE7C,cAAY,iBAAiB,WACtB,CAAC,SAAS,aAAa;AAC9B,QAAK,kBAAkB,UAAU,SAAS;IAC1C;;;;;;;;CASJ,8BAA4C;AAC1C,MAAI,KAAK,yBAAyB,CAAC,KAAK,sBAAsB,CAC5D;AAKF,OAAK,wBAAwB;AAE7B,MAAI;AACF,QAAK,qBAAqB;WACnB,OAAO;AACd,QAAK,MAAM,MAAM,uCAAuC,MAAM;YACtD;AACR,QAAK,qBAA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ase.js";
|
|
3
3
|
import { createPerformanceObserver } from "../../../utils/performanceObserver/performanceObserver.js";
|
|
4
4
|
import "./enums/AttributeNames.js";
|
|
5
|
+
import "./enums/PerformanceTimingNames.js";
|
|
6
|
+
import { addSpanNetworkEvent, addSpanNetworkEvents, hasKey } from "./networkEvents.js";
|
|
5
7
|
import { addSpanPerformancePaintEvents, getPerformanceNavigationEntries } from "./utils.js";
|
|
6
8
|
import { ROOT_CONTEXT, context, propagation, trace } from "@opentelemetry/api";
|
|
7
9
|
import { TRACE_PARENT_HEADER } from "@opentelemetry/core";
|
|
8
10
|
import { ATTR_HTTP_RESPONSE_STATUS_CODE } from "@opentelemetry/semantic-conventions";
|
|
9
11
|
import { safeExecuteInTheMiddle } from "@opentelemetry/instrumentation";
|
|
10
|
-
import { PerformanceTimingNames, addSpanNetworkEvent, addSpanNetworkEvents, hasKey } from "@opentelemetry/sdk-trace-web";
|
|
11
12
|
import { ATTR_HTTP_RESPONSE_BODY_SIZE, ATTR_HTTP_RESPONSE_SIZE, ATTR_URL_FULL as ATTR_URL_FULL$1, ATTR_USER_AGENT_ORIGINAL as ATTR_USER_AGENT_ORIGINAL$1 } from "@opentelemetry/semantic-conventions/incubating";
|
|
12
13
|
//#region src/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.ts
|
|
13
14
|
const ATTR_HTTP_RESPONSE_DELIVERY_TYPE = "http.response.delivery_type";
|
|
@@ -79,13 +80,13 @@ var DocumentLoadInstrumentation = class extends MXLInstrumentationBase {
|
|
|
79
80
|
const entries = getPerformanceNavigationEntries();
|
|
80
81
|
const traceparent = metaElement?.content || "";
|
|
81
82
|
context.with(propagation.extract(ROOT_CONTEXT, { traceparent }), () => {
|
|
82
|
-
const rootSpan = this._startSpan("documentLoad",
|
|
83
|
+
const rootSpan = this._startSpan("documentLoad", "fetchStart", entries);
|
|
83
84
|
if (!rootSpan) {
|
|
84
85
|
this._diag.warn("navigation entry has no fetchStart, document load will not be collected");
|
|
85
86
|
return;
|
|
86
87
|
}
|
|
87
88
|
context.with(trace.setSpan(context.active(), rootSpan), () => {
|
|
88
|
-
const fetchSpan = this._startSpan("documentFetch",
|
|
89
|
+
const fetchSpan = this._startSpan("documentFetch", "fetchStart", entries);
|
|
89
90
|
if (fetchSpan) {
|
|
90
91
|
fetchSpan.setAttribute(ATTR_URL_FULL$1, location.href);
|
|
91
92
|
context.with(trace.setSpan(context.active(), fetchSpan), () => {
|
|
@@ -93,7 +94,7 @@ var DocumentLoadInstrumentation = class extends MXLInstrumentationBase {
|
|
|
93
94
|
this._addResourceAttributesToSpan(fetchSpan, entries);
|
|
94
95
|
this._addNavigationTimingAttributesToSpan(fetchSpan, entries);
|
|
95
96
|
this._addCustomAttributesOnSpan(fetchSpan, this.getConfig().applyCustomAttributesOnSpan?.documentFetch);
|
|
96
|
-
this._endSpan(fetchSpan,
|
|
97
|
+
this._endSpan(fetchSpan, "responseEnd", entries);
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
});
|
|
@@ -102,19 +103,19 @@ var DocumentLoadInstrumentation = class extends MXLInstrumentationBase {
|
|
|
102
103
|
rootSpan.setAttribute(ATTR_USER_AGENT_ORIGINAL$1, navigator.userAgent);
|
|
103
104
|
this._addResourcesSpans(rootSpan);
|
|
104
105
|
if (!this.getConfig().ignoreNetworkEvents) {
|
|
105
|
-
addSpanNetworkEvent(rootSpan,
|
|
106
|
-
addSpanNetworkEvent(rootSpan,
|
|
107
|
-
addSpanNetworkEvent(rootSpan,
|
|
108
|
-
addSpanNetworkEvent(rootSpan,
|
|
109
|
-
addSpanNetworkEvent(rootSpan,
|
|
110
|
-
addSpanNetworkEvent(rootSpan,
|
|
111
|
-
addSpanNetworkEvent(rootSpan,
|
|
112
|
-
addSpanNetworkEvent(rootSpan,
|
|
113
|
-
addSpanNetworkEvent(rootSpan,
|
|
106
|
+
addSpanNetworkEvent(rootSpan, "fetchStart", entries);
|
|
107
|
+
addSpanNetworkEvent(rootSpan, "unloadEventStart", entries);
|
|
108
|
+
addSpanNetworkEvent(rootSpan, "unloadEventEnd", entries);
|
|
109
|
+
addSpanNetworkEvent(rootSpan, "domInteractive", entries);
|
|
110
|
+
addSpanNetworkEvent(rootSpan, "domContentLoadedEventStart", entries);
|
|
111
|
+
addSpanNetworkEvent(rootSpan, "domContentLoadedEventEnd", entries);
|
|
112
|
+
addSpanNetworkEvent(rootSpan, "domComplete", entries);
|
|
113
|
+
addSpanNetworkEvent(rootSpan, "loadEventStart", entries);
|
|
114
|
+
addSpanNetworkEvent(rootSpan, "loadEventEnd", entries);
|
|
114
115
|
}
|
|
115
116
|
if (!this.getConfig().ignorePerformancePaintEvents) addSpanPerformancePaintEvents(rootSpan, this.perf);
|
|
116
117
|
this._addCustomAttributesOnSpan(rootSpan, this.getConfig().applyCustomAttributesOnSpan?.documentLoad);
|
|
117
|
-
this._endSpan(rootSpan,
|
|
118
|
+
this._endSpan(rootSpan, "loadEventEnd", entries);
|
|
118
119
|
});
|
|
119
120
|
}
|
|
120
121
|
/**
|
|
@@ -133,14 +134,14 @@ var DocumentLoadInstrumentation = class extends MXLInstrumentationBase {
|
|
|
133
134
|
* @param parentSpan
|
|
134
135
|
*/
|
|
135
136
|
_initResourceSpan(resource, parentSpan) {
|
|
136
|
-
const span = this._startSpan("resourceFetch",
|
|
137
|
+
const span = this._startSpan("resourceFetch", "fetchStart", resource, parentSpan);
|
|
137
138
|
if (!span) return;
|
|
138
139
|
span.setAttribute(ATTR_URL_FULL$1, resource.name);
|
|
139
140
|
addSpanNetworkEvents(span, resource, this.getConfig().ignoreNetworkEvents);
|
|
140
141
|
this._addResourceAttributesToSpan(span, resource);
|
|
141
142
|
this._addResourceDiagnosticAttributes(span, resource);
|
|
142
143
|
this._addCustomAttributesOnResourceSpan(span, resource, this.getConfig().applyCustomAttributesOnSpan?.resourceFetch);
|
|
143
|
-
this._endSpan(span,
|
|
144
|
+
this._endSpan(span, "responseEnd", resource);
|
|
144
145
|
}
|
|
145
146
|
/**
|
|
146
147
|
* Helper function for starting a span
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentLoadInstrumentation.js","names":["ATTR_URL_FULL","ATTR_USER_AGENT_ORIGINAL"],"sources":["../../../../src/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.ts"],"sourcesContent":["/*\n * Adapted from OpenTelemetry document-load instrumentation\n * https://github.com/open-telemetry/opentelemetry-js-contrib/tree/cc7eff47e2e7bad7678241b766753d5bd6dbc85f/packages/instrumentation-document-load\n *\n * Additional PerformanceResourceTiming attributes collected:\n * - entry_type, initiator_type\n * - decoded_body_size, http.response.body.size, http.response.size\n * - delivery_type (Chromium only)\n * - render_blocking_status (Chromium only)\n * - http.response.status_code (no Safari support)\n *\n * Custom diagnostic attributes added to identify resource loading issues:\n * - http.response.cors_opaque - CORS-restricted resource (opaque response)\n * - http.response.cache_revalidated - 304 Not Modified response\n * - http.request.incomplete - Request started but didn't complete (network error, aborted)\n * - http.request.prevented - Request never started (blocked by CSP, browser, extension)\n *\n * Navigation-only attributes added to the document fetch span:\n * - browser.navigation_timing.type\n * - browser.navigation_timing.not_restored_reasons\n */\n\nimport type { Span } from '@opentelemetry/api';\nimport { ROOT_CONTEXT, context, propagation, trace } from '@opentelemetry/api';\nimport { TRACE_PARENT_HEADER } from '@opentelemetry/core';\nimport { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport type { PerformanceEntries } from '@opentelemetry/sdk-trace-web';\nimport {\n PerformanceTimingNames,\n addSpanNetworkEvent,\n addSpanNetworkEvents,\n hasKey,\n} from '@opentelemetry/sdk-trace-web';\nimport { ATTR_HTTP_RESPONSE_STATUS_CODE } from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_HTTP_RESPONSE_BODY_SIZE,\n ATTR_HTTP_RESPONSE_SIZE,\n ATTR_URL_FULL,\n ATTR_USER_AGENT_ORIGINAL,\n} from '@opentelemetry/semantic-conventions/incubating';\nimport {\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n KEY_MXL_TYPE,\n MXL_TYPES,\n} from '../../../constants/attributes';\nimport { createPerformanceObserver } from '../../../utils/performanceObserver/performanceObserver';\nimport { MXLInstrumentationBase } from '../../MXLInstrumentationBase/MXLInstrumentationBase';\nimport { AttributeNames } from './enums/AttributeNames';\nimport type {\n DocumentLoadCustomAttributeFunction,\n DocumentLoadInstrumentationConfig,\n ResourceFetchCustomAttributeFunction,\n} from './types';\nimport type {\n MXLPerformanceNavigationEntries,\n MXLPerformanceResourceTiming,\n} from './utils';\nimport {\n addSpanPerformancePaintEvents,\n getPerformanceNavigationEntries,\n} from './utils';\n\ntype ResourceSpanData = {\n deliveryType?: 'cache' | '';\n initiatorType?: string;\n renderBlockingStatus?: 'blocking' | 'non-blocking';\n responseStatus?: number;\n encodedBodySize?: number;\n transferSize?: number;\n decodedBodySize?: number;\n};\n\n// PerformanceResourceTiming attribute names\nconst ATTR_HTTP_RESPONSE_DELIVERY_TYPE = 'http.response.delivery_type';\nconst ATTR_HTTP_RESPONSE_DECODED_BODY_SIZE = 'http.response.decoded_body_size';\nconst ATTR_HTTP_REQUEST_INITIATOR_TYPE = 'http.request.initiator_type';\nconst ATTR_HTTP_REQUEST_RENDER_BLOCKING_STATUS =\n 'http.request.render_blocking_status';\n\n// Diagnostic attribute names\nconst ATTR_HTTP_RESPONSE_CORS_OPAQUE = 'http.response.cors_opaque'; // CORS-restricted resource (opaque response)\nconst ATTR_HTTP_RESPONSE_CACHE_REVALIDATED = 'http.response.cache_revalidated'; // 304 Not Modified response\nconst ATTR_HTTP_REQUEST_INCOMPLETE = 'http.request.incomplete'; // Request started but didn't complete\nconst ATTR_HTTP_REQUEST_PREVENTED = 'http.request.prevented'; // Request never started (blocked)\nconst ATTR_BROWSER_NAVIGATION_TIMING_TYPE = 'browser.navigation_timing.type';\n\nexport class DocumentLoadInstrumentation extends MXLInstrumentationBase<DocumentLoadInstrumentationConfig> {\n private _navigationObserver: PerformanceObserver | null = null;\n private _performanceCollected = false;\n\n public constructor({\n diag,\n perf,\n enabled,\n applyCustomAttributesOnSpan,\n ignorePerformancePaintEvents = false,\n ignoreNetworkEvents = false,\n }: DocumentLoadInstrumentationConfig = {}) {\n super({\n config: {\n applyCustomAttributesOnSpan,\n enabled,\n ignoreNetworkEvents,\n ignorePerformancePaintEvents,\n },\n diag,\n instrumentationName: 'DocumentLoadInstrumentation',\n instrumentationVersion: '1.0.0',\n perf,\n });\n\n if (this._config.enabled) {\n this.enable();\n }\n }\n\n /**\n * Adds spans for all resources\n * @param rootSpan\n */\n private _addResourcesSpans(rootSpan: Span): void {\n const resources: MXLPerformanceResourceTiming[] =\n performance.getEntriesByType('resource');\n resources.forEach((resource) => {\n this._initResourceSpan(resource, rootSpan);\n });\n }\n\n /**\n * The one navigation entry per document is mutated in place as the load\n * progresses, so collecting early would end the documentLoad span at time\n * origin. Returning early leaves the observer subscribed for a later\n * notification.\n */\n private _collectIfLoadEventFinished(): void {\n if (this._performanceCollected || !this._isLoadEventFinished()) {\n return;\n }\n\n // Latched before collecting so a throw part way through cannot emit a\n // second set of spans on a later trigger.\n this._performanceCollected = true;\n\n try {\n this._collectPerformance();\n } catch (error) {\n this._diag.error('failed to collect the document load', error);\n } finally {\n this._disconnectObserver();\n }\n }\n\n // LoadEventEnd is written only after every load handler returns. WebKit\n // reports no entry at all for about:blank, popups and srcdoc iframes.\n private _isLoadEventFinished(): boolean {\n const [navigationTiming] = performance.getEntriesByType('navigation');\n return (\n ((navigationTiming as PerformanceNavigationTiming | undefined)\n ?.loadEventEnd ?? 0) > 0\n );\n }\n\n private _disconnectObserver(): void {\n this._navigationObserver?.disconnect();\n this._navigationObserver = null;\n }\n\n /**\n * Collects information about performance and creates appropriate spans\n */\n private _collectPerformance(): void {\n const metaElement = [...document.getElementsByTagName('meta')].find(\n (e) => e.getAttribute('name') === TRACE_PARENT_HEADER,\n );\n const entries = getPerformanceNavigationEntries();\n const traceparent = metaElement?.content || '';\n context.with(propagation.extract(ROOT_CONTEXT, { traceparent }), () => {\n const rootSpan = this._startSpan(\n AttributeNames.DOCUMENT_LOAD,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n if (!rootSpan) {\n this._diag.warn(\n 'navigation entry has no fetchStart, document load will not be collected',\n );\n return;\n }\n context.with(trace.setSpan(context.active(), rootSpan), () => {\n const fetchSpan = this._startSpan(\n AttributeNames.DOCUMENT_FETCH,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n if (fetchSpan) {\n fetchSpan.setAttribute(ATTR_URL_FULL, location.href);\n context.with(trace.setSpan(context.active(), fetchSpan), () => {\n addSpanNetworkEvents(\n fetchSpan,\n entries,\n this.getConfig().ignoreNetworkEvents,\n );\n this._addResourceAttributesToSpan(fetchSpan, entries);\n this._addNavigationTimingAttributesToSpan(fetchSpan, entries);\n this._addCustomAttributesOnSpan(\n fetchSpan,\n this.getConfig().applyCustomAttributesOnSpan?.documentFetch,\n );\n this._endSpan(\n fetchSpan,\n PerformanceTimingNames.RESPONSE_END,\n entries,\n );\n });\n }\n });\n\n rootSpan.setAttribute(KEY_MXL_TYPE, MXL_TYPES.DocumentLoad);\n rootSpan.setAttribute(ATTR_URL_FULL, location.href);\n rootSpan.setAttribute(ATTR_USER_AGENT_ORIGINAL, navigator.userAgent);\n\n this._addResourcesSpans(rootSpan);\n\n if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.UNLOAD_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.UNLOAD_EVENT_END,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_INTERACTIVE,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_END,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_COMPLETE,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.LOAD_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.LOAD_EVENT_END,\n entries,\n );\n }\n\n if (!this.getConfig().ignorePerformancePaintEvents) {\n addSpanPerformancePaintEvents(rootSpan, this.perf);\n }\n\n this._addCustomAttributesOnSpan(\n rootSpan,\n this.getConfig().applyCustomAttributesOnSpan?.documentLoad,\n );\n this._endSpan(rootSpan, PerformanceTimingNames.LOAD_EVENT_END, entries);\n });\n }\n\n /**\n * Helper function for ending a span\n * @param span\n * @param performanceName name of performance entry for end time\n * @param entries\n */\n private _endSpan(\n span: Span | undefined,\n performanceName: string,\n entries: PerformanceEntries,\n ) {\n // Span can be undefined when entries are missing the required performance timing - no span will be created\n if (span) {\n if (\n hasKey(entries, performanceName) &&\n typeof entries[performanceName] === 'number'\n ) {\n span.end(\n this.perf.epochMillisFromOriginOffset(entries[performanceName]),\n );\n } else {\n span.end();\n }\n }\n }\n\n /**\n * Creates and ends a span with network information about a resource added as timed events\n * @param resource\n * @param parentSpan\n */\n private _initResourceSpan(\n resource: MXLPerformanceResourceTiming,\n parentSpan: Span,\n ) {\n const span = this._startSpan(\n AttributeNames.RESOURCE_FETCH,\n PerformanceTimingNames.FETCH_START,\n resource,\n parentSpan,\n );\n if (!span) {\n return;\n }\n\n span.setAttribute(ATTR_URL_FULL, resource.name);\n addSpanNetworkEvents(span, resource, this.getConfig().ignoreNetworkEvents);\n\n this._addResourceAttributesToSpan(span, resource);\n this._addResourceDiagnosticAttributes(span, resource);\n\n this._addCustomAttributesOnResourceSpan(\n span,\n resource,\n this.getConfig().applyCustomAttributesOnSpan?.resourceFetch,\n );\n this._endSpan(span, PerformanceTimingNames.RESPONSE_END, resource);\n }\n\n /**\n * Helper function for starting a span\n * @param spanName name of span\n * @param performanceName name of performance entry for time start\n * @param entries\n * @param parentSpan\n */\n private _startSpan(\n spanName: string,\n performanceName: string,\n entries: PerformanceEntries,\n parentSpan?: Span,\n ): Span | undefined {\n if (\n hasKey(entries, performanceName) &&\n typeof entries[performanceName] === 'number'\n ) {\n const span = this.tracer.startSpan(\n spanName,\n {\n startTime: this.perf.epochMillisFromOriginOffset(\n entries[performanceName],\n ),\n },\n parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined,\n );\n return span;\n }\n return undefined;\n }\n\n /**\n * Adds custom attributes to span if configured\n * Used for both documentFetch and documentLoad spans\n */\n private _addCustomAttributesOnSpan(\n span: Span,\n applyCustomAttributesOnSpan:\n | DocumentLoadCustomAttributeFunction\n | undefined,\n ) {\n if (applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () => {\n applyCustomAttributesOnSpan(span);\n },\n (error) => {\n if (!error) {\n return;\n }\n\n this._diag.error('addCustomAttributesOnSpan', error);\n },\n true,\n );\n }\n }\n\n private _addResourceAttributesToSpan(\n span: Span,\n resource: ResourceSpanData,\n ): void {\n span.setAttribute(KEY_MXL_TYPE, MXL_TYPES.ResourceFetch);\n\n if (resource.deliveryType) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_DELIVERY_TYPE,\n resource.deliveryType,\n );\n }\n\n if (resource.initiatorType) {\n span.setAttribute(\n ATTR_HTTP_REQUEST_INITIATOR_TYPE,\n resource.initiatorType,\n );\n }\n\n if (resource.renderBlockingStatus) {\n span.setAttribute(\n ATTR_HTTP_REQUEST_RENDER_BLOCKING_STATUS,\n resource.renderBlockingStatus,\n );\n }\n\n if (resource.responseStatus) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n resource.responseStatus,\n );\n }\n\n if (resource.encodedBodySize !== undefined) {\n span.setAttribute(ATTR_HTTP_RESPONSE_BODY_SIZE, resource.encodedBodySize);\n }\n\n if (resource.transferSize !== undefined) {\n span.setAttribute(ATTR_HTTP_RESPONSE_SIZE, resource.transferSize);\n }\n\n if (resource.decodedBodySize !== undefined) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_DECODED_BODY_SIZE,\n resource.decodedBodySize,\n );\n }\n }\n\n private _addNavigationTimingAttributesToSpan(\n span: Span,\n entries: MXLPerformanceNavigationEntries,\n ): void {\n if (entries.type) {\n span.setAttribute(ATTR_BROWSER_NAVIGATION_TIMING_TYPE, entries.type);\n }\n\n if (entries.notRestoredReasons?.length) {\n span.setAttribute(\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n entries.notRestoredReasons,\n );\n }\n }\n\n /**\n * Adds custom attributes to resource span if configured\n */\n private _addCustomAttributesOnResourceSpan(\n span: Span,\n resource: MXLPerformanceResourceTiming,\n applyCustomAttributesOnSpan:\n | ResourceFetchCustomAttributeFunction\n | undefined,\n ) {\n if (applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () => {\n applyCustomAttributesOnSpan(span, resource);\n },\n (error) => {\n if (!error) {\n return;\n }\n\n this._diag.error('addCustomAttributesOnResourceSpan', error);\n },\n true,\n );\n }\n }\n\n private _hasNoSizeData(resource: MXLPerformanceResourceTiming): boolean {\n return (\n resource.transferSize === 0 &&\n resource.decodedBodySize === 0 &&\n resource.encodedBodySize === 0\n );\n }\n\n private _hasTimingData(resource: MXLPerformanceResourceTiming): boolean {\n return resource.fetchStart > 0 && resource.responseEnd > 0;\n }\n\n private _isCorsRestricted(resource: MXLPerformanceResourceTiming): boolean {\n return this._hasNoSizeData(resource) && this._hasTimingData(resource);\n }\n\n private _isFetchIncomplete(resource: MXLPerformanceResourceTiming): boolean {\n return (\n this._hasNoSizeData(resource) &&\n resource.fetchStart > 0 &&\n resource.responseEnd === 0\n );\n }\n\n private _isFetchPrevented(resource: MXLPerformanceResourceTiming): boolean {\n return this._hasNoSizeData(resource) && resource.fetchStart === 0;\n }\n\n /**\n * Detect cache validation (304 Not Modified responses)\n *\n * 304 responses show transferSize of ~300 bytes (headers only, no body).\n * Use deliveryType to distinguish from cache hits: 'cache' = no network, otherwise = 304.\n *\n * Spec: https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-transfersize\n */\n private _isCacheValidated(resource: MXLPerformanceResourceTiming): boolean {\n // DeliveryType is Chromium only, so an engine without it never reads 'cache'.\n return resource.transferSize === 300 && resource.deliveryType !== 'cache';\n }\n\n /**\n * Add diagnostic attributes to identify resource loading issues\n *\n * Diagnostic attributes help identify why resources may have incomplete timing data:\n * - CORS restrictions (opaque responses without Timing-Allow-Origin header)\n * - Cache revalidation (304 Not Modified responses)\n * - Request incomplete (started but didn't complete - network error, aborted)\n * - Request prevented (never started - blocked by CSP, browser, extension)\n *\n * The size and timing fields read below are always numbers: a cross-origin\n * resource with no Timing-Allow-Origin reports them as 0 rather than omitting\n * them, and a resource only reaches here once it has produced a span, which\n * required a numeric fetchStart.\n */\n private _addResourceDiagnosticAttributes(\n span: Span,\n resource: MXLPerformanceResourceTiming,\n ): void {\n if (this._isCorsRestricted(resource)) {\n span.setAttribute(ATTR_HTTP_RESPONSE_CORS_OPAQUE, true);\n } else if (this._isFetchIncomplete(resource)) {\n span.setAttribute(ATTR_HTTP_REQUEST_INCOMPLETE, true);\n } else if (this._isFetchPrevented(resource)) {\n span.setAttribute(ATTR_HTTP_REQUEST_PREVENTED, true);\n }\n\n if (this._isCacheValidated(resource)) {\n span.setAttribute(ATTR_HTTP_RESPONSE_CACHE_REVALIDATED, true);\n }\n }\n\n protected override onEnable(): void {\n // An unbuffered subscription registered after the load event is never\n // notified, so collect straight away instead of observing. Deferred a\n // microtask because under registerGlobally: false the tracer provider\n // arrives later in this same task, and earlier spans reach a no-op tracer.\n if (this._isLoadEventFinished()) {\n queueMicrotask(() => {\n if (this._isEnabled) {\n this._collectIfLoadEventFinished();\n }\n });\n return;\n }\n\n // Buffered must stay false: mid-load, WebKit answers a buffered\n // subscription with the unfinished entry and counts it as the observer's\n // one notification, so the finalized entry never arrives.\n this._navigationObserver = createPerformanceObserver(\n 'navigation',\n () => {\n this._collectIfLoadEventFinished();\n },\n { buffered: false, diag: this._diag },\n );\n\n if (!this._navigationObserver) {\n this._diag.warn(\n 'navigation entries are not observable, document load will not be collected',\n );\n }\n }\n\n protected override onDisable(): void {\n this._disconnectObserver();\n }\n}\n"],"mappings":";;;;;;;;;;;;AAyEA,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,mCAAmC;AACzC,MAAM,2CACJ;AAGF,MAAM,iCAAiC;AACvC,MAAM,uCAAuC;AAC7C,MAAM,+BAA+B;AACrC,MAAM,8BAA8B;AACpC,MAAM,sCAAsC;AAE5C,IAAa,8BAAb,cAAiD,uBAA0D;CACzG,sBAA0D;CAC1D,wBAAgC;CAEhC,YAAmB,EACjB,MACA,MACA,SACA,6BACA,+BAA+B,OAC/B,sBAAsB,UACe,EAAE,EAAE;AACzC,QAAM;GACJ,QAAQ;IACN;IACA;IACA;IACA;IACD;GACD;GACA,qBAAqB;GACrB,wBAAwB;GACxB;GACD,CAAC;AAEF,MAAI,KAAK,QAAQ,QACf,MAAK,QAAQ;;;;;;CAQjB,mBAA2B,UAAsB;AAE7C,cAAY,iBAAiB,WACtB,CAAC,SAAS,aAAa;AAC9B,QAAK,kBAAkB,UAAU,SAAS;IAC1C;;;;;;;;CASJ,8BAA4C;AAC1C,MAAI,KAAK,yBAAyB,CAAC,KAAK,sBAAsB,CAC5D;AAKF,OAAK,wBAAwB;AAE7B,MAAI;AACF,QAAK,qBAAqB;WACnB,OAAO;AACd,QAAK,MAAM,MAAM,uCAAuC,MAAM;YACtD;AACR,QAAK,qBAAqB;;;CAM9B,uBAAwC;EACtC,MAAM,CAAC,oBAAoB,YAAY,iBAAiB,aAAa;AACrE,UACI,kBACE,gBAAgB,KAAK;;CAI7B,sBAAoC;AAClC,OAAK,qBAAqB,YAAY;AACtC,OAAK,sBAAsB;;;;;CAM7B,sBAAoC;EAClC,MAAM,cAAc,CAAC,GAAG,SAAS,qB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,iBAAiB;;;;;;;;;;;;;;;;CAiBpE,iCACE,MACA,UACM;AACN,MAAI,KAAK,kBAAkB,SAAS,CAClC,MAAK,aAAa,gCAAgC,KAAK;WAC9C,KAAK,mBAAmB,SAAS,CAC1C,MAAK,aAAa,8BAA8B,KAAK;WAC5C,KAAK,kBAAkB,SAAS,CACzC,MAAK,aAAa,6BAA6B,KAAK;AAGtD,MAAI,KAAK,kBAAkB,SAAS,CAClC,MAAK,aAAa,sCAAsC,KAAK;;CAIjE,WAAoC;AAKlC,MAAI,KAAK,sBAAsB,EAAE;AAC/B,wBAAqB;AACnB,QAAI,KAAK,WACP,MAAK,6BAA6B;KAEpC;AACF;;AAMF,OAAK,sBAAsB,0BACzB,oBACM;AACJ,QAAK,6BAA6B;KAEpC;GAAE,UAAU;GAAO,MAAM,KAAK;GAAO,CACtC;AAED,MAAI,CAAC,KAAK,oBACR,MAAK,MAAM,KACT,6EACD;;CAIL,YAAqC;AACnC,OAAK,qBAAqB"}
|
|
1
|
+
{"version":3,"file":"DocumentLoadInstrumentation.js","names":["ATTR_URL_FULL","ATTR_USER_AGENT_ORIGINAL"],"sources":["../../../../src/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.ts"],"sourcesContent":["/*\n * Adapted from OpenTelemetry document-load instrumentation\n * https://github.com/open-telemetry/opentelemetry-js-contrib/tree/cc7eff47e2e7bad7678241b766753d5bd6dbc85f/packages/instrumentation-document-load\n *\n * Additional PerformanceResourceTiming attributes collected:\n * - entry_type, initiator_type\n * - decoded_body_size, http.response.body.size, http.response.size\n * - delivery_type (Chromium only)\n * - render_blocking_status (Chromium only)\n * - http.response.status_code (no Safari support)\n *\n * Custom diagnostic attributes added to identify resource loading issues:\n * - http.response.cors_opaque - CORS-restricted resource (opaque response)\n * - http.response.cache_revalidated - 304 Not Modified response\n * - http.request.incomplete - Request started but didn't complete (network error, aborted)\n * - http.request.prevented - Request never started (blocked by CSP, browser, extension)\n *\n * Navigation-only attributes added to the document fetch span:\n * - browser.navigation_timing.type\n * - browser.navigation_timing.not_restored_reasons\n */\n\nimport type { Span } from '@opentelemetry/api';\nimport { ROOT_CONTEXT, context, propagation, trace } from '@opentelemetry/api';\nimport { TRACE_PARENT_HEADER } from '@opentelemetry/core';\nimport { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport { ATTR_HTTP_RESPONSE_STATUS_CODE } from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_HTTP_RESPONSE_BODY_SIZE,\n ATTR_HTTP_RESPONSE_SIZE,\n ATTR_URL_FULL,\n ATTR_USER_AGENT_ORIGINAL,\n} from '@opentelemetry/semantic-conventions/incubating';\nimport {\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n KEY_MXL_TYPE,\n MXL_TYPES,\n} from '../../../constants/attributes';\nimport { createPerformanceObserver } from '../../../utils/performanceObserver/performanceObserver';\nimport { MXLInstrumentationBase } from '../../MXLInstrumentationBase/MXLInstrumentationBase';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { PerformanceTimingNames } from './enums/PerformanceTimingNames';\nimport type { PerformanceEntries } from './networkEvents';\nimport {\n addSpanNetworkEvent,\n addSpanNetworkEvents,\n hasKey,\n} from './networkEvents';\nimport type {\n DocumentLoadCustomAttributeFunction,\n DocumentLoadInstrumentationConfig,\n ResourceFetchCustomAttributeFunction,\n} from './types';\nimport type {\n MXLPerformanceNavigationEntries,\n MXLPerformanceResourceTiming,\n} from './utils';\nimport {\n addSpanPerformancePaintEvents,\n getPerformanceNavigationEntries,\n} from './utils';\n\ntype ResourceSpanData = {\n deliveryType?: 'cache' | '';\n initiatorType?: string;\n renderBlockingStatus?: 'blocking' | 'non-blocking';\n responseStatus?: number;\n encodedBodySize?: number;\n transferSize?: number;\n decodedBodySize?: number;\n};\n\n// PerformanceResourceTiming attribute names\nconst ATTR_HTTP_RESPONSE_DELIVERY_TYPE = 'http.response.delivery_type';\nconst ATTR_HTTP_RESPONSE_DECODED_BODY_SIZE = 'http.response.decoded_body_size';\nconst ATTR_HTTP_REQUEST_INITIATOR_TYPE = 'http.request.initiator_type';\nconst ATTR_HTTP_REQUEST_RENDER_BLOCKING_STATUS =\n 'http.request.render_blocking_status';\n\n// Diagnostic attribute names\nconst ATTR_HTTP_RESPONSE_CORS_OPAQUE = 'http.response.cors_opaque'; // CORS-restricted resource (opaque response)\nconst ATTR_HTTP_RESPONSE_CACHE_REVALIDATED = 'http.response.cache_revalidated'; // 304 Not Modified response\nconst ATTR_HTTP_REQUEST_INCOMPLETE = 'http.request.incomplete'; // Request started but didn't complete\nconst ATTR_HTTP_REQUEST_PREVENTED = 'http.request.prevented'; // Request never started (blocked)\nconst ATTR_BROWSER_NAVIGATION_TIMING_TYPE = 'browser.navigation_timing.type';\n\nexport class DocumentLoadInstrumentation extends MXLInstrumentationBase<DocumentLoadInstrumentationConfig> {\n private _navigationObserver: PerformanceObserver | null = null;\n private _performanceCollected = false;\n\n public constructor({\n diag,\n perf,\n enabled,\n applyCustomAttributesOnSpan,\n ignorePerformancePaintEvents = false,\n ignoreNetworkEvents = false,\n }: DocumentLoadInstrumentationConfig = {}) {\n super({\n config: {\n applyCustomAttributesOnSpan,\n enabled,\n ignoreNetworkEvents,\n ignorePerformancePaintEvents,\n },\n diag,\n instrumentationName: 'DocumentLoadInstrumentation',\n instrumentationVersion: '1.0.0',\n perf,\n });\n\n if (this._config.enabled) {\n this.enable();\n }\n }\n\n /**\n * Adds spans for all resources\n * @param rootSpan\n */\n private _addResourcesSpans(rootSpan: Span): void {\n const resources: MXLPerformanceResourceTiming[] =\n performance.getEntriesByType('resource');\n resources.forEach((resource) => {\n this._initResourceSpan(resource, rootSpan);\n });\n }\n\n /**\n * The one navigation entry per document is mutated in place as the load\n * progresses, so collecting early would end the documentLoad span at time\n * origin. Returning early leaves the observer subscribed for a later\n * notification.\n */\n private _collectIfLoadEventFinished(): void {\n if (this._performanceCollected || !this._isLoadEventFinished()) {\n return;\n }\n\n // Latched before collecting so a throw part way through cannot emit a\n // second set of spans on a later trigger.\n this._performanceCollected = true;\n\n try {\n this._collectPerformance();\n } catch (error) {\n this._diag.error('failed to collect the document load', error);\n } finally {\n this._disconnectObserver();\n }\n }\n\n // LoadEventEnd is written only after every load handler returns. WebKit\n // reports no entry at all for about:blank, popups and srcdoc iframes.\n private _isLoadEventFinished(): boolean {\n const [navigationTiming] = performance.getEntriesByType('navigation');\n return (\n ((navigationTiming as PerformanceNavigationTiming | undefined)\n ?.loadEventEnd ?? 0) > 0\n );\n }\n\n private _disconnectObserver(): void {\n this._navigationObserver?.disconnect();\n this._navigationObserver = null;\n }\n\n /**\n * Collects information about performance and creates appropriate spans\n */\n private _collectPerformance(): void {\n const metaElement = [...document.getElementsByTagName('meta')].find(\n (e) => e.getAttribute('name') === TRACE_PARENT_HEADER,\n );\n const entries = getPerformanceNavigationEntries();\n const traceparent = metaElement?.content || '';\n context.with(propagation.extract(ROOT_CONTEXT, { traceparent }), () => {\n const rootSpan = this._startSpan(\n AttributeNames.DOCUMENT_LOAD,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n if (!rootSpan) {\n this._diag.warn(\n 'navigation entry has no fetchStart, document load will not be collected',\n );\n return;\n }\n context.with(trace.setSpan(context.active(), rootSpan), () => {\n const fetchSpan = this._startSpan(\n AttributeNames.DOCUMENT_FETCH,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n if (fetchSpan) {\n fetchSpan.setAttribute(ATTR_URL_FULL, location.href);\n context.with(trace.setSpan(context.active(), fetchSpan), () => {\n addSpanNetworkEvents(\n fetchSpan,\n entries,\n this.getConfig().ignoreNetworkEvents,\n );\n this._addResourceAttributesToSpan(fetchSpan, entries);\n this._addNavigationTimingAttributesToSpan(fetchSpan, entries);\n this._addCustomAttributesOnSpan(\n fetchSpan,\n this.getConfig().applyCustomAttributesOnSpan?.documentFetch,\n );\n this._endSpan(\n fetchSpan,\n PerformanceTimingNames.RESPONSE_END,\n entries,\n );\n });\n }\n });\n\n rootSpan.setAttribute(KEY_MXL_TYPE, MXL_TYPES.DocumentLoad);\n rootSpan.setAttribute(ATTR_URL_FULL, location.href);\n rootSpan.setAttribute(ATTR_USER_AGENT_ORIGINAL, navigator.userAgent);\n\n this._addResourcesSpans(rootSpan);\n\n if (!this.getConfig().ignoreNetworkEvents) {\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.FETCH_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.UNLOAD_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.UNLOAD_EVENT_END,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_INTERACTIVE,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_CONTENT_LOADED_EVENT_END,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.DOM_COMPLETE,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.LOAD_EVENT_START,\n entries,\n );\n addSpanNetworkEvent(\n rootSpan,\n PerformanceTimingNames.LOAD_EVENT_END,\n entries,\n );\n }\n\n if (!this.getConfig().ignorePerformancePaintEvents) {\n addSpanPerformancePaintEvents(rootSpan, this.perf);\n }\n\n this._addCustomAttributesOnSpan(\n rootSpan,\n this.getConfig().applyCustomAttributesOnSpan?.documentLoad,\n );\n this._endSpan(rootSpan, PerformanceTimingNames.LOAD_EVENT_END, entries);\n });\n }\n\n /**\n * Helper function for ending a span\n * @param span\n * @param performanceName name of performance entry for end time\n * @param entries\n */\n private _endSpan(\n span: Span | undefined,\n performanceName: string,\n entries: PerformanceEntries,\n ) {\n // Span can be undefined when entries are missing the required performance timing - no span will be created\n if (span) {\n if (\n hasKey(entries, performanceName) &&\n typeof entries[performanceName] === 'number'\n ) {\n span.end(\n this.perf.epochMillisFromOriginOffset(entries[performanceName]),\n );\n } else {\n span.end();\n }\n }\n }\n\n /**\n * Creates and ends a span with network information about a resource added as timed events\n * @param resource\n * @param parentSpan\n */\n private _initResourceSpan(\n resource: MXLPerformanceResourceTiming,\n parentSpan: Span,\n ) {\n const span = this._startSpan(\n AttributeNames.RESOURCE_FETCH,\n PerformanceTimingNames.FETCH_START,\n resource,\n parentSpan,\n );\n if (!span) {\n return;\n }\n\n span.setAttribute(ATTR_URL_FULL, resource.name);\n addSpanNetworkEvents(span, resource, this.getConfig().ignoreNetworkEvents);\n\n this._addResourceAttributesToSpan(span, resource);\n this._addResourceDiagnosticAttributes(span, resource);\n\n this._addCustomAttributesOnResourceSpan(\n span,\n resource,\n this.getConfig().applyCustomAttributesOnSpan?.resourceFetch,\n );\n this._endSpan(span, PerformanceTimingNames.RESPONSE_END, resource);\n }\n\n /**\n * Helper function for starting a span\n * @param spanName name of span\n * @param performanceName name of performance entry for time start\n * @param entries\n * @param parentSpan\n */\n private _startSpan(\n spanName: string,\n performanceName: string,\n entries: PerformanceEntries,\n parentSpan?: Span,\n ): Span | undefined {\n if (\n hasKey(entries, performanceName) &&\n typeof entries[performanceName] === 'number'\n ) {\n const span = this.tracer.startSpan(\n spanName,\n {\n startTime: this.perf.epochMillisFromOriginOffset(\n entries[performanceName],\n ),\n },\n parentSpan ? trace.setSpan(context.active(), parentSpan) : undefined,\n );\n return span;\n }\n return undefined;\n }\n\n /**\n * Adds custom attributes to span if configured\n * Used for both documentFetch and documentLoad spans\n */\n private _addCustomAttributesOnSpan(\n span: Span,\n applyCustomAttributesOnSpan:\n | DocumentLoadCustomAttributeFunction\n | undefined,\n ) {\n if (applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () => {\n applyCustomAttributesOnSpan(span);\n },\n (error) => {\n if (!error) {\n return;\n }\n\n this._diag.error('addCustomAttributesOnSpan', error);\n },\n true,\n );\n }\n }\n\n private _addResourceAttributesToSpan(\n span: Span,\n resource: ResourceSpanData,\n ): void {\n span.setAttribute(KEY_MXL_TYPE, MXL_TYPES.ResourceFetch);\n\n if (resource.deliveryType) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_DELIVERY_TYPE,\n resource.deliveryType,\n );\n }\n\n if (resource.initiatorType) {\n span.setAttribute(\n ATTR_HTTP_REQUEST_INITIATOR_TYPE,\n resource.initiatorType,\n );\n }\n\n if (resource.renderBlockingStatus) {\n span.setAttribute(\n ATTR_HTTP_REQUEST_RENDER_BLOCKING_STATUS,\n resource.renderBlockingStatus,\n );\n }\n\n if (resource.responseStatus) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n resource.responseStatus,\n );\n }\n\n if (resource.encodedBodySize !== undefined) {\n span.setAttribute(ATTR_HTTP_RESPONSE_BODY_SIZE, resource.encodedBodySize);\n }\n\n if (resource.transferSize !== undefined) {\n span.setAttribute(ATTR_HTTP_RESPONSE_SIZE, resource.transferSize);\n }\n\n if (resource.decodedBodySize !== undefined) {\n span.setAttribute(\n ATTR_HTTP_RESPONSE_DECODED_BODY_SIZE,\n resource.decodedBodySize,\n );\n }\n }\n\n private _addNavigationTimingAttributesToSpan(\n span: Span,\n entries: MXLPerformanceNavigationEntries,\n ): void {\n if (entries.type) {\n span.setAttribute(ATTR_BROWSER_NAVIGATION_TIMING_TYPE, entries.type);\n }\n\n if (entries.notRestoredReasons?.length) {\n span.setAttribute(\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n entries.notRestoredReasons,\n );\n }\n }\n\n /**\n * Adds custom attributes to resource span if configured\n */\n private _addCustomAttributesOnResourceSpan(\n span: Span,\n resource: MXLPerformanceResourceTiming,\n applyCustomAttributesOnSpan:\n | ResourceFetchCustomAttributeFunction\n | undefined,\n ) {\n if (applyCustomAttributesOnSpan) {\n safeExecuteInTheMiddle(\n () => {\n applyCustomAttributesOnSpan(span, resource);\n },\n (error) => {\n if (!error) {\n return;\n }\n\n this._diag.error('addCustomAttributesOnResourceSpan', error);\n },\n true,\n );\n }\n }\n\n private _hasNoSizeData(resource: MXLPerformanceResourceTiming): boolean {\n return (\n resource.transferSize === 0 &&\n resource.decodedBodySize === 0 &&\n resource.encodedBodySize === 0\n );\n }\n\n private _hasTimingData(resource: MXLPerformanceResourceTiming): boolean {\n return resource.fetchStart > 0 && resource.responseEnd > 0;\n }\n\n private _isCorsRestricted(resource: MXLPerformanceResourceTiming): boolean {\n return this._hasNoSizeData(resource) && this._hasTimingData(resource);\n }\n\n private _isFetchIncomplete(resource: MXLPerformanceResourceTiming): boolean {\n return (\n this._hasNoSizeData(resource) &&\n resource.fetchStart > 0 &&\n resource.responseEnd === 0\n );\n }\n\n private _isFetchPrevented(resource: MXLPerformanceResourceTiming): boolean {\n return this._hasNoSizeData(resource) && resource.fetchStart === 0;\n }\n\n /**\n * Detect cache validation (304 Not Modified responses)\n *\n * 304 responses show transferSize of ~300 bytes (headers only, no body).\n * Use deliveryType to distinguish from cache hits: 'cache' = no network, otherwise = 304.\n *\n * Spec: https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-transfersize\n */\n private _isCacheValidated(resource: MXLPerformanceResourceTiming): boolean {\n // DeliveryType is Chromium only, so an engine without it never reads 'cache'.\n return resource.transferSize === 300 && resource.deliveryType !== 'cache';\n }\n\n /**\n * Add diagnostic attributes to identify resource loading issues\n *\n * Diagnostic attributes help identify why resources may have incomplete timing data:\n * - CORS restrictions (opaque responses without Timing-Allow-Origin header)\n * - Cache revalidation (304 Not Modified responses)\n * - Request incomplete (started but didn't complete - network error, aborted)\n * - Request prevented (never started - blocked by CSP, browser, extension)\n *\n * The size and timing fields read below are always numbers: a cross-origin\n * resource with no Timing-Allow-Origin reports them as 0 rather than omitting\n * them, and a resource only reaches here once it has produced a span, which\n * required a numeric fetchStart.\n */\n private _addResourceDiagnosticAttributes(\n span: Span,\n resource: MXLPerformanceResourceTiming,\n ): void {\n if (this._isCorsRestricted(resource)) {\n span.setAttribute(ATTR_HTTP_RESPONSE_CORS_OPAQUE, true);\n } else if (this._isFetchIncomplete(resource)) {\n span.setAttribute(ATTR_HTTP_REQUEST_INCOMPLETE, true);\n } else if (this._isFetchPrevented(resource)) {\n span.setAttribute(ATTR_HTTP_REQUEST_PREVENTED, true);\n }\n\n if (this._isCacheValidated(resource)) {\n span.setAttribute(ATTR_HTTP_RESPONSE_CACHE_REVALIDATED, true);\n }\n }\n\n protected override onEnable(): void {\n // An unbuffered subscription registered after the load event is never\n // notified, so collect straight away instead of observing. Deferred a\n // microtask because under registerGlobally: false the tracer provider\n // arrives later in this same task, and earlier spans reach a no-op tracer.\n if (this._isLoadEventFinished()) {\n queueMicrotask(() => {\n if (this._isEnabled) {\n this._collectIfLoadEventFinished();\n }\n });\n return;\n }\n\n // Buffered must stay false: mid-load, WebKit answers a buffered\n // subscription with the unfinished entry and counts it as the observer's\n // one notification, so the finalized entry never arrives.\n this._navigationObserver = createPerformanceObserver(\n 'navigation',\n () => {\n this._collectIfLoadEventFinished();\n },\n { buffered: false, diag: this._diag },\n );\n\n if (!this._navigationObserver) {\n this._diag.warn(\n 'navigation entries are not observable, document load will not be collected',\n );\n }\n }\n\n protected override onDisable(): void {\n this._disconnectObserver();\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAyEA,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,mCAAmC;AACzC,MAAM,2CACJ;AAGF,MAAM,iCAAiC;AACvC,MAAM,uCAAuC;AAC7C,MAAM,+BAA+B;AACrC,MAAM,8BAA8B;AACpC,MAAM,sCAAsC;AAE5C,IAAa,8BAAb,cAAiD,uBAA0D;CACzG,sBAA0D;CAC1D,wBAAgC;CAEhC,YAAmB,EACjB,MACA,MACA,SACA,6BACA,+BAA+B,OAC/B,sBAAsB,UACe,EAAE,EAAE;AACzC,QAAM;GACJ,QAAQ;IACN;IACA;IACA;IACA;IACD;GACD;GACA,qBAAqB;GACrB,wBAAwB;GACxB;GACD,CAAC;AAEF,MAAI,KAAK,Q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D;AACtE,SACE,SAAS,iBAAiB,KAC1B,SAAS,oBAAoB,KAC7B,SAAS,oBAAoB;;CAIjC,eAAuB,UAAiD;AACtE,SAAO,SAAS,aAAa,KAAK,SAAS,cAAc;;CAG3D,kBAA0B,UAAiD;AACzE,SAAO,KAAK,eAAe,SAAS,IAAI,KAAK,eAAe,SAAS;;CAGvE,mBAA2B,UAAiD;AAC1E,SACE,KAAK,eAAe,SAAS,IAC7B,SAAS,aAAa,KACtB,SAAS,gBAAgB;;CAI7B,kBAA0B,UAAiD;AACzE,SAAO,KAAK,eAAe,SAAS,IAAI,SAAS,eAAe;;;;;;;;;;CAWlE,kBAA0B,UAAiD;AAEzE,SAAO,SAAS,iBAAiB,OAAO,SAAS,iBAAiB;;;;;;;;;;;;;;;;CAiBpE,iCACE,MACA,UACM;AACN,MAAI,KAAK,kBAAkB,SAAS,CAClC,MAAK,aAAa,gCAAgC,KAAK;WAC9C,KAAK,mBAAmB,SAAS,CAC1C,MAAK,aAAa,8BAA8B,KAAK;WAC5C,KAAK,kBAAkB,SAAS,CACzC,MAAK,aAAa,6BAA6B,KAAK;AAGtD,MAAI,KAAK,kBAAkB,SAAS,CAClC,MAAK,aAAa,sCAAsC,KAAK;;CAIjE,WAAoC;AAKlC,MAAI,KAAK,sBAAsB,EAAE;AAC/B,wBAAqB;AACnB,QAAI,KAAK,WACP,MAAK,6BAA6B;KAEpC;AACF;;AAMF,OAAK,sBAAsB,0BACzB,oBACM;AACJ,QAAK,6BAA6B;KAEpC;GAAE,UAAU;GAAO,MAAM,KAAK;GAAO,CACtC;AAED,MAAI,CAAC,KAAK,oBACR,MAAK,MAAM,KACT,6EACD;;CAIL,YAAqC;AACnC,OAAK,qBAAqB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.ts
|
|
3
|
+
let PerformanceTimingNames = /* @__PURE__ */ function(PerformanceTimingNames) {
|
|
4
|
+
PerformanceTimingNames["CONNECT_END"] = "connectEnd";
|
|
5
|
+
PerformanceTimingNames["CONNECT_START"] = "connectStart";
|
|
6
|
+
PerformanceTimingNames["DECODED_BODY_SIZE"] = "decodedBodySize";
|
|
7
|
+
PerformanceTimingNames["DOM_COMPLETE"] = "domComplete";
|
|
8
|
+
PerformanceTimingNames["DOM_CONTENT_LOADED_EVENT_END"] = "domContentLoadedEventEnd";
|
|
9
|
+
PerformanceTimingNames["DOM_CONTENT_LOADED_EVENT_START"] = "domContentLoadedEventStart";
|
|
10
|
+
PerformanceTimingNames["DOM_INTERACTIVE"] = "domInteractive";
|
|
11
|
+
PerformanceTimingNames["DOMAIN_LOOKUP_END"] = "domainLookupEnd";
|
|
12
|
+
PerformanceTimingNames["DOMAIN_LOOKUP_START"] = "domainLookupStart";
|
|
13
|
+
PerformanceTimingNames["ENCODED_BODY_SIZE"] = "encodedBodySize";
|
|
14
|
+
PerformanceTimingNames["FETCH_START"] = "fetchStart";
|
|
15
|
+
PerformanceTimingNames["LOAD_EVENT_END"] = "loadEventEnd";
|
|
16
|
+
PerformanceTimingNames["LOAD_EVENT_START"] = "loadEventStart";
|
|
17
|
+
PerformanceTimingNames["NAVIGATION_START"] = "navigationStart";
|
|
18
|
+
PerformanceTimingNames["REDIRECT_END"] = "redirectEnd";
|
|
19
|
+
PerformanceTimingNames["REDIRECT_START"] = "redirectStart";
|
|
20
|
+
PerformanceTimingNames["REQUEST_START"] = "requestStart";
|
|
21
|
+
PerformanceTimingNames["RESPONSE_END"] = "responseEnd";
|
|
22
|
+
PerformanceTimingNames["RESPONSE_START"] = "responseStart";
|
|
23
|
+
PerformanceTimingNames["SECURE_CONNECTION_START"] = "secureConnectionStart";
|
|
24
|
+
PerformanceTimingNames["START_TIME"] = "startTime";
|
|
25
|
+
PerformanceTimingNames["UNLOAD_EVENT_END"] = "unloadEventEnd";
|
|
26
|
+
PerformanceTimingNames["UNLOAD_EVENT_START"] = "unloadEventStart";
|
|
27
|
+
return PerformanceTimingNames;
|
|
28
|
+
}({});
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.PerformanceTimingNames = PerformanceTimingNames;
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=PerformanceTimingNames.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PerformanceTimingNames.cjs","names":[],"sources":["../../../../../src/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.ts"],"sourcesContent":["/*\n * Adapted from @opentelemetry/sdk-trace-web@2.12.0\n * https://github.com/open-telemetry/opentelemetry-js/blob/v2.12.0/packages/opentelemetry-sdk-trace-web/src/enums/PerformanceTimingNames.ts\n */\n\nexport enum PerformanceTimingNames {\n CONNECT_END = 'connectEnd',\n CONNECT_START = 'connectStart',\n DECODED_BODY_SIZE = 'decodedBodySize',\n DOM_COMPLETE = 'domComplete',\n DOM_CONTENT_LOADED_EVENT_END = 'domContentLoadedEventEnd',\n DOM_CONTENT_LOADED_EVENT_START = 'domContentLoadedEventStart',\n DOM_INTERACTIVE = 'domInteractive',\n DOMAIN_LOOKUP_END = 'domainLookupEnd',\n DOMAIN_LOOKUP_START = 'domainLookupStart',\n ENCODED_BODY_SIZE = 'encodedBodySize',\n FETCH_START = 'fetchStart',\n LOAD_EVENT_END = 'loadEventEnd',\n LOAD_EVENT_START = 'loadEventStart',\n NAVIGATION_START = 'navigationStart',\n REDIRECT_END = 'redirectEnd',\n REDIRECT_START = 'redirectStart',\n REQUEST_START = 'requestStart',\n RESPONSE_END = 'responseEnd',\n RESPONSE_START = 'responseStart',\n SECURE_CONNECTION_START = 'secureConnectionStart',\n START_TIME = 'startTime',\n UNLOAD_EVENT_END = 'unloadEventEnd',\n UNLOAD_EVENT_START = 'unloadEventStart',\n}\n"],"mappings":";;AAKA,IAAY,yBAAL,yBAAA,wBAAA;AACL,wBAAA,iBAAA;AACA,wBAAA,mBAAA;AACA,wBAAA,uBAAA;AACA,wBAAA,kBAAA;AACA,wBAAA,kCAAA;AACA,wBAAA,oCAAA;AACA,wBAAA,qBAAA;AACA,wBAAA,uBAAA;AACA,wBAAA,yBAAA;AACA,wBAAA,uBAAA;AACA,wBAAA,iBAAA;AACA,wBAAA,oBAAA;AACA,wBAAA,sBAAA;AACA,wBAAA,sBAAA;AACA,wBAAA,kBAAA;AACA,wBAAA,oBAAA;AACA,wBAAA,mBAAA;AACA,wBAAA,kBAAA;AACA,wBAAA,oBAAA;AACA,wBAAA,6BAAA;AACA,wBAAA,gBAAA;AACA,wBAAA,sBAAA;AACA,wBAAA,wBAAA;;KACD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.d.ts
|
|
2
|
+
declare enum PerformanceTimingNames {
|
|
3
|
+
CONNECT_END = "connectEnd",
|
|
4
|
+
CONNECT_START = "connectStart",
|
|
5
|
+
DECODED_BODY_SIZE = "decodedBodySize",
|
|
6
|
+
DOM_COMPLETE = "domComplete",
|
|
7
|
+
DOM_CONTENT_LOADED_EVENT_END = "domContentLoadedEventEnd",
|
|
8
|
+
DOM_CONTENT_LOADED_EVENT_START = "domContentLoadedEventStart",
|
|
9
|
+
DOM_INTERACTIVE = "domInteractive",
|
|
10
|
+
DOMAIN_LOOKUP_END = "domainLookupEnd",
|
|
11
|
+
DOMAIN_LOOKUP_START = "domainLookupStart",
|
|
12
|
+
ENCODED_BODY_SIZE = "encodedBodySize",
|
|
13
|
+
FETCH_START = "fetchStart",
|
|
14
|
+
LOAD_EVENT_END = "loadEventEnd",
|
|
15
|
+
LOAD_EVENT_START = "loadEventStart",
|
|
16
|
+
NAVIGATION_START = "navigationStart",
|
|
17
|
+
REDIRECT_END = "redirectEnd",
|
|
18
|
+
REDIRECT_START = "redirectStart",
|
|
19
|
+
REQUEST_START = "requestStart",
|
|
20
|
+
RESPONSE_END = "responseEnd",
|
|
21
|
+
RESPONSE_START = "responseStart",
|
|
22
|
+
SECURE_CONNECTION_START = "secureConnectionStart",
|
|
23
|
+
START_TIME = "startTime",
|
|
24
|
+
UNLOAD_EVENT_END = "unloadEventEnd",
|
|
25
|
+
UNLOAD_EVENT_START = "unloadEventStart"
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { PerformanceTimingNames };
|
|
29
|
+
//# sourceMappingURL=PerformanceTimingNames.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PerformanceTimingNames.d.cts","names":[],"sources":["../../../../../src/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.ts"],"mappings":";aAKY,sBAAA;EACV,WAAA;EACA,aAAA;EACA,iBAAA;EACA,YAAA;EACA,4BAAA;EACA,8BAAA;EACA,eAAA;EACA,iBAAA;EACA,mBAAA;EACA,iBAAA;EACA,WAAA;EACA,cAAA;EACA,gBAAA;EACA,gBAAA;EACA,YAAA;EACA,cAAA;EACA,aAAA;EACA,YAAA;EACA,cAAA;EACA,uBAAA;EACA,UAAA;EACA,gBAAA;EACA,kBAAA;AAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.d.ts
|
|
2
|
+
declare enum PerformanceTimingNames {
|
|
3
|
+
CONNECT_END = "connectEnd",
|
|
4
|
+
CONNECT_START = "connectStart",
|
|
5
|
+
DECODED_BODY_SIZE = "decodedBodySize",
|
|
6
|
+
DOM_COMPLETE = "domComplete",
|
|
7
|
+
DOM_CONTENT_LOADED_EVENT_END = "domContentLoadedEventEnd",
|
|
8
|
+
DOM_CONTENT_LOADED_EVENT_START = "domContentLoadedEventStart",
|
|
9
|
+
DOM_INTERACTIVE = "domInteractive",
|
|
10
|
+
DOMAIN_LOOKUP_END = "domainLookupEnd",
|
|
11
|
+
DOMAIN_LOOKUP_START = "domainLookupStart",
|
|
12
|
+
ENCODED_BODY_SIZE = "encodedBodySize",
|
|
13
|
+
FETCH_START = "fetchStart",
|
|
14
|
+
LOAD_EVENT_END = "loadEventEnd",
|
|
15
|
+
LOAD_EVENT_START = "loadEventStart",
|
|
16
|
+
NAVIGATION_START = "navigationStart",
|
|
17
|
+
REDIRECT_END = "redirectEnd",
|
|
18
|
+
REDIRECT_START = "redirectStart",
|
|
19
|
+
REQUEST_START = "requestStart",
|
|
20
|
+
RESPONSE_END = "responseEnd",
|
|
21
|
+
RESPONSE_START = "responseStart",
|
|
22
|
+
SECURE_CONNECTION_START = "secureConnectionStart",
|
|
23
|
+
START_TIME = "startTime",
|
|
24
|
+
UNLOAD_EVENT_END = "unloadEventEnd",
|
|
25
|
+
UNLOAD_EVENT_START = "unloadEventStart"
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { PerformanceTimingNames };
|
|
29
|
+
//# sourceMappingURL=PerformanceTimingNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PerformanceTimingNames.d.ts","names":[],"sources":["../../../../../src/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.ts"],"mappings":";aAKY,sBAAA;EACV,WAAA;EACA,aAAA;EACA,iBAAA;EACA,YAAA;EACA,4BAAA;EACA,8BAAA;EACA,eAAA;EACA,iBAAA;EACA,mBAAA;EACA,iBAAA;EACA,WAAA;EACA,cAAA;EACA,gBAAA;EACA,gBAAA;EACA,YAAA;EACA,cAAA;EACA,aAAA;EACA,YAAA;EACA,cAAA;EACA,uBAAA;EACA,UAAA;EACA,gBAAA;EACA,kBAAA;AAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.ts
|
|
2
|
+
let PerformanceTimingNames = /* @__PURE__ */ function(PerformanceTimingNames) {
|
|
3
|
+
PerformanceTimingNames["CONNECT_END"] = "connectEnd";
|
|
4
|
+
PerformanceTimingNames["CONNECT_START"] = "connectStart";
|
|
5
|
+
PerformanceTimingNames["DECODED_BODY_SIZE"] = "decodedBodySize";
|
|
6
|
+
PerformanceTimingNames["DOM_COMPLETE"] = "domComplete";
|
|
7
|
+
PerformanceTimingNames["DOM_CONTENT_LOADED_EVENT_END"] = "domContentLoadedEventEnd";
|
|
8
|
+
PerformanceTimingNames["DOM_CONTENT_LOADED_EVENT_START"] = "domContentLoadedEventStart";
|
|
9
|
+
PerformanceTimingNames["DOM_INTERACTIVE"] = "domInteractive";
|
|
10
|
+
PerformanceTimingNames["DOMAIN_LOOKUP_END"] = "domainLookupEnd";
|
|
11
|
+
PerformanceTimingNames["DOMAIN_LOOKUP_START"] = "domainLookupStart";
|
|
12
|
+
PerformanceTimingNames["ENCODED_BODY_SIZE"] = "encodedBodySize";
|
|
13
|
+
PerformanceTimingNames["FETCH_START"] = "fetchStart";
|
|
14
|
+
PerformanceTimingNames["LOAD_EVENT_END"] = "loadEventEnd";
|
|
15
|
+
PerformanceTimingNames["LOAD_EVENT_START"] = "loadEventStart";
|
|
16
|
+
PerformanceTimingNames["NAVIGATION_START"] = "navigationStart";
|
|
17
|
+
PerformanceTimingNames["REDIRECT_END"] = "redirectEnd";
|
|
18
|
+
PerformanceTimingNames["REDIRECT_START"] = "redirectStart";
|
|
19
|
+
PerformanceTimingNames["REQUEST_START"] = "requestStart";
|
|
20
|
+
PerformanceTimingNames["RESPONSE_END"] = "responseEnd";
|
|
21
|
+
PerformanceTimingNames["RESPONSE_START"] = "responseStart";
|
|
22
|
+
PerformanceTimingNames["SECURE_CONNECTION_START"] = "secureConnectionStart";
|
|
23
|
+
PerformanceTimingNames["START_TIME"] = "startTime";
|
|
24
|
+
PerformanceTimingNames["UNLOAD_EVENT_END"] = "unloadEventEnd";
|
|
25
|
+
PerformanceTimingNames["UNLOAD_EVENT_START"] = "unloadEventStart";
|
|
26
|
+
return PerformanceTimingNames;
|
|
27
|
+
}({});
|
|
28
|
+
//#endregion
|
|
29
|
+
export { PerformanceTimingNames };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=PerformanceTimingNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PerformanceTimingNames.js","names":[],"sources":["../../../../../src/instrumentations/document-load/DocumentLoadInstrumentation/enums/PerformanceTimingNames.ts"],"sourcesContent":["/*\n * Adapted from @opentelemetry/sdk-trace-web@2.12.0\n * https://github.com/open-telemetry/opentelemetry-js/blob/v2.12.0/packages/opentelemetry-sdk-trace-web/src/enums/PerformanceTimingNames.ts\n */\n\nexport enum PerformanceTimingNames {\n CONNECT_END = 'connectEnd',\n CONNECT_START = 'connectStart',\n DECODED_BODY_SIZE = 'decodedBodySize',\n DOM_COMPLETE = 'domComplete',\n DOM_CONTENT_LOADED_EVENT_END = 'domContentLoadedEventEnd',\n DOM_CONTENT_LOADED_EVENT_START = 'domContentLoadedEventStart',\n DOM_INTERACTIVE = 'domInteractive',\n DOMAIN_LOOKUP_END = 'domainLookupEnd',\n DOMAIN_LOOKUP_START = 'domainLookupStart',\n ENCODED_BODY_SIZE = 'encodedBodySize',\n FETCH_START = 'fetchStart',\n LOAD_EVENT_END = 'loadEventEnd',\n LOAD_EVENT_START = 'loadEventStart',\n NAVIGATION_START = 'navigationStart',\n REDIRECT_END = 'redirectEnd',\n REDIRECT_START = 'redirectStart',\n REQUEST_START = 'requestStart',\n RESPONSE_END = 'responseEnd',\n RESPONSE_START = 'responseStart',\n SECURE_CONNECTION_START = 'secureConnectionStart',\n START_TIME = 'startTime',\n UNLOAD_EVENT_END = 'unloadEventEnd',\n UNLOAD_EVENT_START = 'unloadEventStart',\n}\n"],"mappings":";AAKA,IAAY,yBAAL,yBAAA,wBAAA;AACL,wBAAA,iBAAA;AACA,wBAAA,mBAAA;AACA,wBAAA,uBAAA;AACA,wBAAA,kBAAA;AACA,wBAAA,kCAAA;AACA,wBAAA,oCAAA;AACA,wBAAA,qBAAA;AACA,wBAAA,uBAAA;AACA,wBAAA,yBAAA;AACA,wBAAA,uBAAA;AACA,wBAAA,iBAAA;AACA,wBAAA,oBAAA;AACA,wBAAA,sBAAA;AACA,wBAAA,sBAAA;AACA,wBAAA,kBAAA;AACA,wBAAA,oBAAA;AACA,wBAAA,mBAAA;AACA,wBAAA,kBAAA;AACA,wBAAA,oBAAA;AACA,wBAAA,6BAAA;AACA,wBAAA,gBAAA;AACA,wBAAA,sBAAA;AACA,wBAAA,wBAAA;;KACD"}
|