Skip to content

Commit

Permalink
Send user id in extension paylod (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
lramos15 authored Jul 30, 2024
1 parent 8123b24 commit 6019c88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/browser/telemetryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import * as vscode from "vscode";
import { oneDataSystemClientFactory } from "../common/1dsClientFactory";
import { BaseTelemetrySender } from "../common/baseTelemetrySender";
import { appInsightsClientFactory } from "../common/appInsightsClientFactory";
import { BaseTelemetryReporter, ReplacementOption } from "../common/baseTelemetryReporter";
import { BaseTelemetrySender } from "../common/baseTelemetrySender";
import { TelemetryUtil } from "../common/util";
import { appInsightsClientFactory } from "../common/appInsightsClientFactory";

function getBrowserRelease(navigator: Navigator): string {
if (navigator.userAgentData) {
Expand All @@ -22,7 +22,7 @@ function getBrowserRelease(navigator: Navigator): string {

export default class TelemetryReporter extends BaseTelemetryReporter {
constructor(key: string, replacementOptions?: ReplacementOption[]) {
let clientFactory = (key: string) => appInsightsClientFactory(key, undefined, replacementOptions);
let clientFactory = (key: string) => appInsightsClientFactory(key, vscode.env.machineId, undefined, replacementOptions);
// If key is usable by 1DS use the 1DS SDk
if (TelemetryUtil.shouldUseOneDataSystemSDK(key)) {
clientFactory = (key: string) => oneDataSystemClientFactory(key, vscode);
Expand Down
10 changes: 6 additions & 4 deletions src/common/appInsightsClientFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { ApplicationInsights } from "@microsoft/applicationinsights-web-basic";
import type { IXHROverride, IConfiguration } from "@microsoft/applicationinsights-core-js";
import type { IChannelConfiguration } from "@microsoft/1ds-post-js";
import { BreezeChannelIdentifier } from "@microsoft/applicationinsights-common";
import type { IConfiguration, IXHROverride } from "@microsoft/applicationinsights-core-js";
import type { ApplicationInsights } from "@microsoft/applicationinsights-web-basic";
import { ReplacementOption, SenderData } from "./baseTelemetryReporter";
import { BaseTelemetryClient } from "./baseTelemetrySender";
import { TelemetryUtil } from "./util";
import type { IChannelConfiguration } from "@microsoft/1ds-post-js";

export const appInsightsClientFactory = async (key: string, xhrOverride?: IXHROverride, replacementOptions?: ReplacementOption[]): Promise<BaseTelemetryClient> => {
export const appInsightsClientFactory = async (key: string, machineId: string, xhrOverride?: IXHROverride, replacementOptions?: ReplacementOption[]): Promise<BaseTelemetryClient> => {
let appInsightsClient: ApplicationInsights | undefined;
try {
const basicAISDK = await import/* webpackMode: "eager" */("@microsoft/applicationinsights-web-basic");
Expand All @@ -37,6 +37,7 @@ export const appInsightsClientFactory = async (key: string, xhrOverride?: IXHROv
disableInstrumentationKeyValidation: true,
extensionConfig,
});

} catch (e) {
return Promise.reject(e);
}
Expand All @@ -51,6 +52,7 @@ export const appInsightsClientFactory = async (key: string, xhrOverride?: IXHROv
name: eventName,
data: properties,
baseType: "EventData",
ext: { user: { id: machineId, authenticatedId: machineId } },
baseData: { name: eventName, properties: data?.properties, measurements: data?.measurements }
});
},
Expand Down
10 changes: 5 additions & 5 deletions src/node/telemetryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import type { IPayloadData, IXHROverride } from "@microsoft/1ds-post-js";
import * as https from "https";
import * as os from "os";
import * as vscode from "vscode";
import * as https from "https";
import { oneDataSystemClientFactory } from "../common/1dsClientFactory";
import { appInsightsClientFactory } from "../common/appInsightsClientFactory";
import { BaseTelemetryReporter, ReplacementOption } from "../common/baseTelemetryReporter";
import { BaseTelemetrySender } from "../common/baseTelemetrySender";
import { TelemetryUtil } from "../common/util";
import type { IXHROverride, IPayloadData } from "@microsoft/1ds-post-js";
import { oneDataSystemClientFactory } from "../common/1dsClientFactory";
import { appInsightsClientFactory } from "../common/appInsightsClientFactory";

/**
* Create a replacement for the XHTMLRequest object utilizing nodes HTTP module.
Expand Down Expand Up @@ -55,7 +55,7 @@ function getXHROverride() {

export default class TelemetryReporter extends BaseTelemetryReporter {
constructor(key: string, replacementOptions?: ReplacementOption[]) {
let clientFactory = (key: string) => appInsightsClientFactory(key, getXHROverride(), replacementOptions);
let clientFactory = (key: string) => appInsightsClientFactory(key, vscode.env.machineId, getXHROverride(), replacementOptions);
// If key is usable by 1DS use the 1DS SDk
if (TelemetryUtil.shouldUseOneDataSystemSDK(key)) {
clientFactory = (key: string) => oneDataSystemClientFactory(key, vscode, getXHROverride());
Expand Down

0 comments on commit 6019c88

Please sign in to comment.