Skip to content

Commit 8d4bccc

Browse files
authored
feat: add meticulous recorder (coder#13886)
1 parent 4dcbd71 commit 8d4bccc

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ jobs:
966966
uses: actions/dependency-review-action@v4.3.2
967967
with:
968968
allow-licenses: Apache-2.0, 0BSD, BSD-2-Clause, BSD-3-Clause, CC0-1.0, ISC, MIT, MIT-0, MPL-2.0
969-
allow-dependencies-licenses: "pkg:golang/github.com/coder/wgtunnel@0.1.13-0.20240522110300-ade90dfb2da0, pkg:npm/pako@1.0.11, pkg:npm/caniuse-lite@1.0.30001639"
969+
allow-dependencies-licenses: "pkg:golang/github.com/coder/wgtunnel@0.1.13-0.20240522110300-ade90dfb2da0, pkg:npm/pako@1.0.11, pkg:npm/caniuse-lite@1.0.30001639, pkg:githubactions/alwaysmeticulous/report-diffs-action/cloud-compute"
970970
license-check: true
971971
vulnerability-check: false
972972
- name: "Report"
@@ -992,3 +992,23 @@ jobs:
992992
fi
993993
done
994994
echo "No incompatible licenses detected"
995+
meticulous:
996+
runs-on: ubuntu-latest
997+
steps:
998+
- name: "Checkout Repository"
999+
uses: actions/checkout@v4
1000+
- name: Setup Node
1001+
uses: ./.github/actions/setup-node
1002+
- name: Build
1003+
working-directory: ./site
1004+
run: pnpm build
1005+
- name: Serve
1006+
working-directory: ./site
1007+
run: |
1008+
pnpm vite preview &
1009+
sleep 5
1010+
- name: Run Meticulous tests
1011+
uses: alwaysmeticulous/report-diffs-action/cloud-compute@v1
1012+
with:
1013+
api-token: ${{ secrets.METICULOUS_API_TOKEN }}
1014+
app-url: "http://127.0.0.1:4173/"

coderd/httpmw/csp.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func CSPHeaders(telemetry bool, websocketHosts func() []string) func(next http.H
5959
cspDirectiveConnectSrc: {"'self'"},
6060
cspDirectiveChildSrc: {"'self'"},
6161
// https://github.com/suren-atoyan/monaco-react/issues/168
62-
cspDirectiveScriptSrc: {"'self'"},
62+
cspDirectiveScriptSrc: {"'self' "},
6363
cspDirectiveStyleSrc: {"'self' 'unsafe-inline'"},
6464
// data: is used by monaco editor on FE for Syntax Highlight
6565
cspDirectiveFontSrc: {"'self' data:"},
@@ -88,6 +88,11 @@ func CSPHeaders(telemetry bool, websocketHosts func() []string) func(next http.H
8888
if telemetry {
8989
// If telemetry is enabled, we report to coder.com.
9090
cspSrcs.Append(cspDirectiveConnectSrc, "https://coder.com")
91+
// These are necessary to allow meticulous to collect sampling to
92+
// improve our testing. Only remove these if we're no longer using
93+
// their services.
94+
cspSrcs.Append(cspDirectiveConnectSrc, meticulousConnectSrc...)
95+
cspSrcs.Append(cspDirectiveScriptSrc, meticulousScriptSrc...)
9196
}
9297

9398
// This extra connect-src addition is required to support old webkit
@@ -131,3 +136,8 @@ func CSPHeaders(telemetry bool, websocketHosts func() []string) func(next http.H
131136
})
132137
}
133138
}
139+
140+
var (
141+
meticulousConnectSrc = []string{"https://cognito-identity.us-west-2.amazonaws.com", "https://user-events-v3.s3-accelerate.amazonaws.com", "*.sentry.io"}
142+
meticulousScriptSrc = []string{"https://snippet.meticulous.ai", "https://browser.sentry-cdn.com"}
143+
)

site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"deadcode": "ts-prune | grep -v \".stories\\|.config\\|e2e\\|__mocks__\\|used in module\\|testHelpers\\|typesGenerated\" || echo \"No deadcode found.\""
3131
},
3232
"dependencies": {
33+
"@alwaysmeticulous/recorder-loader": "2.137.0",
3334
"@emoji-mart/data": "1.2.1",
3435
"@emoji-mart/react": "1.1.1",
3536
"@emotion/css": "11.11.2",

site/pnpm-lock.yaml

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/index.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { tryLoadAndStartRecorder } from "@alwaysmeticulous/recorder-loader";
12
import { createRoot } from "react-dom/client";
23
import { App } from "./App";
34

@@ -12,5 +13,30 @@ const element = document.getElementById("root");
1213
if (element === null) {
1314
throw new Error("root element is null");
1415
}
16+
1517
const root = createRoot(element);
16-
root.render(<App />);
18+
async function startApp() {
19+
// Record all sessions on localhost, staging stacks and preview URLs
20+
if (isInternal()) {
21+
// Start the Meticulous recorder before you initialise your app.
22+
// Note: all errors are caught and logged, so no need to surround with try/catch
23+
await tryLoadAndStartRecorder({
24+
projectId: "Y4uHy1qs0B660xxUdrkLPkazUMPr6OuTqYEnShaR",
25+
isProduction: false,
26+
});
27+
}
28+
29+
root.render(<App />);
30+
}
31+
32+
function isInternal() {
33+
return (
34+
window.location.hostname.indexOf("dev.coder.com") > -1 ||
35+
window.location.hostname.indexOf("localhost") > -1 ||
36+
window.location.hostname.indexOf("127.0.0.1") > -1
37+
);
38+
}
39+
40+
startApp().catch((error) => {
41+
console.error(error);
42+
});

0 commit comments

Comments
 (0)