codeinternetapplications / monolog-stackdriver Goto Github PK
View Code? Open in Web Editor NEWStackdriver handler for Monolog.
License: MIT License
Stackdriver handler for Monolog.
License: MIT License
Hi,
I have installed the package for all of the logs in my Laravel 7 project. There is only thing I couldn't figure out. In the Google Cloud Logging (GCL), I can see the logs but there is no trace information. Without the trace it is difficult to point to error in the project.
In logging.php in Laravel I have setup a new channel as follows
'gcl' => [
'driver' => 'custom',
'via' => CodeInternetApplications\MonologStackdriver\Laravel\CreateStackdriverLogger::class,
'logName' => 'Zeus_'.env('APP_ENV'),
],
and changed LOG_CHANNEL to 'gcl' in .env file.
In Logs Explorer in GCL, I see the log as follows
{
"insertId": "1pw3ckdfpobou1",
"jsonPayload": {
"message": "Undefined offset: 4",
"data": {
"exception": {},
"userId": 100014
}
},
"resource": {
"type": "global",
"labels": {
"project_id": "fizbot-v2"
}
},
"timestamp": "2021-05-29T14:30:44.885308Z",
"severity": "ERROR",
"logName": "projects/fizbot-v2/logs/Zeus_local",
"receiveTimestamp": "2021-05-29T14:30:45.324374997Z"
}
I was expecting to see the whole trace under data element in jsonPayload.
After I have added new lineFormat, I can see the last line of the trace in the GCL but not all of it and all of the data is in the message section
'gcl' => [
'driver' => 'custom',
'via' => CodeInternetApplications\MonologStackdriver\Laravel\CreateStackdriverLogger::class,
'logName' => 'Zeus_'.env('APP_ENV'),
'lineFormat' => '[%datetime%] %channel%.%level_name%: %message% %context% %extra%',
],
{
"insertId": "l3chdjfl3i9ht",
"jsonPayload": {
"message": "[2021-05-29T14:36:17.221251+00:00] stackdriver.ERROR: Undefined offset: 4 {\"userId\":100014,\"exception\":\"[object] (ErrorException(code: 0): Undefined offset: 4 at /Users/canatufkansu/Sites/zeus/app/GraphQL/Queries/TestQuery.php:16)\"} []",
"data": {
"userId": 100014,
"exception": {}
}
},
"resource": {
"type": "global",
"labels": {
"project_id": "fizbot-v2"
}
},
"timestamp": "2021-05-29T14:36:17.221298Z",
"severity": "ERROR",
"logName": "projects/fizbot-v2/logs/Zeus_local",
"receiveTimestamp": "2021-05-29T14:36:17.551372993Z"
}
I can live with this but is there better configuration that I can get the whole trace in Google Cloud Logging ?
I am trying to integrate with symfony but service does not register?
Do you have any comments on that or anyone else has done a integration?
Hi,
When I'm using the google API, I don't provide the project ID or the json path, I just instantiate the object with an empty constructor :
$pubsub = new PubSub();
And the google API will get from the env variables of the AppEngine / (or one that I've set manually on my local dev machine).
GOOGLE_CLOUD_PROJECT, GOOGLE_APPLICATION_CREDENTIALS
putenv("GOOGLE_APPLICATION_CREDENTIALS=/Users/thomas/.proj/project-fr-dev-3536b42e73ef.json");
(it's enough, I didn't set the GOOGLE_CLOUD_PROJECT)
With monolog-stackdriver, I've tried to use an empty constructor and got an error.
It would be nice to be able to instantiate the monolog_strackdriver with an empty constructor.
Side note: using StackDriver locally slow down a lot the application. It put a 3 secondes response time delay each time the logger is used.
I didn't tried yet in an AppEngine, but It feel bad for performances.
Hey,
using your implementation with monolog/monolog >=2.0 currently does not working, because StackdriverHandler does not comply with Monolog/Handler/AbstractHandler.
The return value of StackdriverHandler->write() should be void.
The return value of StackdriverHandler->write() should be array.
Additionally we need to restrict the monolog version in the current releases to monolog/monolog: 1.*
With latest monolog-stackdriver
installed and configured on the latest stable Laravel, when I switch logging to stackdriver
and I get an error it returns the following. It works fine when I switch logging back to stack
but then I cannot log errors to google cloud logging.
"Error decoding message: Invalid argument supplied for foreach()",…}
exception: "Google\ApiCore\ValidationException"
file: "/var/www/mydomain/vendor/google/gax/src/Serializer.php"
line: 128
message: "Error decoding message: Invalid argument supplied for foreach()"
trace: [{file: "/var/www/mydoman/vendor/google/cloud-logging/src/Connection/Grpc.php", line: 331,…},…]
0: {file: "/var/www/mydomain/vendor/google/cloud-logging/src/Connection/Grpc.php", line: 331,…}
1: {file: "/var/www/mydomain/vendor/google/cloud-logging/src/Connection/Grpc.php", line: 138,…}
2: {file: "/var/www/mydomain/vendor/google/cloud-logging/src/Logger.php", line: 412,…}
3: {file: "/var/www/mydomain/vendor/google/cloud-logging/src/Logger.php", line: 380, function: "writeBatch",…}
4: {,…}
5: {file: "/var/www/mydomain/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php",…}
6: {file: "/var/www/mydomain/vendor/monolog/monolog/src/Monolog/Logger.php", line: 323, function: "handle",…}
7: {file: "/var/www/mydomain/vendor/monolog/monolog/src/Monolog/Logger.php", line: 541,…}
8: {file: "/var/www/mydomain/vendor/laravel/framework/src/Illuminate/Log/Logger.php", line: 174,…}
9: {file: "/var/www/mydomain/vendor/laravel/framework/src/Illuminate/Log/Logger.php", line: 87,…}
10: {file: "/var/www/mydomain/vendor/laravel/framework/src/Illuminate/Log/LogManager.php", line: 547,…}
11: {file: "/var/www/mydomain/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php",…}
12: {file: "/var/www/mydomain/app/Exceptions/Handler.php", line: 41, function: "report",…}
13: {,…}
14: {function: "handleException", class: "Illuminate\Foundation\Bootstrap\HandleExceptions", type: "->"}
It's just a standard exception error. Nothing that should cause a log channel to fail. I think this is happening with all 500 errors that Laravel generates.
The name should probably be changed to Google Operations or Google Cloud Logging. I don't think they call it stackdriver anymore. I couldn't find this package at first doing a search for monolog + google cloud logging.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.