-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add apollo query duration #1947
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ const metricCallCount = new prometheusClient.Counter({ | |
module.exports = { | ||
// eslint-disable-next-line no-unused-vars | ||
requestDidStart(ctx) { | ||
const apolloRequestStart = new Date() | ||
return { | ||
didResolveOperation(ctx) { | ||
let logger = ctx.context.log || graphqlLogger | ||
|
@@ -56,6 +57,9 @@ module.exports = { | |
}, | ||
didEncounterErrors(ctx) { | ||
let logger = ctx.context.log || graphqlLogger | ||
logger = logger.child({ | ||
apollo_query_duration_ms: new Date() - apolloRequestStart | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) | ||
|
||
for (const err of ctx.errors) { | ||
const operationName = ctx.request.operationName || null | ||
|
@@ -69,9 +73,15 @@ module.exports = { | |
(err instanceof GraphQLError && err.extensions?.code === 'FORBIDDEN') || | ||
err instanceof ApolloError | ||
) { | ||
logger.info(err, 'graphql error') | ||
logger.info( | ||
err, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for |
||
'{graphql_operation_value} failed after {apollo_query_duration_ms} ms' | ||
) | ||
} else { | ||
logger.error(err, 'graphql error') | ||
logger.error( | ||
err, | ||
'{graphql_operation_value} failed after {apollo_query_duration_ms} ms' | ||
) | ||
} | ||
|
||
Sentry.withScope((scope) => { | ||
|
@@ -91,12 +101,18 @@ module.exports = { | |
} | ||
}, | ||
willSendResponse(ctx) { | ||
const logger = ctx.context.log || graphqlLogger | ||
logger.info('graphql response') | ||
let logger = ctx.context.log || graphqlLogger | ||
logger = logger.child() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why call child without any new properties? |
||
|
||
if (ctx.request.transaction) { | ||
ctx.request.transaction.finish() | ||
} | ||
logger.info( | ||
{ | ||
apollo_query_duration_ms: new Date() - apolloRequestStart | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
'{graphql_operation_value} finished after {apollo_query_duration_ms} ms' | ||
) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Date.now()