|
1 | 1 | // eslint-disable-next-line import/no-webpack-loader-syntax |
2 | 2 | import Worker from "worker-loader!./Worker.js"; |
3 | 3 | import * as Comlink from 'comlink'; |
4 | | -import {bookSetState, bookState, currentStepName, moveStep, ranCode} from "./book/store"; |
| 4 | +import { |
| 5 | + bookSetState, |
| 6 | + bookState, |
| 7 | + currentStepName, |
| 8 | + databaseRequest, |
| 9 | + isProduction, |
| 10 | + logEvent, |
| 11 | + moveStep, |
| 12 | + ranCode |
| 13 | +} from "./book/store"; |
5 | 14 | import _ from "lodash"; |
6 | 15 | import localforage from "localforage"; |
7 | 16 | import {animateScroll} from "react-scroll"; |
@@ -52,21 +61,37 @@ const runCodeRemote = async (entry, onSuccess) => { |
52 | 61 |
|
53 | 62 | export const runCode = ({code, source}) => { |
54 | 63 | const shell = source === "shell"; |
| 64 | + const {route, user, questionWizard, editorContent, numHints, requestingSolution} = bookState; |
55 | 65 | if (!shell && !code) { |
56 | | - code = bookState.editorContent; |
| 66 | + code = editorContent; |
57 | 67 | } |
58 | 68 | bookSetState("processing", true); |
59 | 69 | const entry = { |
60 | 70 | input: code, |
61 | 71 | source, |
62 | | - page_slug: bookState.user.pageSlug, |
| 72 | + page_slug: user.pageSlug, |
63 | 73 | step_name: currentStepName(), |
64 | | - question_wizard: bookState.route === "question", |
65 | | - expected_output: bookState.questionWizard.expectedOutput, |
| 74 | + question_wizard: route === "question", |
| 75 | + expected_output: questionWizard.expectedOutput, |
66 | 76 | }; |
67 | 77 |
|
68 | 78 | const onSuccess = (data) => { |
69 | 79 | const {error} = data; |
| 80 | + |
| 81 | + logEvent('run_code', { |
| 82 | + code_source: entry.source, |
| 83 | + page_slug: entry.page_slug, |
| 84 | + step_name: entry.step_name, |
| 85 | + entry_passed: data.passed, |
| 86 | + has_error: Boolean(error), |
| 87 | + num_messages: data.messages.length, |
| 88 | + // user: user.uid, |
| 89 | + // developerMode: user.developerMode, |
| 90 | + page_route: route, |
| 91 | + num_hints: numHints, |
| 92 | + requesting_solution: requestingSolution, |
| 93 | + }); |
| 94 | + |
70 | 95 | if (error) { |
71 | 96 | Sentry.captureEvent(error.sentry_event); |
72 | 97 | delete error.sentry_event; |
@@ -107,6 +132,24 @@ export const runCode = ({code, source}) => { |
107 | 132 | showCodeResult(data); |
108 | 133 | terminalRef.current.focusTerminal(); |
109 | 134 | } |
| 135 | + |
| 136 | + if (isProduction) { |
| 137 | + databaseRequest("POST", { |
| 138 | + entry, |
| 139 | + result: { |
| 140 | + ..._.omit(data, "output_parts"), |
| 141 | + messages: data.messages.map(m => _.truncate(m, {length: 1000})), |
| 142 | + output: _.truncate(data.output, {length: 1000}), |
| 143 | + }, |
| 144 | + state: { |
| 145 | + developerMode: user.developerMode, |
| 146 | + page_route: route, |
| 147 | + num_hints: numHints, |
| 148 | + requesting_solution: requestingSolution, |
| 149 | + }, |
| 150 | + timestamp: new Date().toISOString(), |
| 151 | + }, "code_entries"); |
| 152 | + } |
110 | 153 | } |
111 | 154 |
|
112 | 155 | runCodeRemote(entry, onSuccess); |
|
0 commit comments