Skip to content
Advertisement

GCP error reporting stacktrace sample is not detected

I’m currently trying to implement the GCP error reporting for a Symfony project (PHP) in order to report any errors especially the stack trace of the application. The implementation is done by using the Google Cloud Client Library. However it appear that GCP is not detecting the stacktrace that I’m sending. Below is a screenshot of how it look like on the interface:

enter image description here

As documented in this documentation. I have to precise the type of message that I’m sending to the ReportedEventError (If i’m not mistaken the message should be prefix by the ‘PHP Fatal Error’) string in order for the message to be recognized as a stacktrace. But that didn’t worked.

In order for you to help me solve my issues below is the JSON paylaod of what is send by the Google Cloud Client Library.

  {
    "insertId": "INSERT ID ",
    "jsonPayload": {
      "context": {
        "httpRequest": {
          "responseStatusCode": 500,
          "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
          "method": "GET",
          "url": "/ping/edit",
          "remoteIp": "172.18.0.1"
        },
        "reportLocation": {
          "functionName": "editAction",
          "filePath": "/app/src/NS/PingBundle/Controller/DefaultController.php",
          "lineNumber": 24
        }
      },
      "message": "PHP Fatal error: #0 [internal function]: NS\CommonBundle\EventListener\ExceptionListener->onKernelException(Object(Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent), 'kernel.exceptio...', Object(Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher))n#1 /app/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php(104): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent), 'kernel.exceptio...', Object(Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher))n#2 [internal function]: Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(Object(Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent), 'kernel.exceptio...', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))n#3 /app/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(212): call_user_func(Object(Symfony\Component\EventDispatcher\Debug\WrappedListener), Object(Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent), 'kernel.exceptio...', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))n#4 /app/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(44): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'kernel.exceptio...', Object(Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent))n#5 /app/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php(146): Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.exceptio...', Object(Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent))n#6 /app/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(230): Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.exceptio...', Object(Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent))n#7 /app/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(79): Symfony\Component\HttpKernel\HttpKernel->handleException(Object(Exception), Object(Symfony\Component\HttpFoundation\Request), 1)n#8 /app/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(171): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)n#9 /app/web/app_dev.php(28): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))n#10 {main}",
      "serviceContext": {
        "service": "hummingbird-sf"
      },
      "@type": "type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent"
    },
    "httpRequest": {
      "requestMethod": "GET",
      "requestUrl": "/ping/edit",
      "status": 500,
      "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
      "remoteIp": "172.18.0.1"
    },
    "resource": {
      "type": "reported_errors",
      "labels": {
        "project_id": "<project_id>"
      }
    },
    "timestamp": "2019-12-09T14:33:51.792619820Z",
    "severity": "ERROR",
    "logName": "projects/<project_id>/logs/clouderrorreporting.googleapis.com%2Freported_errors",
    "sourceLocation": {
      "file": "/app/src/NS/PingBundle/Controller/DefaultController.php",
      "line": "24",
      "function": "editAction"
    },
    "receiveTimestamp": "2019-12-09T14:33:51.792619820Z"
  }

Note: I also try to remove the location which didn’t work either. As for the Symfony framework integration this solution didn’t work too for others reasons…

Does anyone have any ideas ?

Advertisement

Answer

The issue I had was that I used the Symfony default’s method to print the error. In order to resolve this issue I replace this piece of code

$this->stacktrace->getTraceAsString()

by

(string) $this->stacktrace

and the stacktrace appear.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement