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

add apollo query duration #1947

merged 3 commits into from
Jan 10, 2024

Conversation

gjedlicska
Copy link
Contributor

Description & motivation

Changes:

To-do before merge:

Screenshots:

Validation of changes:

Checklist:

  • My pull request follows the guidelines in the Contributing guide?
  • My pull request does not duplicate any other open Pull Requests for the same update/change?
  • My commits are related to the pull request and do not amend unrelated code or documentation.
  • My code follows a similar style to existing code.
  • I have added appropriate tests.
  • I have updated or added relevant documentation.

References

let logger = ctx.context.log || graphqlLogger
if (ctx.context.apolloRequestStart)
logger = logger.child({
'apollo-query-duration': new Date() - ctx.context.apolloRequestStart
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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')
Copy link
Contributor

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()
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?

@@ -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.

@@ -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()

@@ -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


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()

@gjedlicska gjedlicska merged commit e0aee71 into main Jan 10, 2024
19 of 21 checks passed
@gjedlicska gjedlicska deleted the gergo/apolloQueryDuration branch January 11, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants