Skip to content

Commit 95b0b06

Browse files
committed
fix: merge getCommonProperties and getAsyncCommonProperties
1 parent 8d53eea commit 95b0b06

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

src/telemetry/telemetry.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ async function isContainerized(): Promise<boolean> {
5050
export class Telemetry {
5151
/** Resolves when the device ID is retrieved or timeout occurs */
5252
private pendingPromises: number = 2;
53-
public deviceIdPromise: Promise<string> | undefined;
54-
public containerEnvPromise: Promise<boolean> | undefined;
53+
private deviceIdPromise: Promise<string> | undefined;
54+
private containerEnvPromise: Promise<boolean> | undefined;
5555
private deviceIdAbortController = new AbortController();
5656
private eventCache: EventCache;
5757
private getRawMachineId: () => Promise<string>;
@@ -156,20 +156,14 @@ export class Telemetry {
156156
* Gets the common properties for events
157157
* @returns Object containing common properties for all events
158158
*/
159-
public getCommonProperties(): CommonProperties {
159+
public async getCommonProperties(): Promise<CommonProperties> {
160160
return {
161161
...this.commonProperties,
162162
mcp_client_version: this.session.agentRunner?.version,
163163
mcp_client_name: this.session.agentRunner?.name,
164164
session_id: this.session.sessionId,
165165
config_atlas_auth: this.session.apiClient.hasCredentials() ? "true" : "false",
166166
config_connection_string: this.userConfig.connectionString ? "true" : "false",
167-
};
168-
}
169-
170-
public async getAsyncCommonProperties(): Promise<CommonProperties> {
171-
return {
172-
...this.getCommonProperties(),
173167
is_container_env: (await this.containerEnvPromise) ? "true" : "false",
174168
device_id: await this.deviceIdPromise,
175169
};
@@ -239,7 +233,7 @@ export class Telemetry {
239233
*/
240234
private async sendEvents(client: ApiClient, events: BaseEvent[]): Promise<EventResult> {
241235
try {
242-
const commonProperties = await this.getAsyncCommonProperties();
236+
const commonProperties = await this.getCommonProperties();
243237
await client.sendEvents(
244238
events.map((event) => ({
245239
...event,

tests/integration/telemetry.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe("Telemetry", () => {
1414
});
1515

1616
expect(telemetry.hasPendingPromises()).toBe(true);
17-
const commonProps = await telemetry.getAsyncCommonProperties();
17+
const commonProps = await telemetry.getCommonProperties();
1818

1919
expect(commonProps.device_id).toBe(actualHashedId);
2020
expect(telemetry.hasPendingPromises()).toBe(false);

tests/unit/telemetry.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe("Telemetry", () => {
7777
expect(appendEvents.length).toBe(appendEventsCalls);
7878

7979
if (sendEventsCalledWith) {
80-
const commonProps = await telemetry.getAsyncCommonProperties();
80+
const commonProps = await telemetry.getCommonProperties();
8181

8282
expect(sendEvents[0]?.[0]).toEqual(
8383
sendEventsCalledWith.map((event) => ({
@@ -198,7 +198,7 @@ describe("Telemetry", () => {
198198
device_id: hashedMachineId,
199199
};
200200

201-
const commonProps = await telemetry.getAsyncCommonProperties();
201+
const commonProps = await telemetry.getCommonProperties();
202202

203203
expect(commonProps).toMatchObject(expectedProps);
204204
});
@@ -221,7 +221,7 @@ describe("Telemetry", () => {
221221
});
222222

223223
expect(telemetry.hasPendingPromises()).toBe(true);
224-
const commonProps = await telemetry.getAsyncCommonProperties();
224+
const commonProps = await telemetry.getCommonProperties();
225225
expect(telemetry.hasPendingPromises()).toBe(false);
226226
expect(commonProps.device_id).toBe(hashedMachineId);
227227
});
@@ -235,7 +235,7 @@ describe("Telemetry", () => {
235235
});
236236

237237
expect(telemetry.hasPendingPromises()).toBe(true);
238-
const commonProps = await telemetry.getAsyncCommonProperties();
238+
const commonProps = await telemetry.getCommonProperties();
239239
expect(telemetry.hasPendingPromises()).toBe(false);
240240
expect(commonProps.device_id).toBe("unknown");
241241

@@ -256,7 +256,7 @@ describe("Telemetry", () => {
256256
});
257257
expect(telemetry.hasPendingPromises()).toBe(true);
258258
jest.advanceTimersByTime(DEVICE_ID_TIMEOUT);
259-
const commonProps = await telemetry.getAsyncCommonProperties();
259+
const commonProps = await telemetry.getCommonProperties();
260260
expect(commonProps.device_id).toBe("unknown");
261261
expect(loggerSpy).toHaveBeenCalledWith(
262262
LogId.telemetryDeviceIdTimeout,

0 commit comments

Comments
 (0)