Skip to content

Commit c5da0d4

Browse files
committed
fix(telemetry): log (well known) workspace and dataset names
1 parent 5a26381 commit c5da0d4

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

packages/sanity/src/core/studio/StudioTelemetryProvider.tsx

+28-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ import {SANITY_VERSION} from '../version'
99

1010
const sessionId = createSessionId()
1111

12+
// A list of common dataset / workspace names we can safely log without collecting private data
13+
const WELL_KNOWN_NAMES = [
14+
'staging',
15+
'stage',
16+
'stg',
17+
'production',
18+
'prod',
19+
'preprod',
20+
'development',
21+
'dev',
22+
'qa',
23+
'test',
24+
]
25+
1226
// Wrap the app in a TelemetryProvider
1327
// This will enable usage of the `useTelemetry()` hook
1428
export function StudioTelemetryProvider(props: {children: ReactNode; config: Config}) {
@@ -39,6 +53,7 @@ export function StudioTelemetryProvider(props: {children: ReactNode; config: Con
3953
}, [client, projectId])
4054

4155
useEffect(() => {
56+
const workspaces = arrify(props.config)
4257
store.logger.updateUserProperties({
4358
userAgent: navigator.userAgent,
4459
screen: {
@@ -49,14 +64,24 @@ export function StudioTelemetryProvider(props: {children: ReactNode; config: Con
4964
innerWidth: window.innerWidth,
5065
},
5166
studioVersion: SANITY_VERSION,
52-
plugins: arrify(props.config).flatMap(
53-
(config) =>
54-
config.plugins?.flatMap((plugin) => ({
67+
plugins: workspaces.flatMap(
68+
(workspace) =>
69+
workspace.plugins?.flatMap((plugin) => ({
5570
name: plugin.name || '<unnamed>',
5671
})) || [],
5772
),
73+
workspaceNames: workspaces.map((workspace) =>
74+
workspace.name ? getWellKnownName(workspace.name) || '<custom>' : '<missing>',
75+
),
76+
datasetNames: workspaces.flatMap((workspace) =>
77+
workspace.dataset ? getWellKnownName(workspace.dataset) || '<custom>' : '<missing>',
78+
),
5879
})
5980
}, [props.config, store.logger])
6081

6182
return <TelemetryProvider store={store}>{props.children}</TelemetryProvider>
6283
}
84+
85+
function getWellKnownName(name: string) {
86+
return WELL_KNOWN_NAMES.includes(name.toLowerCase()) ? name : undefined
87+
}

0 commit comments

Comments
 (0)