Skip to content

Commit 9983081

Browse files
committed
Merge branch 'copilot/add-graphql-mongo-metrics' into stage
2 parents 1869036 + 02e6cd0 commit 9983081

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/metrics/mongodb.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ export function setupMongoMetrics(client: MongoClient): void {
5454

5555
if (startTime) {
5656
const duration = (Date.now() - startTime) / 1000;
57-
const collection = event.command?.collection || event.command?.[event.commandName] || 'unknown';
57+
58+
/**
59+
* Extract collection name from the command
60+
* For most commands, the collection name is the value of the command name key
61+
* e.g., { find: "users" } -> collection is "users"
62+
*/
63+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
64+
const collection = (event.command as any)[event.commandName] || 'unknown';
5865
const db = event.databaseName || 'unknown';
5966

6067
mongoCommandDuration
@@ -74,7 +81,14 @@ export function setupMongoMetrics(client: MongoClient): void {
7481

7582
if (startTime) {
7683
const duration = (Date.now() - startTime) / 1000;
77-
const collection = event.command?.collection || event.command?.[event.commandName] || 'unknown';
84+
85+
/**
86+
* Extract collection name from the command
87+
* For most commands, the collection name is the value of the command name key
88+
* e.g., { find: "users" } -> collection is "users"
89+
*/
90+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
91+
const collection = (event.command as any)[event.commandName] || 'unknown';
7892
const db = event.databaseName || 'unknown';
7993

8094
mongoCommandDuration

0 commit comments

Comments
 (0)