open-telemetry / opentelemetry-js

OpenTelemetry JavaScript Client
https://opentelemetry.io
Apache License 2.0
2.64k stars 762 forks source link

The window.onerror method cannot obtain the correct error source, line number and column number #3447

Open yuanman0109 opened 1 year ago

yuanman0109 commented 1 year ago

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: image image

dyladan commented 1 year ago

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?

yuanman0109 commented 1 year ago

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

dyladan commented 1 year ago

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?

dyladan commented 1 year ago

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.

yuanman0109 commented 1 year ago

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