Skip to content

Commit f1abf01

Browse files
committed
refactor: Enhance logging data structure in publish function
1 parent 5fb22e1 commit f1abf01

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/metrics/graphql.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ export const graphqlMetricsPlugin: ApolloServerPlugin = {
8181

8282
const hasErrors = ctx.errors && ctx.errors.length > 0;
8383

84-
const breadcrumbData: Record<string, string | number> = { operationName, operationType, durationMs };
84+
const breadcrumbData: Record<string, string | number> = {
85+
operationName,
86+
operationType,
87+
durationMs,
88+
};
8589

8690
if (hasErrors) {
8791
breadcrumbData.errors = ctx.errors!.map((e: GraphQLError) => e.message).join('; ');

src/metrics/mongodb.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,12 @@ export function setupMongoMetrics(client: MongoClient): void {
312312
category: 'db.query',
313313
message: `${metadata.db}.${metadata.collectionFamily}.${metadata.commandName} ${event.duration}ms`,
314314
level: 'debug',
315-
data: { db: metadata.db, collection: metadata.collectionFamily, command: metadata.commandName, durationMs: event.duration },
315+
data: {
316+
db: metadata.db,
317+
collection: metadata.collectionFamily,
318+
command: metadata.commandName,
319+
durationMs: { value: event.duration },
320+
},
316321
});
317322

318323
// Clean up metadata
@@ -353,7 +358,13 @@ export function setupMongoMetrics(client: MongoClient): void {
353358
category: 'db.query',
354359
message: `${metadata.db}.${metadata.collectionFamily}.${metadata.commandName} FAILED: ${errorMsg} ${event.duration}ms`,
355360
level: 'error',
356-
data: { db: metadata.db, collection: metadata.collectionFamily, command: metadata.commandName, durationMs: event.duration, errorCode },
361+
data: {
362+
db: metadata.db,
363+
collection: metadata.collectionFamily,
364+
command: metadata.commandName,
365+
durationMs: { value: event.duration },
366+
errorCode,
367+
},
357368
});
358369

359370
// Clean up metadata

src/models/usersFactory.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Collection, Db, OptionalId } from 'mongodb';
44
import DataLoaders from '../dataLoaders';
55
import { UserDBScheme } from '@hawk.so/types';
66

7-
87
/**
98
* Users factory to work with User Model
109
*/

src/rabbitmq.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ export async function publish(exchange: string, route: string, message: string,
138138
category: 'amqp.publish',
139139
message: `AMQP publish ${exchange || '(default)'}/${route}`,
140140
level: 'debug',
141-
data: { exchange, route },
141+
data: {
142+
exchange: { value: exchange },
143+
route: { value: route },
144+
},
142145
});
143146
debug(`Message sent: ${message}`);
144147
} catch (err) {
@@ -147,7 +150,10 @@ export async function publish(exchange: string, route: string, message: string,
147150
category: 'amqp.publish',
148151
message: `AMQP publish FAILED ${exchange || '(default)'}/${route}: ${(err as Error).message}`,
149152
level: 'error',
150-
data: { exchange, route },
153+
data: {
154+
exchange: { value: exchange },
155+
route: { value: route },
156+
},
151157
});
152158
HawkCatcher.send(err as Error);
153159
console.log('Message was rejected:', (err as Error).stack);

0 commit comments

Comments
 (0)