Skip to content

Commit 91c11cc

Browse files
feat: added atlas local deployment id to telemetry (#627)
1 parent cb5d335 commit 91c11cc

File tree

8 files changed

+57
-31
lines changed

8 files changed

+57
-31
lines changed

package-lock.json

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"node": "^20.19.0 || ^22.12.0 || >= 23.0.0"
122122
},
123123
"optionalDependencies": {
124-
"@mongodb-js-preview/atlas-local": "^0.0.0-preview.6",
124+
"@mongodb-js-preview/atlas-local": "^0.0.0-preview.7",
125125
"kerberos": "^2.2.2"
126126
}
127127
}

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: 17 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,18 @@ 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 lookupDeploymentId(client: Client, containerId: string): Promise<void> {
43+
// Don't run if telemetry is disabled
44+
if (this.telemetry.isTelemetryEnabled()) {
45+
return;
46+
}
47+
48+
// Lookup the deployment id and save it to the deploymentId property.
49+
// This property will be added to the telemetry metadata when resolveTelemetryMetadata is called.
50+
const deploymentId = await client.getDeploymentId(containerId);
51+
this.deploymentId = deploymentId;
52+
}
53+
4154
protected abstract executeWithAtlasLocalClient(
4255
client: Client,
4356
...args: Parameters<ToolCallback<typeof this.argsShape>>
@@ -67,11 +80,9 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
6780
return super.handleError(error, args);
6881
}
6982

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 {};
83+
protected resolveTelemetryMetadata(): TelemetryToolMetadata {
84+
return {
85+
atlasLocaldeploymentId: this.deploymentId,
86+
};
7687
}
7788
}

src/tools/atlasLocal/connect/connectDeployment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export class ConnectDeploymentTool extends AtlasLocalToolBase {
2222
// Connect to the deployment
2323
await this.session.connectToMongoDB({ connectionString });
2424

25+
// Lookup the deployment id and add it to the telemetry metadata
26+
await this.lookupDeploymentId(client, deploymentName);
27+
2528
return {
2629
content: [
2730
{

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.lookupDeploymentId(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.lookupDeploymentId(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)