Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

GraphQl-220: Implement exception logging #355

Merged

Conversation

novikor
Copy link
Contributor

@novikor novikor commented Feb 7, 2019

Description (*)

Created logging for client and server errors.
I use exception category from \GraphQL\Error\ClientAware to divide errors between the client (var/log/graphql/client/exception.log) and server (var/log/graphql/server/exception.log).
In case the category is not recognized, the errors will be logged into a general log (var/log/graphql/exception.log)

Fixed Issues (if relevant)

  1. Implement exception logging #220: Implement exception logging

Manual testing scenarios (*)

  1. Cause any client-side error (Incorrect query parameter, for example) and check var/log/graphql/client/exception.log
  2. Manually throw exception elsewhere on backend during query processing, and check var/log/graphql/server/exception.log

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

Maksym Novik added 2 commits February 7, 2019 14:53
Created custom error handler;
Applied default error handling functionality
Implemented client and server errors logging
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Feb 7, 2019

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ vpodorozh
✅ novikor
❌ Maksym Novik


Maksym Novik seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.

@novikor
Copy link
Contributor Author

novikor commented Feb 13, 2019

Probably, it could be a better idea to use \GraphQL\Error\ClientAware::isClientSafe to detect if it is a client-side error instead of \GraphQL\Error\ClientAware::getCategory.

It this case there will be no need to update the virtualtypes every time new exception category is created.

naydav
naydav previously requested changes Mar 5, 2019
app/etc/di.xml Outdated Show resolved Hide resolved
app/etc/di.xml Outdated Show resolved Hide resolved
@novikor
Copy link
Contributor Author

novikor commented Mar 18, 2019

@naydav , @paliarush
I can suggest 2 ways to divide errors into client and server:

  • Use \GraphQL\Error\ClientAware::isClientSafe
  • Just check if the exception is an instance of \Magento\Framework\Exception\LocalizedException

@naydav naydav changed the title Implement exception logging#220 GraphQl-220: Implement exception logging May 2, 2019
@vpodorozh vpodorozh self-assigned this Jun 12, 2019
@vpodorozh vpodorozh self-requested a review June 12, 2019 19:38
@vpodorozh
Copy link
Contributor

@magento run all tests

…ent-exception-logging#220

# Conflicts:
#	app/etc/di.xml
Copy link
Contributor

@vpodorozh vpodorozh left a comment

Choose a reason for hiding this comment

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

@novikor - please check my review

@vpodorozh
Copy link
Contributor

vpodorozh commented Jun 15, 2019

@naydav , @paliarush
I can suggest 2 ways to divide errors into client and server:

  • Use \GraphQL\Error\ClientAware::isClientSafe
  • Just check if the exception is an instance of \Magento\Framework\Exception\LocalizedException

@novikor - I've put the comments to review from @naydav about my vision.
I think we can start implementing it (my vision :) ) from Wednesday (19.06) in case guys will not respond with their notes.

Thank you!

novikor pushed a commit to novikor/graphql-ce that referenced this pull request Jun 22, 2019
Moved DI to graphql area;
Create ResolveLogger service;
Use ClientAvare->isClientSafe() to divide exceptions into client and server
@novikor novikor requested a review from vpodorozh June 22, 2019 10:20
@novikor novikor dismissed naydav’s stale review June 22, 2019 10:20

Not actual anymore

Moved DI to graphql area;
Create ResolveLogger service;
Use ClientAvare->isClientSafe() to divide exceptions into client and server
@novikor novikor force-pushed the Implement-exception-logging#220 branch from bc45d86 to 6a5c7e2 Compare June 22, 2019 14:30
@vpodorozh
Copy link
Contributor

seems to be ok - tested it locally with different error types. Waiting for test builds.

Copy link
Contributor

@vpodorozh vpodorozh left a comment

Choose a reason for hiding this comment

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

@novikor - please check my change request.

@swnsma - please pick up this PR as a reviewer, I do not have any permissions for approving.
Thx!

@novikor
Copy link
Contributor Author

novikor commented Aug 28, 2019

Yep. It will be finished this week.

Removed client errors logging.
@novikor
Copy link
Contributor Author

novikor commented Aug 28, 2019

PR is ready for review.

Integration or at least Unit tests will be provided at the end of the current week.

@TomashKhamlai TomashKhamlai added the QA in progress We are checking label Aug 28, 2019
@TomashKhamlai
Copy link
Contributor

@novikor, please try these steps:

  1. php bin/magento deploy:mode:set developer
  2. Perform steps described in [Customizable Options] Call to a member function format() on boolean #761

Expected result(until #761 is not fixed):

{
  "errors": [
    {
      "debugMessage": "Call to a member function format() on boolean",
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "addSimpleProductsToCart"
      ]
    }
  ],
  "data": {
    "addSimpleProductsToCart": null
  }
}

Actual result:

{
  "errors": [
    {
      "message": "Internal server error",
      "category": "internal",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "addSimpleProductsToCart"
      ]
    }
  ],
  "data": {
    "addSimpleProductsToCart": null
  }
}

It seems like a regression. Also, it doesn't work for me in production mode. I do not see any error log, do you see any?

@novikor
Copy link
Contributor Author

novikor commented Aug 28, 2019

Looks strange. I will check again

@novikor
Copy link
Contributor Author

novikor commented Aug 31, 2019

Hi, @TomashKhamlai .
I have rechecked your case and failed to reproduce the problem.
Please take my patch for simplifying steps to reproduce (attached).
GraphQl-220__Implement_exception_logging_.patch.zip

Use the next query:

{
  products(filter: {}) {
    total_count
  }
}

image

@lenaorobei
Copy link
Contributor

I've tested your branch and it logs the same message in 2 places var/log/graphql/exception.log and exception.log. Please consider logging in one place, I would suggest var/log/exception.log.

Removed duplicated logging to var/log/graphql.
@novikor
Copy link
Contributor Author

novikor commented Sep 6, 2019

Fixed

@ghost
Copy link

ghost commented Sep 10, 2019

Hi @novikor, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants