opentelemetry-js
opentelemetry-js copied to clipboard
The window.onerror method cannot obtain the correct error source, line number and column number
- [ ] This only affects the JavaScript OpenTelemetry library
- [ ] This may affect other libraries, but I would like to get opinions here first
Because otel depends on zone. js, if there are js errors in the application, we want to get the error source and line number through window.onerror, but now it returns zone Position of throw error in js, The following is a snapshot of the location where the console prints the error:

Can you provide more details about your setup? I assume because of the zone context manager this must be a browser usecase. Are you using zone.js other than OTel? Unfortunately, OTel context propagation doesn't work at all without zone.js in the browser so you would need to manually propagate context in order to avoid its use. Do you believe this is caused by the existence of zone.js or a misuse by OTel?
Can you provide more details about your setup? I assume because of the zone context manager this must be a browser usecase. Are you using zone.js other than OTel? Unfortunately, OTel context propagation doesn't work at all without zone.js in the browser so you would need to manually propagate context in order to avoid its use. Do you believe this is caused by the existence of zone.js or a misuse by OTel?
Yes, I am an application on the browser. I use ZoneContextManager. This package is based on zone.js Instead of my extra introduction, it will try catch the error, so the source and line number of the error will become it. I hope window.onerror can return normal information, but at present, it can only be obtained through error.stack. If zone.js will take over the js error, what we can do now is to parse the stack information ourselves, i need the original error's stack
I'm sorry I am not a zone expert so I'm not sure how to interpret this. Do you have a current workaround for your application code or are you suggesting a fix for the zone context manager?
I'm going to label this as p4 since it is a bug but is not causing a crash or any incorrect telemetry to be emitted.
I'm sorry I am not a zone expert so I'm not sure how to interpret this. Do you have a current workaround for your application code or are you suggesting a fix for the zone context manager?
At present, no better solution has been found, but it is found that not all errors will be taken over by zone.js, so the scope of influence is small