Custom start and end time for a span
skjindal93 opened this issue · comments
Is there any way I can specify a custom start and end time for a span, instead of just using the time when span.start
and span.end
is called?
I am actually trying to send a span for a resource from Resource Timing API. The Resource Timing API has a startTime
and endTime = startTime + duration
for each resource.
But, I am unable to start and end a span using startTime
and endTime
from Resource Timing API.
Great question - have you seen the getResourceSpan function that creates a Span from a Resource Timing API entry? Might that do what you need?
The way it works is by setting the startPerfTime
and endPerfTime
span attributes, which correspond to the browser performance clock. Those attributes were designed to make creating spans from the resource timing API (or via performance.now
calls) easy.
I think there should be a separate function to set endPerfTime. That time should be honored while ending the span.
The reason being I want to end a span by calling span.end()
, but also set a custom end time to the span.
OK, thanks for clarifying. So would having a setEndPerfTime
function be all you need?
Currently endPerfTime
is a mutable property of the span:
I had not created a setEndPerfTime
function just because it felt a bit redundant with setting the property to me, but if that makes things cleaner to use, I'm open to adding it!
The pain point is that I have a root span. When I end the root span, it sets the endPerfTime
as the current time. The end function also adds the root span into the buffer.
It does not make sense to overwrite the endPerfTime
by doing span. endPerfTime
after the end function has been called.
Having a function to set custom end time before ending the span will be useful. While ending the span, there can be a check if endPerfTime
has already been set.
Makes sense! We could create a setEndPerfTime
function, and then to make the end
function only set endPerfTime
to performance.now()
if it's not zero.
I will plan to get a PR out for this when I get a chance (may not be until later this month). Your contribution to fix this would also be welcomed :)
Thanks for the PR! This is now fixed and is in the 0.0.3
release.