From 4563517d90d1e049eb0665814f5bc9e5b8b8ccea Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 6 May 2024 15:53:53 -0800 Subject: [PATCH] Add isContainer property to telemetry --- patches/display-language.diff | 2 +- patches/telemetry.diff | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/patches/display-language.diff b/patches/display-language.diff index df2b04008..2a9a6f2b7 100644 --- a/patches/display-language.diff +++ b/patches/display-language.diff @@ -30,7 +30,7 @@ Index: code-server/lib/vscode/src/vs/server/node/serverServices.ts import { ProtocolConstants } from 'vs/base/parts/ipc/common/ipc.net'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { ConfigurationService } from 'vs/platform/configuration/common/configurationService'; -@@ -228,6 +228,9 @@ export async function setupServerService +@@ -239,6 +239,9 @@ export async function setupServerService const channel = new ExtensionManagementChannel(extensionManagementService, (ctx: RemoteAgentConnectionContext) => getUriTransformer(ctx.remoteAuthority)); socketServer.registerChannel('extensions', channel); diff --git a/patches/telemetry.diff b/patches/telemetry.diff index eaa284bc9..15234f6d4 100644 --- a/patches/telemetry.diff +++ b/patches/telemetry.diff @@ -20,14 +20,29 @@ Index: code-server/lib/vscode/src/vs/server/node/serverServices.ts import { NullPolicyService } from 'vs/platform/policy/common/policy'; import { OneDataSystemAppender } from 'vs/platform/telemetry/node/1dsAppender'; import { LoggerService } from 'vs/platform/log/node/loggerService'; -@@ -149,7 +150,10 @@ export async function setupServerService +@@ -146,10 +147,25 @@ export async function setupServerService + const requestService = new RequestService(configurationService, environmentService, logService, loggerService); + services.set(IRequestService, requestService); + ++ let isContainer = undefined; ++ try { ++ await Promises.stat('/run/.containerenv'); ++ isContainer = true; ++ } catch (error) { /* Does not exist, probably. */ } ++ if (!isContainer) { ++ try { ++ const content = await Promises.readFile('/proc/self/cgroup', 'utf8') ++ isContainer = content.includes('docker'); ++ } catch (error) { /* Permission denied, probably. */ } ++ } ++ let oneDsAppender: ITelemetryAppender = NullAppender; const isInternal = isInternalTelemetry(productService, configurationService); if (supportsTelemetry(productService, environmentService)) { - if (!isLoggingOnly(productService, environmentService) && productService.aiConfig?.ariaKey) { + const telemetryEndpoint = process.env.CS_TELEMETRY_URL || "https://v1.telemetry.coder.com/track"; + if (telemetryEndpoint) { -+ oneDsAppender = new OneDataSystemAppender(requestService, false, eventPrefix, null, () => new TelemetryClient(telemetryEndpoint)); ++ oneDsAppender = new OneDataSystemAppender(requestService, false, eventPrefix, null, () => new TelemetryClient(telemetryEndpoint, isContainer)); + } else if (!isLoggingOnly(productService, environmentService) && productService.aiConfig?.ariaKey) { oneDsAppender = new OneDataSystemAppender(requestService, isInternal, eventPrefix, null, productService.aiConfig.ariaKey); disposables.add(toDisposable(() => oneDsAppender?.flush())); // Ensure the AI appender is disposed so that it flushes remaining data @@ -36,14 +51,16 @@ Index: code-server/lib/vscode/src/vs/server/node/telemetryClient.ts =================================================================== --- /dev/null +++ code-server/lib/vscode/src/vs/server/node/telemetryClient.ts -@@ -0,0 +1,49 @@ +@@ -0,0 +1,53 @@ +import { AppInsightsCore, IExtendedTelemetryItem, ITelemetryItem } from '@microsoft/1ds-core-js'; +import * as https from 'https'; +import * as http from 'http'; +import * as os from 'os'; + +export class TelemetryClient extends AppInsightsCore { -+ public constructor(private readonly endpoint: string) { ++ public constructor( ++ private readonly endpoint: string, ++ private readonly isContainer: Boolean | undefined) { + super(); + } + @@ -73,6 +90,8 @@ Index: code-server/lib/vscode/src/vs/server/node/telemetryClient.ts + options.properties['common.arch'] = os.arch(); + } catch (error) {} + ++ options.properties['common.isContainer'] = this.isContainer; ++ + try { + const request = (/^http:/.test(this.endpoint) ? http : https).request(this.endpoint, { + method: 'POST',