williaster commented on a change in pull request #4226: add frontend logging
functions and log loading time for Dashboard and explore view
URL:
https://github.com/apache/incubator-superset/pull/4226#discussion_r162572323
##########
File path: superset/assets/javascripts/logger.js
##########
@@ -0,0 +1,79 @@
+import $ from 'jquery';
+
+export const LOG_ACTIONS_LOAD_DASHBOARD = 'load_dashboard';
+export const LOG_ACTIONS_LOAD_EXPLORE = 'load_explore';
+export const LOAD_EVENT = 'load';
+
+export class ActionLog {
+ constructor({ action, containerId, eventName }) {
+ this.containerId = containerId;
+ this.action = action;
+ this.eventName = eventName;
+ this.startAt = 0;
+ this.duration = 0;
+ this.events = [];
+
+ this.addEvent = this.addEvent.bind(this);
+ }
+
+ setAttribute(name, value) {
+ this[name] = value;
+ }
+
+ addEvent(eventBody) {
+ this.events.push(eventBody);
+ }
+}
+
+const handlers = {};
+
+export default {
+ start(log) {
+ log.setAttribute('startAt', this.getTimestamp());
+ if (!handlers[log.eventName]) {
+ handlers[log.eventName] = [];
+ }
+ handlers[log.eventName].push(log.addEvent);
+ },
+
+ append(eventName, eventBody) {
+ return handlers[eventName].length &&
+ handlers[eventName].forEach((handler) => {
+ handler(eventBody);
+ });
+ },
+
+ end(log) {
+ log.setAttribute('duration', this.getTimestamp() - log.startAt);
+ this.send(log);
+
+ if (handlers[log.eventName].length) {
+ const index = handlers[log.eventName].findIndex(handler => (handler ===
log.addEvent));
+ handlers[log.eventName].splice(index, 1);
+ }
+ },
+
+ send(log) {
+ const { action, containerId, events, startAt, duration } = log;
+ const url = `/superset/${action}/?${action === LOG_ACTIONS_LOAD_DASHBOARD
? 'dashboard_id' : 'slice_id'}=${containerId}`;
+ const eventData = {};
+ events.forEach((event) => {
+ const { label, ...eventBody } = event;
Review comment:
it seems like `label` is functioning more like an event name or event key,
and all other object keys implicitly get mapped to meta data. could we make the
format of the logs more explicit and generic by having only `event` (or
`eventName`, to replace `label`) and `meta` keys, where `meta` is an object of
anything?
cc @john-bodley for naming/formatting.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services