Skip to content

Commit 72cc261

Browse files
authored
Enhance telemetry logging with environment info (#1201)
- ✨ Added environment parameter to OneDSLogger and oneDSLoggerWrapper constructors. - 🔧 Updated instantiation calls to include environment information in telemetry logs. - 📈 Improved logging context for better tracking of telemetry data. -Priyanshu
1 parent c590e67 commit 72cc261

5 files changed

Lines changed: 52 additions & 27 deletions

File tree

src/client/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export async function activate(
202202
if (artemisResponse !== null && artemisResponse.response !== null) {
203203
ArtemisContext.setContext(artemisResponse);
204204

205-
const { geoName, geoLongName, clusterName, clusterNumber } = artemisResponse.response;
205+
const { geoName, geoLongName, clusterName, clusterNumber, environment } = artemisResponse.response;
206206
let AadObjectId, EnvID, TenantID;
207207

208208
if ((pacActiveAuth && pacActiveAuth.Status === SUCCESS)) {
@@ -231,7 +231,7 @@ export async function activate(
231231
registerCopilotPanels(pacWrapper);
232232
}
233233

234-
oneDSLoggerWrapper.instantiate(geoName, geoLongName);
234+
oneDSLoggerWrapper.instantiate(geoName, geoLongName, environment);
235235
let initContext: object = { ...orgDetails, orgGeo: geoName };
236236
if (AadObjectId) {
237237
initContext = { ...initContext, AadId: AadObjectId }

src/common/OneDSLoggerTelemetry/oneDSLogger.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { AppInsightsCore, type IExtendedConfiguration } from "@microsoft/1ds-cor
99
import { PostChannel, type IChannelConfiguration, type IXHROverride } from "@microsoft/1ds-post-js";
1010
import { ITelemetryLogger } from "./ITelemetryLogger";
1111
import { IContextInfo, IUserInfo } from "./IEventTypes";
12-
import { EventType, Severity } from "./telemetryConstants";
12+
import { EndpointUrls, EventType, InstrumentationKeys, Severity } from "./telemetryConstants";
1313
import * as vscode from "vscode";
1414
import { getExtensionType, getExtensionVersion, getOperatingSystem, getOperatingSystemLabel, getOperatingSystemVersion } from "../utilities/Utils";
1515
import { EXTENSION_ID } from "../constants";
@@ -33,6 +33,7 @@ export class OneDSLogger implements ITelemetryLogger {
3333
private static contextInfo: IContextInfo;
3434
private static userRegion: string = "";
3535
private static orgGeo: string = "";
36+
private static testInstrumentationEnvironments = new Set(['preprod', 'test', 'tie']);
3637

3738
private readonly regexPatternsToRedact = [
3839
/key["\\ ']*[:=]+["\\ ']*([a-zA-Z0-9]*)/igm,
@@ -84,7 +85,7 @@ export class OneDSLogger implements ITelemetryLogger {
8485
},
8586
};
8687

87-
public constructor(geo?: string, geoLongName?: string) {
88+
public constructor(geo?: string, geoLongName?: string, environment?: string) {
8889

8990
this.appInsightsCore = new AppInsightsCore();
9091
this.postChannel = new PostChannel();
@@ -94,7 +95,7 @@ export class OneDSLogger implements ITelemetryLogger {
9495
httpXHROverride: this.fetchHttpXHROverride,
9596
};
9697

97-
const instrumentationSetting: IInstrumentationSettings = OneDSLogger.getInstrumentationSettings(geo, geoLongName); // Need to replace with actual data
98+
const instrumentationSetting: IInstrumentationSettings = OneDSLogger.getInstrumentationSettings(geo, geoLongName, environment); // Need to replace with actual data
9899

99100
// Configure App insights core to send to collector
100101
const coreConfig: IExtendedConfiguration = {
@@ -136,12 +137,17 @@ export class OneDSLogger implements ITelemetryLogger {
136137
}
137138
}
138139

139-
private static getInstrumentationSettings(geo?: string, geoLongName?: string): IInstrumentationSettings {
140+
private static getInstrumentationSettings(geo?: string, geoLongName?: string, environment?: string): IInstrumentationSettings {
140141
const buildRegion: string = region;
141142
const instrumentationSettings: IInstrumentationSettings = {
142-
endpointURL: 'https://self.pipe.aria.int.microsoft.com/OneCollector/1.0/',
143-
instrumentationKey: 'ffdb4c99ca3a4ad5b8e9ffb08bf7da0d-65357ff3-efcd-47fc-b2fd-ad95a52373f4-7402'
143+
endpointURL: EndpointUrls.INTERNAL,
144+
instrumentationKey: InstrumentationKeys.INTERNAL
144145
};
146+
147+
if (environment && OneDSLogger.testInstrumentationEnvironments.has(environment.toLowerCase())) {
148+
return instrumentationSettings;
149+
}
150+
145151
switch (geoLongName) {
146152
case 'usgov':
147153
geo = 'gov';
@@ -156,6 +162,7 @@ export class OneDSLogger implements ITelemetryLogger {
156162
geo = 'mooncake';
157163
break;
158164
}
165+
159166
switch (buildRegion) {
160167
case 'tie':
161168
case 'test':
@@ -174,37 +181,37 @@ export class OneDSLogger implements ITelemetryLogger {
174181
case 'za':
175182
case 'ae':
176183
case 'kr':
177-
instrumentationSettings.endpointURL = 'https://us-mobile.events.data.microsoft.com/OneCollector/1.0/',
178-
instrumentationSettings.instrumentationKey = '197418c5cb8c4426b201f9db2e87b914-87887378-2790-49b0-9295-51f43b6204b1-7172'
184+
instrumentationSettings.endpointURL = EndpointUrls.US;
185+
instrumentationSettings.instrumentationKey = InstrumentationKeys.US_AND_EU;
179186
break;
180187
case 'eu':
181188
case 'uk':
182189
case 'de':
183190
case 'fr':
184191
case 'no':
185192
case 'ch':
186-
instrumentationSettings.endpointURL = 'https://eu-mobile.events.data.microsoft.com/OneCollector/1.0/',
187-
instrumentationSettings.instrumentationKey = '197418c5cb8c4426b201f9db2e87b914-87887378-2790-49b0-9295-51f43b6204b1-7172'
193+
instrumentationSettings.endpointURL = EndpointUrls.EU;
194+
instrumentationSettings.instrumentationKey = InstrumentationKeys.US_AND_EU;
188195
break;
189196
case 'gov':
190-
instrumentationSettings.endpointURL = 'https://tb.events.data.microsoft.com/OneCollector/1.0/',
191-
instrumentationSettings.instrumentationKey = '2f217cb8f40440eeb8b0aa80a2be2f7e-e0ec7b51-d1bb-4d8c-83b1-cc77aaba9009-7472'
197+
instrumentationSettings.endpointURL = EndpointUrls.GOV_AND_HIGH;
198+
instrumentationSettings.instrumentationKey = InstrumentationKeys.GOV;
192199
break;
193200
case 'high':
194-
instrumentationSettings.endpointURL = 'https://tb.events.data.microsoft.com/OneCollector/1.0/',
195-
instrumentationSettings.instrumentationKey = '4a07e143372c46aabf3841dc4f0ef795-a753031e-2005-4282-9451-a086fea4234a-6942'
201+
instrumentationSettings.endpointURL = EndpointUrls.GOV_AND_HIGH;
202+
instrumentationSettings.instrumentationKey = InstrumentationKeys.HIGH;
196203
break;
197204
case 'dod':
198-
instrumentationSettings.endpointURL = 'https://pf.events.data.microsoft.com/OneCollector/1.0/',
199-
instrumentationSettings.instrumentationKey = 'af47f3d608774379a53fa07cf36362ea-69701588-1aad-43ee-8b52-f71125849774-6656'
205+
instrumentationSettings.endpointURL = EndpointUrls.DOD;
206+
instrumentationSettings.instrumentationKey = InstrumentationKeys.DOD;
200207
break;
201208
case 'mooncake':
202-
instrumentationSettings.endpointURL = 'https://collector.azure.cn/OneCollector/1.0/',
203-
instrumentationSettings.instrumentationKey = 'f9b6e63b5e394453ba8f58f7a7b9aea7-f38fcfa2-eb34-48bc-9ae2-61fba4abbd39-7390' //prod key;
209+
instrumentationSettings.endpointURL = EndpointUrls.MOONCAKE;
210+
instrumentationSettings.instrumentationKey = InstrumentationKeys.MOONCAKE;
204211
break;
205212
default:
206-
instrumentationSettings.endpointURL = 'https://us-mobile.events.data.microsoft.com/OneCollector/1.0/',
207-
instrumentationSettings.instrumentationKey = '197418c5cb8c4426b201f9db2e87b914-87887378-2790-49b0-9295-51f43b6204b1-7172'
213+
instrumentationSettings.endpointURL = EndpointUrls.US;
214+
instrumentationSettings.instrumentationKey = InstrumentationKeys.US_AND_EU;
208215
break;
209216
}
210217
break;

src/common/OneDSLoggerTelemetry/oneDSLoggerWrapper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ export class oneDSLoggerWrapper {
1414
private static instance: oneDSLoggerWrapper;
1515
private static oneDSLoggerInstance: OneDSLogger;
1616

17-
private constructor(geo?: string, geoLongName?: string) {
18-
oneDSLoggerWrapper.oneDSLoggerInstance = new OneDSLogger(geo, geoLongName);
17+
private constructor(geo?: string, geoLongName?: string, environment?: string) {
18+
oneDSLoggerWrapper.oneDSLoggerInstance = new OneDSLogger(geo, geoLongName, environment);
1919
}
2020

2121

2222
static getLogger() {
2323
return this.instance;
2424
}
2525

26-
static instantiate(geo?: string, geoLongName?: string) {
27-
oneDSLoggerWrapper.instance = new oneDSLoggerWrapper(geo, geoLongName);
26+
static instantiate(geo?: string, geoLongName?: string, environment?: string) {
27+
oneDSLoggerWrapper.instance = new oneDSLoggerWrapper(geo, geoLongName, environment);
2828
}
2929

3030
/// Trace info log

src/common/OneDSLoggerTelemetry/telemetryConstants.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,21 @@ export const AUTH_KEYS = {
5757
ORGANIZATION_UNIQUE_NAME: 'Organization Unique Name:',
5858
ORGANIZATION_FRIENDLY_NAME: 'Organization Friendly Name:'
5959
};
60+
61+
export const EndpointUrls = {
62+
INTERNAL: 'https://self.pipe.aria.int.microsoft.com/OneCollector/1.0/',
63+
US: 'https://us-mobile.events.data.microsoft.com/OneCollector/1.0/',
64+
EU: 'https://eu-mobile.events.data.microsoft.com/OneCollector/1.0/',
65+
GOV_AND_HIGH: 'https://tb.events.data.microsoft.com/OneCollector/1.0/',
66+
DOD: 'https://pf.events.data.microsoft.com/OneCollector/1.0/',
67+
MOONCAKE: 'https://collector.azure.cn/OneCollector/1.0/'
68+
} as const;
69+
70+
export const InstrumentationKeys = {
71+
INTERNAL: 'ffdb4c99ca3a4ad5b8e9ffb08bf7da0d-65357ff3-efcd-47fc-b2fd-ad95a52373f4-7402',
72+
US_AND_EU: '197418c5cb8c4426b201f9db2e87b914-87887378-2790-49b0-9295-51f43b6204b1-7172',
73+
GOV: '2f217cb8f40440eeb8b0aa80a2be2f7e-e0ec7b51-d1bb-4d8c-83b1-cc77aaba9009-7472',
74+
HIGH: '4a07e143372c46aabf3841dc4f0ef795-a753031e-2005-4282-9451-a086fea4234a-6942',
75+
DOD: 'af47f3d608774379a53fa07cf36362ea-69701588-1aad-43ee-8b52-f71125849774-6656',
76+
MOONCAKE: 'f9b6e63b5e394453ba8f58f7a7b9aea7-f38fcfa2-eb34-48bc-9ae2-61fba4abbd39-7390'
77+
} as const;

src/web/client/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
106106
const orgId = queryParamsMap.get(queryParameters.ORG_ID) as string;
107107
await fetchArtemisData(orgId);
108108
WebExtensionContext.telemetry.sendInfoTelemetry(webExtensionTelemetryEventNames.WEB_EXTENSION_ORG_GEO, { orgId: orgId, orgGeo: WebExtensionContext.geoName });
109-
oneDSLoggerWrapper.instantiate(WebExtensionContext.geoName, WebExtensionContext.geoLongName);
109+
oneDSLoggerWrapper.instantiate(WebExtensionContext.geoName, WebExtensionContext.geoLongName, WebExtensionContext.serviceEndpointCategory);
110110

111111
WebExtensionContext.telemetry.sendExtensionInitPathParametersTelemetry(
112112
appName,

0 commit comments

Comments
 (0)