vaadin / observability-kit

Other
5 stars 2 forks source link

Trace errors in production for JavaScript executions sent by the server-side #188

Open mcollovati opened 1 year ago

mcollovati commented 1 year ago

JavaScript's errors raised when executing code sent from the server-side (e.g. Page.executeJs()) cannot be traced in production because Flow client silently suppresses them.

https://github.com/vaadin/flow/issues/2028 https://github.com/vaadin/flow/issues/2963

To be able to trace errors from the server-sent JavaScript code in production mode, we may need to tweak the Flow client Console.reportStacktrace() method.

public static void reportStacktrace(Exception exception) {
    if (GWT.isScript()) {
        if (shouldLogToBrowserConsole) {
            doReportStacktrace(exception);
        }
    } else {
        exception.printStackTrace();
    }
}

where shouldLogToBrowserConsole = !ApplicationConfiguration.isProductionMode

It seems to me that instrumenting the GWT generated JavaScript code is not possible, or at least not easy to accomplish.

Something we can maybe do is to add a traceErrors flag in Flow client ApplicationConfiguration, propagate it to Console and change the above method to consider also this configuration. Then, if we do not want the developers to be able to set the configuration on their own, we can try to add an instrumentation in Observability Kit that intercepts BootstrapHandler$ApplicationParameterBuilder.getApplicationParameters and adds the flag to the returned JsonObject.