Skip to content

Commit 7a5ca88

Browse files
add deploymentid to telemetry data for create and delete local atlas tool
1 parent 9976243 commit 7a5ca88

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

src/telemetry/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type ToolEventProperties = {
3232
org_id?: string;
3333
cluster_name?: string;
3434
is_atlas?: boolean;
35+
atlas_local_deployment_id?: string;
3536
};
3637

3738
export type ToolEvent = TelemetryEvent<ToolEventProperties>;

src/tools/atlasLocal/atlasLocalTool.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Client } from "@mongodb-js-preview/atlas-local";
66

77
export abstract class AtlasLocalToolBase extends ToolBase {
88
public category: ToolCategory = "atlas-local";
9+
protected deploymentId?: string;
910

1011
protected verifyAllowed(): boolean {
1112
return this.session.atlasLocalClient !== undefined && super.verifyAllowed();
@@ -38,6 +39,15 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
3839
return this.executeWithAtlasLocalClient(client, ...args);
3940
}
4041

42+
protected async lookupDeploymentIdAndAddToTelemetryMetadata(
43+
client: Client,
44+
containerId: string,
45+
46+
): Promise<void> {
47+
const deploymentId = await client.getDeploymentId(containerId);
48+
this.deploymentId = deploymentId;
49+
}
50+
4151
protected abstract executeWithAtlasLocalClient(
4252
client: Client,
4353
...args: Parameters<ToolCallback<typeof this.argsShape>>
@@ -67,11 +77,9 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
6777
return super.handleError(error, args);
6878
}
6979

70-
protected resolveTelemetryMetadata(
71-
...args: Parameters<ToolCallback<typeof this.argsShape>>
72-
): TelemetryToolMetadata {
73-
// TODO: include deployment id in the metadata where possible
74-
void args; // this shuts up the eslint rule until we implement the TODO above
75-
return {};
80+
protected resolveTelemetryMetadata(): TelemetryToolMetadata {
81+
return {
82+
atlasLocaldeploymentId: this.deploymentId,
83+
};
7684
}
7785
}

src/tools/atlasLocal/create/createDeployment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export class CreateDeploymentTool extends AtlasLocalToolBase {
2626
// Create the deployment
2727
const deployment = await client.createDeployment(deploymentOptions);
2828

29+
// Lookup the deployment id and add it to the telemetry metadata
30+
await this.lookupDeploymentIdAndAddToTelemetryMetadata(client, deployment.containerId);
31+
2932
return {
3033
content: [
3134
{

src/tools/atlasLocal/delete/deleteDeployment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export class DeleteDeploymentTool extends AtlasLocalToolBase {
1616
client: Client,
1717
{ deploymentName }: ToolArgs<typeof this.argsShape>
1818
): Promise<CallToolResult> {
19+
// Lookup the deployment id and add it to the telemetry metadata
20+
await this.lookupDeploymentIdAndAddToTelemetryMetadata(client, deploymentName);
21+
1922
// Delete the deployment
2023
await client.deleteDeployment(deploymentName);
2124

src/tools/tool.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type ToolCategory = "mongodb" | "atlas" | "atlas-local";
1616
export type TelemetryToolMetadata = {
1717
projectId?: string;
1818
orgId?: string;
19+
atlasLocaldeploymentId?: string;
1920
};
2021

2122
export type ToolConstructor = new (session: Session, config: UserConfig, telemetry: Telemetry) => ToolBase;
@@ -232,6 +233,10 @@ export abstract class ToolBase {
232233
event.properties.project_id = metadata.projectId;
233234
}
234235

236+
if (metadata?.atlasLocaldeploymentId) {
237+
event.properties.atlas_local_deployment_id = metadata.atlasLocaldeploymentId;
238+
}
239+
235240
await this.telemetry.emitEvents([event]);
236241
}
237242
}

0 commit comments

Comments
 (0)