Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/common/atlas/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { AccessToken, ClientCredentials } from "simple-oauth2";
import { ApiClientError } from "./apiClientError.js";
import { paths, operations } from "./openapi.js";
import { BaseEvent } from "../../telemetry/types.js";
import { mongoLogId } from "mongodb-log-writer";
import logger from "../../logger.js";
import { packageInfo } from "../../packageInfo.js";

const ATLAS_API_VERSION = "2025-03-12";
Expand Down Expand Up @@ -98,11 +96,6 @@ export class ApiClient {
}

public hasCredentials(): boolean {
logger.info(
mongoLogId(1_000_000),
"api-client",
`Checking if API client has credentials: ${!!(this.oauth2Client && this.accessToken)}`
);
return !!(this.oauth2Client && this.accessToken);
}

Expand Down
4 changes: 2 additions & 2 deletions src/telemetry/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getMachineIdSync } from "native-machine-id";
import { packageInfo } from "../packageInfo.js";

import { type CommonStaticProperties } from "./types.js";
/**
* Machine-specific metadata formatted for telemetry
*/
export const MACHINE_METADATA = {
export const MACHINE_METADATA: CommonStaticProperties = {
device_id: getMachineIdSync(),
mcp_server_version: packageInfo.version,
mcp_server_name: packageInfo.mcpServerName,
Expand Down
17 changes: 3 additions & 14 deletions src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Session } from "../session.js";
import { BaseEvent } from "./types.js";
import { BaseEvent, CommonProperties } from "./types.js";
import { config } from "../config.js";
import logger from "../logger.js";
import { mongoLogId } from "mongodb-log-writer";
Expand All @@ -12,19 +12,6 @@ type EventResult = {
error?: Error;
};

type CommonProperties = {
device_id?: string;
mcp_server_version: string;
mcp_server_name: string;
mcp_client_version?: string;
mcp_client_name?: string;
platform: string;
arch: string;
os_type: string;
os_version?: string;
session_id?: string;
};

export class Telemetry {
private readonly commonProperties: CommonProperties;

Expand Down Expand Up @@ -88,6 +75,8 @@ export class Telemetry {
mcp_client_version: this.session.agentRunner?.version,
mcp_client_name: this.session.agentRunner?.name,
session_id: this.session.sessionId,
config_atlas_auth: this.session.apiClient.hasCredentials() ? "true" : "false",
config_connection_string: config.connectionString ? "true" : "false",
};
}

Expand Down
37 changes: 26 additions & 11 deletions src/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
export type TelemetryResult = "success" | "failure";
export type ServerCommand = "start" | "stop";
export type TelemetryConfigSet = "true" | "false";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's call this a boolean

Suggested change
export type TelemetryConfigSet = "true" | "false";
export type TelemetryBoolSet = "true" | "false";

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!


/**
* Base interface for all events
Expand All @@ -14,21 +15,11 @@ export interface Event {
}

export interface BaseEvent extends Event {
properties: {
device_id?: string;
mcp_server_version: string;
mcp_server_name: string;
mcp_client_version?: string;
mcp_client_name?: string;
platform: string;
arch: string;
os_type: string;
properties: CommonProperties & {
component: string;
duration_ms: number;
result: TelemetryResult;
category: string;
os_version?: string;
session_id?: string;
} & Event["properties"];
}

Expand Down Expand Up @@ -58,3 +49,27 @@ export interface ServerEvent extends BaseEvent {
runtime_duration_ms?: number;
} & BaseEvent["properties"];
}

/**
* Interface for static properties, they can be fetched once and reused.
*/
export type CommonStaticProperties = {
device_id?: string;
mcp_server_version: string;
mcp_server_name: string;
platform: string;
arch: string;
os_type: string;
os_version?: string;
};

/**
* Common properties for all events that might change.
*/
export type CommonProperties = {
mcp_client_version?: string;
mcp_client_name?: string;
config_atlas_auth?: TelemetryConfigSet;
config_connection_string?: TelemetryConfigSet;
session_id?: string;
} & CommonStaticProperties;
Loading