Skip to content

Commit 6bb8bd5

Browse files
committed
feat: add gql error codes metric
1 parent be9d511 commit 6bb8bd5

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { getSubscriptionSettings } from './subscription';
3131
import { ioRedisPool } from './redis';
3232
import { loadFeatures } from './growthbook';
3333
import { runInRootSpan } from './telemetry';
34+
import { counters } from './telemetry/metrics';
3435
import { loggerConfig } from './logger';
3536
import { getTemporalClient } from './temporal/client';
3637
import { BrokenCircuitError } from 'cockatiel';
@@ -244,6 +245,13 @@ export default async function app(
244245
code: 'UNEXPECTED',
245246
};
246247
}
248+
249+
if (typeof newError.extensions?.code === 'string') {
250+
counters?.api?.graphqlErrors?.add(1, {
251+
'graphql.error.code': newError.extensions.code,
252+
});
253+
}
254+
247255
if (isProd) {
248256
newError.originalError = undefined;
249257
}

src/telemetry/metrics.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const counterMap = {
3131
description:
3232
'How many graphql operations have been performed, their operation type and name',
3333
},
34+
graphqlErrors: {
35+
name: 'graphql_errors',
36+
description: 'How many graphql errors have been returned, by error code',
37+
},
3438
rateLimit: {
3539
name: 'rate_limit',
3640
description: 'How many times a rate limit has been hit',

0 commit comments

Comments
 (0)