From 676edc69bd4caf0e9c8ce9fe1df24b2c4af1b78d Mon Sep 17 00:00:00 2001 From: Thierry DEGREMONT Date: Mon, 9 Sep 2024 10:54:06 +0200 Subject: [PATCH] fix error filter and log level --- package.json | 2 +- .../custom-plugins/monitor-yoga.ts | 14 +++++++------- packages/graphql-mesh/utils/logger.ts | 18 ++++++++---------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 2578ad6..775aba0 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "preinstall": "npm run build:local:packages", "start": "npm start -w graphql-mesh", "startmesh": "npm run startmesh -w graphql-mesh", - "server": "npm run server -w graphql-mesh" + "serve": "npm run serve -w graphql-mesh" }, "devDependencies": { "concurrently": "^8.2.2", diff --git a/packages/graphql-mesh/custom-plugins/monitor-yoga.ts b/packages/graphql-mesh/custom-plugins/monitor-yoga.ts index dffe845..02ae05e 100644 --- a/packages/graphql-mesh/custom-plugins/monitor-yoga.ts +++ b/packages/graphql-mesh/custom-plugins/monitor-yoga.ts @@ -18,7 +18,7 @@ export function useYagaMonitoring({ options }): Plugin { // filter error in production anyway const isFilterError = options?.filterError?.enabled || process.env['FILTER_ERRORS'] == 'true' || process.env['IS_PROUCTION_ENV'] == 'true' || false const errorMaskMessage = options?.maskError?.message ? options.maskError.message : "something goes wrong" - const responseLogInfoLevel = options?.responseLogInfoLevel ? options.responseLogInfoLevel : "low" + const responseLogInfoLevel = options?.responseLogInfoLevel ? options.responseLogInfoLevel : "medium" const resultLogInfoLevel = options?.resultLogInfoLevel ? options.resultLogInfoLevel : "medium" return { @@ -50,7 +50,7 @@ export function useYagaMonitoring({ options }): Plugin { Logger.onRequestParseDone(requestHeaders, nRequestParseDoneEventPayload.requestParserResult['query'], nRequestParseDoneEventPayload.requestParserResult['operationName'], nRequestParseDoneEventPayload.requestParserResult['variables'], timestamp - beforeTimestamp) } if (nRequestParseDoneEventPayload.requestParserResult['query'].includes('__schema')) { - Logger.introspection( requestHeaders, nRequestParseDoneEventPayload.requestParserResult['query']) + Logger.introspection(requestHeaders, nRequestParseDoneEventPayload.requestParserResult['query']) } } } @@ -78,15 +78,15 @@ export function useYagaMonitoring({ options }): Plugin { } } else { // if we want to filter error to only return the message, don't return extend information like stacktrace - if (isFilterError) { - if (args.result['errors']) { + + if (args.result['errors']) { + if (isFilterError) { let errors = args.result['errors'] for (let i = 0; i < errors.length; i++) { - errors[i] = new GraphQLError(filterErrorMessage(errors[i]['message'])) + // return only message and path + errors[i] = new GraphQLError(filterErrorMessage(errors[i]['message']), { path: errors[i]['path'] }) } - } - } } }, diff --git a/packages/graphql-mesh/utils/logger.ts b/packages/graphql-mesh/utils/logger.ts index c9b45ce..b30dadd 100644 --- a/packages/graphql-mesh/utils/logger.ts +++ b/packages/graphql-mesh/utils/logger.ts @@ -11,9 +11,8 @@ export class Logger { private static level: string = process.env["LogLevel"] || "INFO" private static format: string = process.env["LogFormat"] || "HUMAN" // set JSON_STRING to have one line json string by log - private static bodyMaxLogSize = process.env["LogBodyMaxSize"] ? parseInt(process.env["LogBodyMaxSize"]) : 100 - private static maxSkackLogSize = process.env["LogStackTraceMaxSize"] ? parseInt(process.env["LogStackTraceMaxSize"]) : 100 - private static trackerOnly: boolean = process.env["LogTrackerHeadersOnly"] ? process.env["LogTrackerHeadersOnly"] == 'true' : false + private static bodyMaxLogSize = process.env["LogBodyMaxSize"] ? parseInt(process.env["LogBodyMaxSize"]) : 200 + private static maxSkackLogSize = process.env["LogStackTraceMaxSize"] ? parseInt(process.env["LogStackTraceMaxSize"]) : 500 private static envLog: string = process.env["LogEnvFieldToAdd"] // use to add env extra field in json log ex "app=graphql,env.name=production,env.site=Paris" private static localDateCountry: string = process.env["LogLocalDateCountry"] || "fr-FR" private static logHeaders = defineLogHeaders(process.env["LogHeaders"] || "headers.host=host,headers.origin,headers.user-agent=user-agent,headers.content-length=content-length,headers.authorization=authorization") @@ -188,7 +187,7 @@ export class Logger { /** * log the on reponse event http respnse return */ - public static onResponse(request: any, response: any, logResponseLevellevel: string) { + public static onResponse(request: any, response: any, logResponseLevel: string) { const headers = request['headers'] try { if (this.isEventToLog(headers)) { @@ -211,7 +210,7 @@ export class Logger { httpStatus: response.status, duration: responseTimestamp - requestTimestamp } - if (logResponseLevellevel != 'low') { + if (logResponseLevel != 'low') { info.response['bodyExtract'] = extractBody(response.bodyInit, this.bodyMaxLogSize) } @@ -382,7 +381,6 @@ function mask(stringToMask: string) { function InfoResult(result: any, maxStackLogSize: number, resultLogInfoLevel: string) { let resultInfo = {} - let keys = null let nbKeys = 0 const maxKeys = 1 const nbErrorsMaxToLog = 3 @@ -399,10 +397,10 @@ function InfoResult(result: any, maxStackLogSize: number, resultLogInfoLevel: st logError['message'] = error['message'] } } - if (resultLogInfoLevel == 'hight') { - if (error['path']) { - logError['path'] = error['path'] - } + if (error['path']) { + logError['path'] = error['path'] + } + if (resultLogInfoLevel == 'high') { // no stack trace and extension in low trace level if (error['stack']) { logError['stack'] = error['stack'].substring(0, maxStackLogSize)