Skip to content

Commit

Permalink
fix error filter and log level
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry DEGREMONT committed Sep 16, 2024
1 parent 9385c8d commit 676edc6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions packages/graphql-mesh/custom-plugins/monitor-yoga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'])
}
}
}
Expand Down Expand Up @@ -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'] })
}

}

}
}
},
Expand Down
18 changes: 8 additions & 10 deletions packages/graphql-mesh/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)) {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 676edc6

Please sign in to comment.