Skip to content

Commit

Permalink
feat(instrumentation-document-load): documentLoad attributes enhancem…
Browse files Browse the repository at this point in the history
  • Loading branch information
kkruk-sumo authored May 5, 2021
1 parent 69d5f8a commit 209f336
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ export class DocumentLoadInstrumentation extends InstrumentationBase<unknown> {
}
});

rootSpan.setAttribute(SemanticAttributes.HTTP_URL, location.href);
rootSpan.setAttribute(
SemanticAttributes.HTTP_USER_AGENT,
navigator.userAgent
);

this._addResourcesSpans(rootSpan);

addSpanNetworkEvent(rootSpan, PTN.FETCH_START, entries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ const entriesFallback = {
loadEventEnd: 1571078170394,
} as any;

const userAgent =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36';

function ensureNetworkEventsExists(events: TimedEvent[]) {
assert.strictEqual(events[0].name, PTN.FETCH_START);
assert.strictEqual(events[1].name, PTN.DOMAIN_LOOKUP_START);
Expand All @@ -198,6 +201,7 @@ describe('DocumentLoad Instrumentation', () => {
writable: true,
value: 'complete',
});
sandbox.replaceGetter(navigator, 'userAgent', () => userAgent);
plugin = new DocumentLoadInstrumentation({
enabled: false,
});
Expand Down Expand Up @@ -492,31 +496,37 @@ describe('DocumentLoad Instrumentation', () => {
it('should export correct span with events', done => {
plugin.enable();
setTimeout(() => {
const rootSpan = exporter.getFinishedSpans()[0] as ReadableSpan;
const fetchSpan = exporter.getFinishedSpans()[1] as ReadableSpan;
const rsEvents = rootSpan.events;
const fetchSpan = exporter.getFinishedSpans()[0] as ReadableSpan;
const rootSpan = exporter.getFinishedSpans()[1] as ReadableSpan;
const fsEvents = fetchSpan.events;
const rsEvents = rootSpan.events;

assert.strictEqual(rootSpan.name, 'documentFetch');
assert.strictEqual(fetchSpan.name, 'documentLoad');
assert.strictEqual(fetchSpan.name, 'documentFetch');
assert.strictEqual(rootSpan.name, 'documentLoad');

ensureNetworkEventsExists(rsEvents);
assert.strictEqual(
rootSpan.attributes['http.url'],
'http://localhost:9876/context.html'
);
assert.strictEqual(rootSpan.attributes['http.user_agent'], userAgent);

assert.strictEqual(fsEvents[0].name, PTN.FETCH_START);
assert.strictEqual(fsEvents[1].name, PTN.UNLOAD_EVENT_START);
assert.strictEqual(fsEvents[2].name, PTN.UNLOAD_EVENT_END);
assert.strictEqual(fsEvents[3].name, PTN.DOM_INTERACTIVE);
ensureNetworkEventsExists(fsEvents);

assert.strictEqual(rsEvents[0].name, PTN.FETCH_START);
assert.strictEqual(rsEvents[1].name, PTN.UNLOAD_EVENT_START);
assert.strictEqual(rsEvents[2].name, PTN.UNLOAD_EVENT_END);
assert.strictEqual(rsEvents[3].name, PTN.DOM_INTERACTIVE);
assert.strictEqual(
fsEvents[4].name,
rsEvents[4].name,
PTN.DOM_CONTENT_LOADED_EVENT_START
);
assert.strictEqual(fsEvents[5].name, PTN.DOM_CONTENT_LOADED_EVENT_END);
assert.strictEqual(fsEvents[6].name, PTN.DOM_COMPLETE);
assert.strictEqual(fsEvents[7].name, PTN.LOAD_EVENT_START);
assert.strictEqual(fsEvents[8].name, PTN.LOAD_EVENT_END);
assert.strictEqual(rsEvents[5].name, PTN.DOM_CONTENT_LOADED_EVENT_END);
assert.strictEqual(rsEvents[6].name, PTN.DOM_COMPLETE);
assert.strictEqual(rsEvents[7].name, PTN.LOAD_EVENT_START);
assert.strictEqual(rsEvents[8].name, PTN.LOAD_EVENT_END);

assert.strictEqual(rsEvents.length, 9);
assert.strictEqual(fsEvents.length, 9);
assert.strictEqual(rsEvents.length, 9);
assert.strictEqual(exporter.getFinishedSpans().length, 2);
done();
});
Expand Down

0 comments on commit 209f336

Please sign in to comment.