-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 support for Raven, the protocol used by Sentry (http://github.com/dcramer/sentry) #76
Conversation
protocol used by Sentry (http://github.com/dcramer/sentry). Uses raven-php (https://github.com/getsentry/raven-php).
@@ -16,9 +16,11 @@ | |||
"php": ">=5.3.0" | |||
}, | |||
"require-dev": { | |||
"raven/raven": ">=0.2.0", |
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.
Please use 0.2.* or >=0.2.0,<1.0.0 or something more restrictive because this is not good since they could break BC in a future release. We shouldn't assume they won't.
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.
See 8aeb75a
"raven/raven": "0.2.*" as suggested by @Seldaek in https://github.com/Seldaek/monolog/pull/76/files#r737288
ERROR, because otherwise those messages will fail. As suggested by @Seldaek in https://github.com/Seldaek/monolog/pull/76/files#r737292
Logger::ERROR, as suggested by @Seldaek in Seldaek#76 (comment)
RavenHandlerTest::testException
tests/Monolog/Handler/RavenHandlerTest.php into a separate file so that the test can pass when raven-php is installed and can be skipped when raven-php is not installed. Addresses @stof's comment in Seldaek#76 (comment)
$this->methodThatThrowsAnException(); | ||
} | ||
catch (\Exception $e) | ||
{ |
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.
curly braces should be on the same line than the control structure (same than if, for, foreach and while)
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.
See 4830b92
Any more changes needed on this PR? |
Nope it looks good but I haven't had time to look more in depth. |
@stof, Any more feedback? |
{ | ||
$record = parent::format($record); | ||
|
||
$record['level'] = $this->logLevels[$record['level']]; |
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.
instead of changing the level here, I would move the level map to the handler to be consistent with other handlers
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.
and the formatter should return only the formatted message instead of returning a full record with a different message.
Some news about this PR ? |
Well, there is still some feedback which has not been taken into account |
Sorry to take so long. I'm not really working with Sentry or monolog these days, so this is all very rusty in my head now I'm afraid. I just pushed commit 5d17212 which addresses some but not all of @stof's comments. Maybe it's too late at night or perhaps it's simply because I've been away from monolog and raven for a long time, but I had trouble grokking some of it, particularly the comment about the If there are other folks who are interested in this PR, then it may be most expedient for them to tackle what's remaining. I don't have quite as much time or motivation as I did when I first submitted this many months ago. I wonder also if the tests could use some improving. It sounds like some stuff with params doesn't work, so maybe I am missing some test cases here. |
Looking at this a little bit more this morning, I guess I'm a little confused about what should be done in formatters vs. handlers. Some of the existing stuff in Monolog follows what you said -- where the translation of log levels happens in the handler and often these have no formatter (which makes sense because the formatters as they're explained in the docs mostly do things that are completely independent of the handler -- e.g.: adding timestamps). An example of this type of handler is Others are splitting processing between the handler and the formatter (and I probably copied the structure of one of these; in fact, I probably copied
I think I followed the model of the latter group (specifically |
In this case, indeed. Your formatted message is not a special format (like for ChromePHP or FirePHP) but a string. So you should simply use a LineFormatter here (btw, your RavenFormatter is simply a Lineformatter with a particular format which is not the default one) |
Can I just remove |
I'm also leaning towards passing |
text-oriented interface and doesn't need special processing.
Hopefully, with 368b1f0, we are almost there. |
*/ | ||
public function close() | ||
{ | ||
$this->ravenClient = null; |
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.
Removing the dependency seems weird to me
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.
Which dependency? I meant to remove RavenFormatter
. RavenHandler
still depends on RavenClient
(in line 16). Or maybe you wanted me to keep a defintion of getDefaultFormatter
?
Let me know what you meant and I'll try to turn it around quick.
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.
you are removing the dependency of the handler (the raven client) on close, which seems weird to me. This means that the handler is in a totally broken state once close (calling a method on it would trigger a fatal error). And removing the reference is not needed. PHP is able to garbage collect objects.
OK, I removed the Personally, I expect things to be unusable after I call Maybe Although just now I noticed that I don't really see any place where |
Let me know if you'd like me to make more changes. |
This looks good to me. Could you update the readme to add the handler in the list ? |
Okey doke. Done in 10fcd61. |
Bump (only because my last day at my PHP-focused job is tomorrow and I'd like to get closure on this before I get busy with other stuff). |
@msabramo thanks, unfortunately I don't have time right now but I'll try to look at all the monolog PRs in the nearish future. I'm sure this is fine by now though, don't let this keep you up at night :) |
@Seldaek Thanks! No problem. If minor tweaks are needed later on I might be able to make them, but I hesitate to commit. Like you said, it's been through quite a few rounds of discussion, so it's probably very close. |
I think you shouldn't use captureMessage as you can't pass additional data parameters. |
+1 for this pull request |
); | ||
if ($record['level'] >= Logger::ERROR && isset($record['context']['exception'])) { | ||
$this->ravenClient->captureException($record['context']['exception']); | ||
} |
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.
Won't this capture exceptions twice? Once as a regular message and once as an exception.
Merged, thanks. I mapped the new monolog log levels to sentry equivalents and added FATAL levels since it seems raven 0.3 added that level. If anyone uses this and thinks it can be improved somehow feel free to open an issue. I know there was some unresolved feedback above but from what I can tell it should work as it is, I just don't know sentry/raven enough to assess this in greater detail. Feedback from the trenches would be welcome. |
Raven is the protocol used by Sentry. Uses raven-php, which is maintained by the Sentry team.