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

Missing fields on Fetch PerformanceResourceTiming instance #2515

Open
Ethan-Arrowood opened this issue Dec 8, 2023 · 6 comments
Open

Missing fields on Fetch PerformanceResourceTiming instance #2515

Ethan-Arrowood opened this issue Dec 8, 2023 · 6 comments
Labels
bug Something isn't working fetch

Comments

@Ethan-Arrowood
Copy link
Collaborator

Does anyone know why the PerformanceResourceTiming instance is missing information regarding DNS and what not?

Here is an example:

PerformanceResourceTiming {
    name: 'https://example.com/',
    entryType: 'resource',
    startTime: 257.69891691207886,
    duration: 98.86862516403198,
    initiatorType: 'fetch',
    nextHopProtocol: undefined,
    workerStart: 0,
    redirectStart: 0,
    redirectEnd: 0,
    fetchStart: 257.69891691207886,
    domainLookupStart: undefined,
    domainLookupEnd: undefined,
    connectStart: undefined,
    connectEnd: undefined,
    secureConnectionStart: undefined,
    requestStart: 0,
    responseStart: 0,
    responseEnd: 356.56754207611084,
    transferSize: 300,
    encodedBodySize: 0,
    decodedBodySize: 0
  }

That you get from a simple script like:

const url = new URL('https://example.com')
const res1 = await fetch(url);

await res1.text();

const fetchEntry = perfHooks.performance.getEntriesByName(url);
console.log(fetchEntry);

I tracked down the places in the source code where this gets created:

  1. undici/lib/fetch/index.js

    Lines 311 to 325 in 8422aa9

    markResourceTiming(
    timingInfo,
    originalURL,
    initiatorType,
    globalThis,
    cacheState
    )
    }
    // https://w3c.github.io/resource-timing/#dfn-mark-resource-timing
    function markResourceTiming (timingInfo, originalURL, initiatorType, globalThis, cacheState) {
    if (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2)) {
    performance.markResourceTiming(timingInfo, originalURL.href, initiatorType, globalThis, cacheState)
    }
    }
  2. https://github.com/nodejs/node/blob/main/lib/internal/perf/resource_timing.js#L205-L228

But it's still not immediately clear to me how to fix this. Any ideas?

@Ethan-Arrowood Ethan-Arrowood added the bug Something isn't working label Dec 8, 2023
@Ethan-Arrowood
Copy link
Collaborator Author

I think I found it: https://github.com/nodejs/undici/blob/main/lib/fetch/util.js#L274-L288

These are all 0 - we need to figure out how to populate these values correctly.

@Ethan-Arrowood
Copy link
Collaborator Author

And the relevant part of the spec that would be setting some of these values (such as domainLookupStartTime (https://fetch.spec.whatwg.org/#ref-for-connection-timing-info-domain-lookup-start-time)

@Ethan-Arrowood
Copy link
Collaborator Author

Ethan-Arrowood commented Dec 8, 2023

Found it for real:

// 9. Run these steps, but abort when the ongoing fetch is terminated:

its just not implemented.

Someone is welcome to take this on if they'd like. Otherwise I may be able to next week.

@Ethan-Arrowood
Copy link
Collaborator Author

Some relevant places to completely implement performanceresourcetiming:

@Ethan-Arrowood
Copy link
Collaborator Author

@ronag where / how would I get access to the underlying connection and dns processes for fetch? I'm trying to add those timings to the PerformanceResourceTiming instance and I can't seem to find it.

@metcoder95
Copy link
Member

I think is not doable without using Symbols to access the Socket from the dispatcher (either through init or getting the global one).

For the DNS is even trickier, I don't think there's a way to intercept that without messing directly with the lookup option while connecting 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fetch
Projects
None yet
Development

No branches or pull requests

3 participants