Skip to content

Commit 8e1a8a8

Browse files
committed
Merge branch 'copilot/add-graphql-mongo-metrics' into stage
2 parents 9983081 + ea345c5 commit 8e1a8a8

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/metrics/graphql.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import client from 'prom-client';
2-
import { GraphQLRequestContext } from 'apollo-server-plugin-base';
2+
import { ApolloServerPlugin, GraphQLRequestContext, GraphQLRequestListener } from 'apollo-server-plugin-base';
33
import { GraphQLError } from 'graphql';
44

55
/**
@@ -37,8 +37,8 @@ export const gqlResolverDuration = new client.Histogram({
3737
/**
3838
* Apollo Server plugin to track GraphQL metrics
3939
*/
40-
export const graphqlMetricsPlugin = {
41-
async requestDidStart(requestContext: GraphQLRequestContext) {
40+
export const graphqlMetricsPlugin: ApolloServerPlugin = {
41+
async requestDidStart(requestContext: GraphQLRequestContext): Promise<GraphQLRequestListener> {
4242
const startTime = Date.now();
4343
let operationName = 'unknown';
4444
let operationType = 'unknown';

src/metrics/mongodb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function setupMongoMetrics(client: MongoClient): void {
6161
* e.g., { find: "users" } -> collection is "users"
6262
*/
6363
// eslint-disable-next-line @typescript-eslint/no-explicit-any
64-
const collection = (event.command as any)[event.commandName] || 'unknown';
64+
const collection = event.command ? ((event.command as any)[event.commandName] || 'unknown') : 'unknown';
6565
const db = event.databaseName || 'unknown';
6666

6767
mongoCommandDuration
@@ -88,7 +88,7 @@ export function setupMongoMetrics(client: MongoClient): void {
8888
* e.g., { find: "users" } -> collection is "users"
8989
*/
9090
// eslint-disable-next-line @typescript-eslint/no-explicit-any
91-
const collection = (event.command as any)[event.commandName] || 'unknown';
91+
const collection = event.command ? ((event.command as any)[event.commandName] || 'unknown') : 'unknown';
9292
const db = event.databaseName || 'unknown';
9393

9494
mongoCommandDuration

0 commit comments

Comments
 (0)