From c347ae5dafd05db97f72aee6caaa7678b9683082 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 22 Jan 2020 08:42:40 -0600 Subject: [PATCH 1/5] Expose telemetry log to extension API. --- .../sourcegraph-extension-api/src/sourcegraph.d.ts | 10 ++++++++++ shared/src/api/extension/extensionHost.ts | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/packages/sourcegraph-extension-api/src/sourcegraph.d.ts b/packages/sourcegraph-extension-api/src/sourcegraph.d.ts index 3a8da113f818..21806b22e51d 100644 --- a/packages/sourcegraph-extension-api/src/sourcegraph.d.ts +++ b/packages/sourcegraph-extension-api/src/sourcegraph.d.ts @@ -1433,4 +1433,14 @@ declare module 'sourcegraph' { add: (unsubscribable: Unsubscribable | (() => void)) => void } } + + /** + * Sending counts and latencies of extension operations back to Sourcegraph. + */ + export namespace telemetry { + /** + * Log an event (by sending it to the server). + */ + export const log: (eventName: string, eventProperties?: any) => void + } } diff --git a/shared/src/api/extension/extensionHost.ts b/shared/src/api/extension/extensionHost.ts index fd701b8dc9dc..ac83423156f3 100644 --- a/shared/src/api/extension/extensionHost.ts +++ b/shared/src/api/extension/extensionHost.ts @@ -18,6 +18,7 @@ import { ExtRoots } from './api/roots' import { ExtSearch } from './api/search' import { ExtViews } from './api/views' import { ExtWindows } from './api/windows' +import { NOOP_TELEMETRY_SERVICE } from '../../telemetry/telemetryService' /** * Required information when initializing an extension host. @@ -261,6 +262,10 @@ function createExtensionAPI( sourcegraphURL: new URL(initData.sourcegraphURL), clientApplication: initData.clientApplication, }, + + telemetry: { + log: NOOP_TELEMETRY_SERVICE.log.bind(NOOP_TELEMETRY_SERVICE), + }, } return { extensionHostAPI, extensionAPI, subscription } } From 70fcdfd12ea732177a28e9d660b6c7eb458d38ba Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 22 Jan 2020 09:37:47 -0600 Subject: [PATCH 2/5] Undo that old stuff. --- .../src/sourcegraph.d.ts | 10 ---------- shared/src/api/extension/extensionHost.ts | 4 ---- shared/src/commands/commands.ts | 15 ++++++++++++++- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/sourcegraph-extension-api/src/sourcegraph.d.ts b/packages/sourcegraph-extension-api/src/sourcegraph.d.ts index 21806b22e51d..3a8da113f818 100644 --- a/packages/sourcegraph-extension-api/src/sourcegraph.d.ts +++ b/packages/sourcegraph-extension-api/src/sourcegraph.d.ts @@ -1433,14 +1433,4 @@ declare module 'sourcegraph' { add: (unsubscribable: Unsubscribable | (() => void)) => void } } - - /** - * Sending counts and latencies of extension operations back to Sourcegraph. - */ - export namespace telemetry { - /** - * Log an event (by sending it to the server). - */ - export const log: (eventName: string, eventProperties?: any) => void - } } diff --git a/shared/src/api/extension/extensionHost.ts b/shared/src/api/extension/extensionHost.ts index ac83423156f3..5caee304f154 100644 --- a/shared/src/api/extension/extensionHost.ts +++ b/shared/src/api/extension/extensionHost.ts @@ -262,10 +262,6 @@ function createExtensionAPI( sourcegraphURL: new URL(initData.sourcegraphURL), clientApplication: initData.clientApplication, }, - - telemetry: { - log: NOOP_TELEMETRY_SERVICE.log.bind(NOOP_TELEMETRY_SERVICE), - }, } return { extensionHostAPI, extensionAPI, subscription } } diff --git a/shared/src/commands/commands.ts b/shared/src/commands/commands.ts index 021bde9221b8..4463b2e9e6aa 100644 --- a/shared/src/commands/commands.ts +++ b/shared/src/commands/commands.ts @@ -15,7 +15,7 @@ import { PlatformContext } from '../platform/context' */ export function registerBuiltinClientCommands( { settings: settingsService, commands: commandRegistry, textDocumentLocations }: Services, - context: Pick + context: Pick ): Unsubscribable { const subscription = new Subscription() @@ -102,6 +102,19 @@ export function registerBuiltinClientCommands( }) ) + /** + * TODO + */ + subscription.add( + commandRegistry.registerCommand({ + command: 'logTelemetryEvent', + run: (eventName: string, eventProperties?: any): Promise => { + context.telemetryService?.log(eventName, eventProperties) + return Promise.resolve() + }, + }) + ) + return subscription } From 919f9ed4c913b9014fcf444b554be5e8bce0af1d Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 22 Jan 2020 09:38:19 -0600 Subject: [PATCH 3/5] Remove unused import. --- shared/src/api/extension/extensionHost.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/shared/src/api/extension/extensionHost.ts b/shared/src/api/extension/extensionHost.ts index 5caee304f154..fd701b8dc9dc 100644 --- a/shared/src/api/extension/extensionHost.ts +++ b/shared/src/api/extension/extensionHost.ts @@ -18,7 +18,6 @@ import { ExtRoots } from './api/roots' import { ExtSearch } from './api/search' import { ExtViews } from './api/views' import { ExtWindows } from './api/windows' -import { NOOP_TELEMETRY_SERVICE } from '../../telemetry/telemetryService' /** * Required information when initializing an extension host. From 9fac27fa8ba98708e0050fa6a3bab6cf42837b53 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 22 Jan 2020 09:40:19 -0600 Subject: [PATCH 4/5] Add docstring. --- shared/src/commands/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/src/commands/commands.ts b/shared/src/commands/commands.ts index 4463b2e9e6aa..51852e4b04e1 100644 --- a/shared/src/commands/commands.ts +++ b/shared/src/commands/commands.ts @@ -103,7 +103,7 @@ export function registerBuiltinClientCommands( ) /** - * TODO + * Sends a telemetry event to the Sourcegraph instance with the correct anonymous user id. */ subscription.add( commandRegistry.registerCommand({ From 53b79589e50d585cf006d1134da340cce76084c8 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Wed, 22 Jan 2020 09:43:42 -0600 Subject: [PATCH 5/5] Fix lint. --- shared/src/commands/commands.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shared/src/commands/commands.ts b/shared/src/commands/commands.ts index 51852e4b04e1..6ec89356b16b 100644 --- a/shared/src/commands/commands.ts +++ b/shared/src/commands/commands.ts @@ -109,7 +109,9 @@ export function registerBuiltinClientCommands( commandRegistry.registerCommand({ command: 'logTelemetryEvent', run: (eventName: string, eventProperties?: any): Promise => { - context.telemetryService?.log(eventName, eventProperties) + if (context.telemetryService) { + context.telemetryService.log(eventName, eventProperties) + } return Promise.resolve() }, })