Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(instrumentation-document-load): documentLoad attributes enhancement #441

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentLoad span is the root one so I think previous names were mistaken?


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