-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[Monolog] Added ElasticsearchLogstashHandler #32360
Conversation
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
I'd suggest telling this in the docblock + explain how to do it in prod |
Actually, I could work a bit on it to make it available on production: WDYT? |
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your suggestion for a prod mode makes sense to me.
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
0a45301
to
c30cf2d
Compare
|
@nicolas-grekas How can I disable all exceptions in the http-client? Or at least catch them all? (But I think this is not do-able since I use the __destruct feature) |
Hmm, I managed to do something. Could you look at the last commit? Thanks |
I rebased this PR. It's now ready and green 💚 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor doc review :)
edit : do you plan to add real doc, or a blog post to explain the config for dev/vs prod ?
i think it is a must have, to not degrade perf on prod :)
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
Not really. There is already many blog post on internet about symfony + ELK |
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
I addressed your comments |
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
acf80a7
to
982f437
Compare
This will be done in the monolog-bundle :) |
src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
Outdated
Show resolved
Hide resolved
8b1328c
to
3202332
Compare
3202332
to
1587e9a
Compare
Do you plan to add some doc ? |
src/Symfony/Bridge/Monolog/Tests/Handler/ElasticsearchLogstashHandlerTest.php
Show resolved
Hide resolved
Thank you @lyrixx. |
This PR was merged into the 4.4 branch. Discussion ---------- [Monolog] Added ElasticsearchLogstashHandler | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | This PR was initially [submitted on Monolog](Seldaek/monolog#1334). It has been refused , but Jordi suggested to add it to the symfony bridge. So here we go :) --- ATM, there are few options to push log to Elastic Stack in order to play with them: * install logstash and use a Gelf handler. It works but you have to install logstash and configure it. Not an easy task. More over, it need an extra PHP package * use the ES handler: It does not play well with context and extra: Kibana is not able to filter on nested object. And this handler is tightly coupled to the ElasticaFormatter formater. More over, it need an extra PHP package * use something to parse file logs. This is really a bad idea since it involves a parsing... More over a daemon is needed to do that (file beat / logstash / you name it) This is why I'm introducing a new Handler. * There is not need to install anything (expect ES, of course) * It play very well with Kibana, as it uses the Logstash format * It requires symfony/http-client, but in a modern PHP application (SF 4.3) this dependency is already present * It slow down a bit the application since it trigger an HTTP request for each logs. But symfony/http-client is non-blocking. If you want to use it in production, I recommend to wrap this handler in a buffer handler or a cross-finger handle to have only one HTTP call. --- Some performance consideration en a prod env with a buffer handler + this one * with push to ES: https://blackfire.io/profiles/f94ccf35-9f9d-4df1-bfc5-7fa75a535628/graph * with push to ES commented: https://blackfire.io/profiles/6b66bc18-6b90-4341-963f-797f7a7a689c/graph As you can see, as requests are made synchronously, there is no penalty on `AppKernel::Handler()` 😍! But the PHP worker has more work to do, and it's busy much more time (about X2) I explained everything in the PHP Doc Block --- This is what you can expect **out of the box** ![image](https://user-images.githubusercontent.com/408368/59916122-9b7b7580-941e-11e9-9a22-f56bc1d1a288.png) Commits ------- 1587e9a [Monolog] Added ElasticsearchLogstashHandler
@lyrixx could you please have a look at failures on branch master? It looks like the new class is not compatible with Monolog 2. Thanks. |
👍 I will look at it. Thanks |
thanks @lyrixx for this contribution :) I tried it and found the problem that the logging recrudes. The handler uses the HttpClient, which logs every request ( monolog:
handlers:
es:
type: service
id: Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler
channels: ["!http_client"] Do you have any idea how to still log the http client requests without landing in a recrusion? |
I bypassed this problem by not using the global http client: Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler:
arguments:
$client: null so I can remove the http_client channel exclude in the mongo handler config :) |
Hello. I did not anticipate this 😂 |
Hmm, I don"t see how Symfony could fix this issue since it's "normal" to have this behavior. Thanks for the feedback 👍 |
This PR was merged into the 3.x-dev branch. Discussion ---------- Use an HttpClient without logger in all handlers fixes: * symfony/symfony#34423 * symfony/symfony#32360 (comment) * symfony/symfony-docs#12642 Commits ------- faf6943 Use an HttpClient without logger in all handlers
This PR was merged into the 3.x-dev branch. Discussion ---------- Use an HttpClient without logger in all handlers fixes: * symfony/symfony#34423 * symfony/symfony#32360 (comment) * symfony/symfony-docs#12642 Commits ------- 2abc6f6 Use an HttpClient without logger in all handlers
This PR was initially submitted on Monolog.
It has been refused , but Jordi suggested to add it to the symfony bridge. So here we go :)
ATM, there are few options to push log to Elastic Stack in order to play with them:
This is why I'm introducing a new Handler.
Some performance consideration en a prod env with a buffer handler + this one
As you can see, as requests are made synchronously, there is no penalty on
AppKernel::Handler()
😍! But the PHP worker has more work to do, and it's busy much more time (about X2)I explained everything in the PHP Doc Block
This is what you can expect out of the box