Skip to content
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

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/server/logging/apolloPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const metricCallCount = new prometheusClient.Counter({
module.exports = {
// eslint-disable-next-line no-unused-vars
requestDidStart(ctx) {
const apolloRequestStart = new Date()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date.now()

return {
didResolveOperation(ctx) {
let logger = ctx.context.log || graphqlLogger
Expand Down Expand Up @@ -56,6 +57,9 @@ module.exports = {
},
didEncounterErrors(ctx) {
let logger = ctx.context.log || graphqlLogger
logger = logger.child({
apollo_query_duration_ms: new Date() - apolloRequestStart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date.now

})

for (const err of ctx.errors) {
const operationName = ctx.request.operationName || null
Expand All @@ -69,9 +73,15 @@ module.exports = {
(err instanceof GraphQLError && err.extensions?.code === 'FORBIDDEN') ||
err instanceof ApolloError
) {
logger.info(err, 'graphql error')
logger.info(
err,
Copy link
Contributor

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.

'{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) => {
Expand All @@ -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()
Copy link
Contributor

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?


if (ctx.request.transaction) {
ctx.request.transaction.finish()
}
logger.info(
{
apollo_query_duration_ms: new Date() - apolloRequestStart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date.now()

},
'{graphql_operation_value} finished after {apollo_query_duration_ms} ms'
)
}
}
}
Expand Down