Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SIREPO.traceWS and better logging of ws messages #6250

Closed
robnagler opened this issue Aug 26, 2023 · 2 comments
Closed

Add SIREPO.traceWS and better logging of ws messages #6250

robnagler opened this issue Aug 26, 2023 · 2 comments

Comments

@robnagler
Copy link
Member

@e-carlin writes:

With websockets and a binary protocol that now doesn't work. What about adding a pkdc to parse_message and websocket_response that allows one to dump the message (with associated uri, seq num, etc)?

Add pkdc like feature called sr_trace or similar to sirepo.js. In the client, you can expand the object as opposed to cluttering a terminal window with all messages between client and server, which are often quite large. sr_trace could get the control regex from pkdebug. We could also set it dynamically in production from the js console.

function sr_trace(...args) {
    if (sr_trace_re) {
        if (sr_trace.caller === null || sr_trace_re.match(sr_trace.caller) {
             // probably want better formatting of sr_trace.caller
             console.log(sr_trace.caller, ...args);
        }
    }
}
@moellep
Copy link
Member

moellep commented Aug 31, 2023

Here's a simple implementation, which can be enabled on the client by typing "SIREPO.traceWS = true" in the javascript console. It logs the sequence number, url and data on the send, and sequence number, and either json content or content-type on replies:

@moellep
Copy link
Member

moellep commented Aug 31, 2023

@@ -2093,6 +2093,15 @@ SIREPO.app.factory('msgRouter', ($http, $interval, $q, $window, errorService) =>
             wsreq.deferred.reject("invalid reply from server");
             return;
         }
+        if (SIREPO.traceWS) {
+            srlog(
+                'ws reply:',
+                header.reqSeq,
+                header.contentType == "application/json"
+                    ? JSON.parse(content)
+                    : `<${header.contentType} content>`,
+            );
+        }
         wsreq.deferred.resolve({
             data: header.contentType == "application/json" ? JSON.parse(content) : content,
             status: header.httpStatus
@@ -2207,6 +2216,9 @@ SIREPO.app.factory('msgRouter', ($http, $interval, $q, $window, errorService) =>
         if (wsreq.timeout) {
             wsreq.timeout.then(() => {_remove(wsreq);});
         }
+        if (SIREPO.traceWS) {
+            srlog('ws send:', wsreq.header.reqSeq, url, data);
+        }
         const c = (buffers) => {

@robnagler robnagler changed the title Add sr_trace similar to pkdc Add SIREPO.traceWS and better logging of ws messages Sep 26, 2023
robnagler pushed a commit that referenced this issue Sep 26, 2023
Fix #6351 brilliance.py.jinja incorrect srwpy import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants