Skip to content

Commit d82e187

Browse files
Merge pull request #6509 from Shopify/sd.wasm_helpers_telemetry
Telemetry for function-testing-helpers usage tracking
2 parents 39f4105 + 8f7a779 commit d82e187

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

packages/cli-kit/src/private/node/analytics.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,14 @@ export async function getEnvironmentData(config: Interfaces.Config): Promise<Env
9797
export async function getSensitiveEnvironmentData(config: Interfaces.Config) {
9898
return {
9999
env_plugin_installed_all: JSON.stringify(getPluginNames(config)),
100+
env_shopify_variables: JSON.stringify(getShopifyEnvironmentVariables()),
100101
}
101102
}
102103

104+
function getShopifyEnvironmentVariables() {
105+
return Object.fromEntries(Object.entries(process.env).filter(([key]) => key.startsWith('SHOPIFY_')))
106+
}
107+
103108
function getPluginNames(config: Interfaces.Config) {
104109
const pluginNames = [...config.plugins.keys()]
105110
return pluginNames.sort().filter((plugin) => !plugin.startsWith('@oclif/'))

packages/cli-kit/src/public/node/analytics.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,36 @@ describe('event tracking', () => {
185185
})
186186
})
187187

188+
test('sends SHOPIFY_ environment variables in sensitive payload', async () => {
189+
const originalEnv = {...process.env}
190+
process.env.SHOPIFY_TEST_VAR = 'test_value'
191+
process.env.SHOPIFY_ANOTHER_VAR = 'another_value'
192+
process.env.NOT_SHOPIFY_VAR = 'should_not_appear'
193+
194+
await inProjectWithFile('package.json', async (args) => {
195+
const commandContent = {command: 'dev', topic: 'app'}
196+
await startAnalytics({commandContent, args, currentTime: currentDate.getTime() - 100})
197+
198+
// When
199+
const config = {
200+
runHook: vi.fn().mockResolvedValue({successes: [], failures: []}),
201+
plugins: [],
202+
} as any
203+
await reportAnalyticsEvent({config, exitMode: 'ok'})
204+
205+
// Then
206+
const sensitivePayload = publishEventMock.mock.calls[0]![2]
207+
expect(publishEventMock).toHaveBeenCalledOnce()
208+
expect(sensitivePayload).toHaveProperty('env_shopify_variables')
209+
expect(sensitivePayload.env_shopify_variables).toBeDefined()
210+
211+
const shopifyVars = JSON.parse(sensitivePayload.env_shopify_variables as string)
212+
expect(shopifyVars).toHaveProperty('SHOPIFY_TEST_VAR', 'test_value')
213+
expect(shopifyVars).toHaveProperty('SHOPIFY_ANOTHER_VAR', 'another_value')
214+
expect(shopifyVars).not.toHaveProperty('NOT_SHOPIFY_VAR')
215+
})
216+
})
217+
188218
test('does nothing when analytics are disabled', async () => {
189219
await inProjectWithFile('package.json', async (args) => {
190220
// Given

packages/cli-kit/src/public/node/monorail.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const url = 'https://monorail-edge.shopifysvc.com/v1/produce'
1010
type Optional<T> = T | null
1111

1212
// This is the topic name of the main event we log to Monorail, the command tracker
13-
export const MONORAIL_COMMAND_TOPIC = 'app_cli3_command/1.19'
13+
export const MONORAIL_COMMAND_TOPIC = 'app_cli3_command/1.20'
1414

1515
export interface Schemas {
1616
[MONORAIL_COMMAND_TOPIC]: {
@@ -27,6 +27,7 @@ export interface Schemas {
2727

2828
// Environment
2929
env_plugin_installed_all?: Optional<string>
30+
env_shopify_variables?: Optional<string>
3031
}
3132
public: {
3233
business_platform_id?: Optional<number>

0 commit comments

Comments
 (0)