opentelemetry-js
opentelemetry-js copied to clipboard
Invalid timings sent by instrumentations (xhr,fetch,resource)
When browser navigation or resource timing apis don't set a certain timing value or report it as 0 (e.g connectionStart, responseStart,...) the spans generated by instrumentations like like xhr/fetch/resource report a value that is lower than fetchStart ( timeOrigin ) , which can result in wrong metrics by backend. Can we avoid reporting this invalid timings by either checking if their value is above 0, or above a certain reference time like fetchStart
Here is a sample payload from xhr with such issues, It is a failed xhr request and the values from domainLookupStart up to responseEnd show a lower value than fetchStart. Similar issue can happen to cached requests, or aborted requests too.
events: [ { "attributes": [], "name": "open", "timeUnixNano": "1707848692048000000", "droppedAttributesCount": 0 }, { "attributes": [], "name": "send", "timeUnixNano": "1707848692048200000", "droppedAttributesCount": 0 }, { "attributes": [], "name": "fetchStart", "timeUnixNano": "1707848692048699951", "droppedAttributesCount": 0 }, { "attributes": [], "name": "domainLookupStart", "timeUnixNano": "1707848675667199951", "droppedAttributesCount": 0 }, { "attributes": [], "name": "domainLookupEnd", "timeUnixNano": "1707848675667199951", "droppedAttributesCount": 0 }, { "attributes": [], "name": "connectStart", "timeUnixNano": "1707848675667199951", "droppedAttributesCount": 0 }, { "attributes": [], "name": "connectEnd", "timeUnixNano": "1707848675667199951", "droppedAttributesCount": 0 }, { "attributes": [], "name": "requestStart", "timeUnixNano": "1707848675667199951", "droppedAttributesCount": 0 }, { "attributes": [], "name": "responseStart", "timeUnixNano": "1707848675667199951", "droppedAttributesCount": 0 }, { "attributes": [], "name": "responseEnd", "timeUnixNano": "1707848692057099951", "droppedAttributesCount": 0 }, { "attributes": [], "name": "error", "timeUnixNano": "1707848692058000000", "droppedAttributesCount": 0 } ]
Here is how the events are added to spans,
https://github.com/open-telemetry/opentelemetry-js/blob/44b0b29dea98217130bc4e68d6c9b6901e75aef7/packages/opentelemetry-sdk-trace-web/src/utils.ts#L60
@martinkuba , @MSNev , @scheler , @t2t2 , can you take a loot at this issue ?
I think we can add logic to check that these values are sane, but some of them have 0 as a valid value.