diff --git a/plugins/web/opentelemetry-plugin-document-load/package.json b/plugins/web/opentelemetry-plugin-document-load/package.json index 2481938d64..d850821125 100644 --- a/plugins/web/opentelemetry-plugin-document-load/package.json +++ b/plugins/web/opentelemetry-plugin-document-load/package.json @@ -74,6 +74,7 @@ "dependencies": { "@opentelemetry/api": "^0.10.1", "@opentelemetry/core": "^0.10.1", + "@opentelemetry/semantic-conventions": "^0.10.1", "@opentelemetry/tracing": "^0.10.1", "@opentelemetry/web": "^0.10.1" } diff --git a/plugins/web/opentelemetry-plugin-document-load/src/documentLoad.ts b/plugins/web/opentelemetry-plugin-document-load/src/documentLoad.ts index bf05686d7f..7becf0a299 100644 --- a/plugins/web/opentelemetry-plugin-document-load/src/documentLoad.ts +++ b/plugins/web/opentelemetry-plugin-document-load/src/documentLoad.ts @@ -28,6 +28,7 @@ import { } from '@opentelemetry/core'; import { addSpanNetworkEvent, + addSpanNetworkEvents, hasKey, PerformanceEntries, PerformanceLegacy, @@ -35,6 +36,7 @@ import { } from '@opentelemetry/web'; import { AttributeNames } from './enums/AttributeNames'; import { VERSION } from './version'; +import { HttpAttribute } from '@opentelemetry/semantic-conventions'; /** * This class represents a document load plugin @@ -81,21 +83,6 @@ export class DocumentLoad extends BasePlugin { } } - /** - * Adds span network events - * @param span - * @param entries entries that contains performance information about resource - */ - private _addSpanNetworkEvents(span: Span, entries: PerformanceEntries) { - addSpanNetworkEvent(span, PTN.DOMAIN_LOOKUP_START, entries); - addSpanNetworkEvent(span, PTN.DOMAIN_LOOKUP_END, entries); - addSpanNetworkEvent(span, PTN.CONNECT_START, entries); - addSpanNetworkEvent(span, PTN.SECURE_CONNECTION_START, entries); - addSpanNetworkEvent(span, PTN.CONNECT_END, entries); - addSpanNetworkEvent(span, PTN.REQUEST_START, entries); - addSpanNetworkEvent(span, PTN.RESPONSE_START, entries); - } - /** * Collects information about performance and creates appropriate spans */ @@ -123,7 +110,7 @@ export class DocumentLoad extends BasePlugin { ); if (fetchSpan) { this._tracer.withSpan(fetchSpan, () => { - this._addSpanNetworkEvents(fetchSpan, entries); + addSpanNetworkEvents(fetchSpan, entries); this._endSpan(fetchSpan, PTN.RESPONSE_END, entries); }); } @@ -131,6 +118,7 @@ export class DocumentLoad extends BasePlugin { this._addResourcesSpans(rootSpan); + addSpanNetworkEvent(rootSpan, PTN.FETCH_START, entries); addSpanNetworkEvent(rootSpan, PTN.UNLOAD_EVENT_START, entries); addSpanNetworkEvent(rootSpan, PTN.UNLOAD_EVENT_END, entries); addSpanNetworkEvent(rootSpan, PTN.DOM_INTERACTIVE, entries); @@ -142,6 +130,7 @@ export class DocumentLoad extends BasePlugin { addSpanNetworkEvent(rootSpan, PTN.DOM_CONTENT_LOADED_EVENT_END, entries); addSpanNetworkEvent(rootSpan, PTN.DOM_COMPLETE, entries); addSpanNetworkEvent(rootSpan, PTN.LOAD_EVENT_START, entries); + addSpanNetworkEvent(rootSpan, PTN.LOAD_EVENT_END, entries); this._endSpan(rootSpan, PTN.LOAD_EVENT_END, entries); }); @@ -161,7 +150,6 @@ export class DocumentLoad extends BasePlugin { // span can be undefined when entries are missing the certain performance - the span will not be created if (span) { if (hasKey(entries, performanceName)) { - addSpanNetworkEvent(span, performanceName, entries); span.end(entries[performanceName]); } else { // just end span @@ -184,7 +172,7 @@ export class DocumentLoad extends BasePlugin { keys.forEach((key: string) => { if (hasKey(performanceNavigationTiming, key)) { const value = performanceNavigationTiming[key]; - if (typeof value === 'number' && value > 0) { + if (typeof value === 'number' && value >= 0) { entries[key] = value; } } @@ -198,7 +186,7 @@ export class DocumentLoad extends BasePlugin { keys.forEach((key: string) => { if (hasKey(performanceTiming, key)) { const value = performanceTiming[key]; - if (typeof value === 'number' && value > 0) { + if (typeof value === 'number' && value >= 0) { entries[key] = value; } } @@ -218,13 +206,14 @@ export class DocumentLoad extends BasePlugin { spanOptions: SpanOptions = {} ) { const span = this._startSpan( - resource.name, + AttributeNames.RESOURCE_FETCH, PTN.FETCH_START, resource, spanOptions ); if (span) { - this._addSpanNetworkEvents(span, resource); + span.setAttribute(HttpAttribute.HTTP_URL, resource.name); + addSpanNetworkEvents(span, resource); this._endSpan(span, PTN.RESPONSE_END, resource); } } @@ -257,7 +246,6 @@ export class DocumentLoad extends BasePlugin { ) ); span.setAttribute(AttributeNames.COMPONENT, this.component); - addSpanNetworkEvent(span, performanceName, entries); return span; } return undefined; diff --git a/plugins/web/opentelemetry-plugin-document-load/src/enums/AttributeNames.ts b/plugins/web/opentelemetry-plugin-document-load/src/enums/AttributeNames.ts index 9765fa1919..ad672fd016 100644 --- a/plugins/web/opentelemetry-plugin-document-load/src/enums/AttributeNames.ts +++ b/plugins/web/opentelemetry-plugin-document-load/src/enums/AttributeNames.ts @@ -18,4 +18,5 @@ export enum AttributeNames { COMPONENT = 'component', DOCUMENT_LOAD = 'documentLoad', DOCUMENT_FETCH = 'documentFetch', + RESOURCE_FETCH = 'resourceFetch', } diff --git a/plugins/web/opentelemetry-plugin-document-load/test/documentLoad.test.ts b/plugins/web/opentelemetry-plugin-document-load/test/documentLoad.test.ts index a6bfabee28..330a9efe77 100644 --- a/plugins/web/opentelemetry-plugin-document-load/test/documentLoad.test.ts +++ b/plugins/web/opentelemetry-plugin-document-load/test/documentLoad.test.ts @@ -40,6 +40,7 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { ExportResult } from '@opentelemetry/core'; import { DocumentLoad } from '../src'; +import { HttpAttribute } from '@opentelemetry/semantic-conventions'; export class DummyExporter implements SpanExporter { export( @@ -325,6 +326,11 @@ describe('DocumentLoad Plugin', () => { const fsEvents = fetchSpan.events; assert.strictEqual(rootSpan.name, 'documentFetch'); + assert.ok( + (rootSpan.attributes[ + HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH + ] as number) > 0 + ); assert.strictEqual(fetchSpan.name, 'documentLoad'); ensureNetworkEventsExists(rsEvents); @@ -418,11 +424,11 @@ describe('DocumentLoad Plugin', () => { const srEvents2 = spanResource2.events; assert.strictEqual( - spanResource1.name, + spanResource1.attributes[HttpAttribute.HTTP_URL], 'http://localhost:8090/bundle.js' ); assert.strictEqual( - spanResource2.name, + spanResource2.attributes[HttpAttribute.HTTP_URL], 'http://localhost:8090/sockjs-node/info?t=1572620894466' ); @@ -454,7 +460,7 @@ describe('DocumentLoad Plugin', () => { const srEvents1 = spanResource1.events; assert.strictEqual( - spanResource1.name, + spanResource1.attributes[HttpAttribute.HTTP_URL], 'http://localhost:8090/bundle.js' );