Skip to content

Commit 2271809

Browse files
committed
chore: include tool args for perf advisor telemetry
1 parent 38353c7 commit 2271809

File tree

8 files changed

+255
-117
lines changed

8 files changed

+255
-117
lines changed

src/telemetry/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type TelemetryEvent<T> = {
1616
duration_ms: number;
1717
result: TelemetryResult;
1818
category: string;
19-
};
19+
} & Record<string, string | number | string[]>;
2020
};
2121

2222
export type BaseEvent = TelemetryEvent<unknown>;

src/tools/atlas/atlasTool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ For more information on Atlas API access roles, visit: https://www.mongodb.com/d
107107

108108
// Extract projectId using type guard
109109
if ("projectId" in data && typeof data.projectId === "string" && data.projectId.trim() !== "") {
110-
toolMetadata.projectId = data.projectId;
110+
toolMetadata.project_id = data.projectId;
111111
}
112112

113113
// Extract orgId using type guard
114114
if ("orgId" in data && typeof data.orgId === "string" && data.orgId.trim() !== "") {
115-
toolMetadata.orgId = data.orgId;
115+
toolMetadata.org_id = data.orgId;
116116
}
117117
return toolMetadata;
118118
}

src/tools/atlas/read/getPerformanceAdvisor.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from "zod";
22
import { AtlasToolBase } from "../atlasTool.js";
3-
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
4-
import type { OperationType, ToolArgs } from "../../tool.js";
3+
import type { CallToolResult, ServerNotification, ServerRequest } from "@modelcontextprotocol/sdk/types.js";
4+
import type { OperationType, TelemetryToolMetadata, ToolArgs } from "../../tool.js";
55
import { formatUntrustedData } from "../../tool.js";
66
import {
77
getSuggestedIndexes,
@@ -13,6 +13,7 @@ import {
1313
SLOW_QUERY_LOGS_COPY,
1414
} from "../../../common/atlas/performanceAdvisorUtils.js";
1515
import { AtlasArgs } from "../../args.js";
16+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
1617

1718
const PerformanceAdvisorOperationType = z.enum([
1819
"suggestedIndexes",
@@ -130,4 +131,14 @@ export class GetPerformanceAdvisorTool extends AtlasToolBase {
130131
};
131132
}
132133
}
134+
135+
protected override resolveTelemetryMetadata(
136+
result: CallToolResult,
137+
args: ToolArgs<typeof this.argsShape>,
138+
extra: RequestHandlerExtra<ServerRequest, ServerNotification>
139+
): TelemetryToolMetadata {
140+
const baseMetadata = super.resolveTelemetryMetadata(result, args, extra);
141+
baseMetadata.operations = args.operations;
142+
return baseMetadata;
143+
}
133144
}

src/tools/atlasLocal/atlasLocalTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
125125
// If the deployment ID is set, we use it for telemetry
126126
const resultDeploymentId = result._meta?.[AtlasLocalToolMetadataDeploymentIdKey];
127127
if (resultDeploymentId !== undefined && typeof resultDeploymentId === "string") {
128-
toolMetadata.atlasLocaldeploymentId = resultDeploymentId;
128+
toolMetadata.atlas_local_deployment_id = resultDeploymentId;
129129
}
130130

131131
return toolMetadata;

src/tools/mongodb/mongodbTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export abstract class MongoDBToolBase extends ToolBase {
120120

121121
// Add projectId to the metadata if running a MongoDB operation to an Atlas cluster
122122
if (this.session.connectedAtlasCluster?.projectId) {
123-
metadata.projectId = this.session.connectedAtlasCluster.projectId;
123+
metadata.project_id = this.session.connectedAtlasCluster.projectId;
124124
}
125125

126126
return metadata;

src/tools/tool.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ export type ToolCategory = "mongodb" | "atlas" | "atlas-local";
4444
* the project and organization IDs if available.
4545
*/
4646
export type TelemetryToolMetadata = {
47-
projectId?: string;
48-
orgId?: string;
49-
atlasLocaldeploymentId?: string;
50-
};
47+
project_id?: string;
48+
org_id?: string;
49+
atlas_local_deployment_id?: string;
50+
} & Record<string, string | number | string[]>;
5151

5252
export type ToolConstructorParams = {
5353
session: Session;
@@ -303,21 +303,10 @@ export abstract class ToolBase {
303303
component: "tool",
304304
duration_ms: duration,
305305
result: result.isError ? "failure" : "success",
306+
...metadata,
306307
},
307308
};
308309

309-
if (metadata?.orgId) {
310-
event.properties.org_id = metadata.orgId;
311-
}
312-
313-
if (metadata?.projectId) {
314-
event.properties.project_id = metadata.projectId;
315-
}
316-
317-
if (metadata?.atlasLocaldeploymentId) {
318-
event.properties.atlas_local_deployment_id = metadata.atlasLocaldeploymentId;
319-
}
320-
321310
this.telemetry.emitEvents([event]);
322311
}
323312

0 commit comments

Comments
 (0)