Skip to content
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

Merged
merged 17 commits into from
Jan 7, 2013

Conversation

msabramo
Copy link
Contributor

Raven is the protocol used by Sentry. Uses raven-php, which is maintained by the Sentry team.

@@ -16,9 +16,11 @@
"php": ">=5.3.0"
},
"require-dev": {
"raven/raven": ">=0.2.0",
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 8aeb75a

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)
{
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 4830b92

@msabramo
Copy link
Contributor Author

msabramo commented May 2, 2012

Any more changes needed on this PR?

@Seldaek
Copy link
Owner

Seldaek commented May 2, 2012

Nope it looks good but I haven't had time to look more in depth.

@msabramo
Copy link
Contributor Author

msabramo commented May 6, 2012

@stof, Any more feedback?

{
$record = parent::format($record);

$record['level'] = $this->logLevels[$record['level']];
Copy link
Contributor

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

Copy link
Contributor

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.

@yguedidi
Copy link

Some news about this PR ?

@stof
Copy link
Contributor

stof commented Oct 24, 2012

Well, there is still some feedback which has not been taken into account

@msabramo
Copy link
Contributor Author

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 $params passed to the Raven_Client, so I didn't handle all of the concerns.

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.

@msabramo
Copy link
Contributor Author

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 SyslogHandler.

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 GelfHandler since Graylog seemed most similar to Sentry). Examples are:

  • FirePHPHandler and WildfireFormatter.
  • ChromePHPHandler and ChromePHPFormatter
  • GelfHandler and GelfMessageFormatter

I think I followed the model of the latter group (specifically GelfHandler), but I wonder if I should be following the model of the former. It seems to me that I probably could get by with just RavenHandler and completely get rid of RavenFormatter. This would let me take advantage of other formatters. Am I right about this?

@stof
Copy link
Contributor

stof commented Oct 25, 2012

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)

@msabramo
Copy link
Contributor Author

Can I just remove getDefaultFormatter entirely and let it fall back to the default formatter defined by AbstractHandler?

@msabramo
Copy link
Contributor Author

I'm also leaning towards passing $params = array() to Raven_Client::captureMessage because I don't see anything useful at the moment that I can put there (I think what I had before was silly and not doing anything). This seems to be a special feature of Raven which monolog doesn't really need (since it has its own formatters)...?

text-oriented interface and doesn't need special processing.
@msabramo
Copy link
Contributor Author

Hopefully, with 368b1f0, we are almost there.

*/
public function close()
{
$this->ravenClient = null;
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@msabramo
Copy link
Contributor Author

OK, I removed the close method. As an aside, GelfHandler does this as well and that is almost certainly where it came from for me.

Personally, I expect things to be unusable after I call close on them so that didn't bother me. But I don't think it matters much either way as garbage collection will take care of like you said, so I'm fine with removing the close method.

Maybe close in monolog is more of a flush in that for RotatingFileHandler it does log rotation. I don't think I realized that until now and thought of close more in the sense of what you do on a raw file or a database connection.

Although just now I noticed that StreamHandler also closes and sets the underlying stream to null. So I don't know what close is supposed to do; I guess it's implementation-dependent.

I don't really see any place where Logger calls close (either implicitly or exposing a method that lets the user close the logger), so this might be a moot point.

@msabramo
Copy link
Contributor Author

Let me know if you'd like me to make more changes.

@stof
Copy link
Contributor

stof commented Oct 29, 2012

This looks good to me. Could you update the readme to add the handler in the list ?

@msabramo
Copy link
Contributor Author

Okey doke. Done in 10fcd61.

@msabramo
Copy link
Contributor Author

msabramo commented Nov 1, 2012

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).

@Seldaek
Copy link
Owner

Seldaek commented Nov 1, 2012

@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 :)

@msabramo
Copy link
Contributor Author

msabramo commented Nov 1, 2012

@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.

@vytautasgimbutas
Copy link

I think you shouldn't use captureMessage as you can't pass additional data parameters.

@luxifer
Copy link
Contributor

luxifer commented Nov 22, 2012

+1 for this pull request

);
if ($record['level'] >= Logger::ERROR && isset($record['context']['exception'])) {
$this->ravenClient->captureException($record['context']['exception']);
}

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.

@Seldaek Seldaek merged commit 10fcd61 into Seldaek:master Jan 7, 2013
@Seldaek
Copy link
Owner

Seldaek commented Jan 7, 2013

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.

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

Successfully merging this pull request may close these issues.

None yet

8 participants