-
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
Conversation
let logger = ctx.context.log || graphqlLogger | ||
if (ctx.context.apolloRequestStart) | ||
logger = logger.child({ | ||
'apollo-query-duration': new Date() - ctx.context.apolloRequestStart |
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.
FYI: Typescript doesn't like subtracting dates. From what I recall, I think you need to call .getTime()
and subtract that.
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.
I think Date.now()
is what you're looking for
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.
i always forget that, thanks
|
||
if (ctx.request.transaction) { | ||
ctx.request.transaction.finish() | ||
} | ||
logger.info('graphql response') |
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.
Ideally this should be unique so we can easily find the location in the code. We already log graphql response
elsewhere.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
why call child without any new properties?
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
for .info
we need to wrap the error in an object e.g. {err}
, I believe. Only .error
wraps it automatically.
@@ -18,6 +18,7 @@ const metricCallCount = new prometheusClient.Counter({ | |||
module.exports = { | |||
// eslint-disable-next-line no-unused-vars | |||
requestDidStart(ctx) { | |||
const apolloRequestStart = new Date() |
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()
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Date.now
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Date.now()
Description & motivation
Changes:
To-do before merge:
Screenshots:
Validation of changes:
Checklist:
References