-
-
Notifications
You must be signed in to change notification settings - Fork 450
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
[2.0] Refactor how the events are captured and stored #487
Conversation
There shouldn't be a use case for modifying events after their creation, so 👍 for immutable events, since they are being passed around by reference now and we should avoid any "spooky action from distance". |
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.
I know it's still a WIP, I've added just small comments.
But good job, go ahead!
composer.json
Outdated
@@ -20,6 +20,7 @@ | |||
"php-http/discovery": "~1.2", | |||
"php-http/httplug": "~1.1", | |||
"psr/http-message-implementation": "~1.0", | |||
"ramsey/uuid": "~3.6", |
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.
Can we lower this to 3.3.0? Just for more BC, since that release is the oldest that I would advise to use (due to the fix to the collision bug).
lib/Raven/Client.php
Outdated
@@ -737,7 +694,7 @@ public function sanitize(&$data) | |||
/** | |||
* Process data through all defined \Raven\Processor sub-classes | |||
* | |||
* @param array $data Associative array of data to log | |||
* @param array $data Associative array of data to logf |
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.
Typo
lib/Raven/Stacktrace.php
Outdated
@@ -65,6 +65,20 @@ public function __construct(Client $client) | |||
$this->reprSerializer = $client->getReprSerializer(); | |||
} | |||
|
|||
/** |
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.
Indentation error
According to the official SDK reference what is not an attribute of the event is assumed to be an interface. I was thinking to split make the event composable: a set of data collectors should collect the data (e.g. the stacktrace or the user information) and then somehow the resulting data should be added to the event. What do you think about this? This way the |
I like the idea of splitted interfaces that follows the official SDK. I just hope that those are not too much work for no benefit!! |
Well I'm not sure if we would benefit from making it immutable since an event is mostly only handled by the Client and we might shoot ourselfs int he foot making it immutable (if we later want to introduce middleware for example) to make it easier for 3rd parties to modify the event being sent or scrub some extra data or something, or am I thinking in the wrong direction here? I do like the idea of splitting the event in components that can be composed to an event however this sounds very complex, how would you see an event being built (in pseudocode)? |
http://php.net/manual/en/function.random-bytes.php
That's good |
I've re-read the code, and I'm now inclined against an immutable object: everywhere we do a Therefore, I'm 👍 for avoiding complexity and go forward with this without immutability. @ste93cry do you want help with this? |
This is not entirely true, as the event is supposed to be passed to the processors which can edit the data it contains. Also, an immutable event would prevent any modification of itself after it reached the Httplug client that could create bugs or strange things difficult to track.
The main problem with this PR is how to collect things for the SDK data interfaces. I was thinking about creating a sort of system that works with the middleware pattern so that the event can be composed and then the processors are called on top of the built object. This would allow third parties to hook into the process at any time. Does it makes sense? |
For me it make sense, but you would be forced to create a generic |
…tags, user, server and extra data
…ctorMiddleware middleware
sentry-php/lib/Raven/Client.php Lines 363 to 365 in dcc287f
The following check can be found in the |
…he event object to send
I don't know, but this would be a change in the behavior of the lib; I think we should be coherent with all the others Sentry implementantions, and we should change this only if the others are doing it like that. |
I understood the meaning of this pull request only now. I approve changing of storing internal data from plain array to structured objects. This is how structured data (like Sentry events) should be stored. It helps to understand the meaning of every field in event datum, makes highlights in code (in IDE) and allows to find incorrect using of fields (i.e. using |
I had a look at the other SDKs, and the most common like Javascript or Ruby does not have anything similar to the "previous exception" concept of PHP. Instead, the Python SDK behaves a bit different: the |
Ok, good investigation. Please list it as a BC in the migration document then. |
Does it makes sense to log the
I don't think the session ID is a valuable information (not that the IP address is more valuable anyway imho). If users want to identify a user that got an error, then they should add tags or even better create their own middleware and edit the event object by attaching whatever info they want |
Ok so here it's the status of this PR: I asked to review the code because it's almost done, the only thing I would like to improve a bit is the code coverage of some methods (e.g. the |
I'm 👍 for removing |
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.
I've asked a few questions, but overall this PR is great! 👍
|
||
- The `Client::captureQuery` method has been removed. | ||
|
||
- The `Client::captureMessage` method has changed its signature by removing the |
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.
Maybe we should add a reason to why we removed that?
Also: it's still possible to send a generic message to sentry like this?
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.
As an example: can we easily attach a stack trace to the message?
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.
it's still possible to send a generic message to sentry like this?
It's possible by using the Client::capture
method as all other Client::capture<...>
methods just forward the call to it by passing the right options as payload.
can we easily attach a stack trace to the message?
you can by passing the exception
option in the $payload
argument.
lib/Raven/Client.php
Outdated
/** | ||
* @var callable The tip of the middleware call stack | ||
*/ | ||
private $middlewareTip; |
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.
Maybe we should call it firstMiddleware
or middlewareStackTip
for more clarity?
lib/Raven/Client.php
Outdated
/** | ||
* Seeds the middleware stack with the first callable. | ||
*/ | ||
private function seedMiddlewareStack() |
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.
Can't we do it in the constructor once and for all?
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.
Indeed, original code for the middleware part was taken from a PHP trait
available to Slim framework users and meant to be reusable, but there is no reason we have the same requirements here 👍
@@ -979,13 +672,43 @@ private function isEncodingCompressed() | |||
return 'gzip' === $this->config->getEncoding(); | |||
} | |||
|
|||
private function autoloadRavenStacktrace() |
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.
Why this has been removed? It's still needed.
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.
I cannot reproduce the bug anymore so I assumed it was somehow fixed as it's pretty old (PHP 5.2)... I tried testing with the code found in this issue: https://bugs.php.net/bug.php?id=42098.
]; | ||
} | ||
|
||
public function testInvokeWithExceptionContainingLatin1Characters() |
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.
Great work on migrating all those tests! 👍
I am not sure For the ease of use, just 3-5 lines you can implement the lib (although I am not sure what the state on that is now...) and implementing user feedback means just asking the client for the last ID no matter from where it was called (maybe even by 3rd party components on which you have no control). So in favor of keeping it simple for the end user (which I think should be considered over ultra-clean code in this lib) it might be a good idea to leave the |
It's a nice reason, in fact. I could happen frequently that Sentry is not called directly but by third party integrations (the bundle, the Laravel integration...) so yeah, maybe we should leave it. Even better, maybe we can change it to |
I would propose to have |
Ok. We can deprecate it to drop in in next major, so people will migrate toward |
Yeah we can, although I'm not bothered by it being there (if it uses the Event for getting the ID). But if you want to deprecate it I'm not against. |
My opinion about removing any |
In general, a lot of the API that exists, make an assumption that it has a good reason to exist, and I'd consider getting sign off from @getsentry/sdks before removing an actual feature. |
Sorry if my message seemed to be rude, it was not my intention. I like to simplify things the most I can and I didn't know the |
I've been refactoring the python SDK and implementing a prototype roughly based on this gist. Some features like an interface for internal SDK errors have only been shortly discussed. Axing the equivalent of getLastEventID is also planned once the integrations don't depend on it. |
Ok so:
It seems a good plan 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.
After a lot of work, this LGTM! 👍
If it's no longer WIP, we can merge it!
should I trigger a deprecated notice in the |
Since I suggested it, I'm obviously 👍 for it. That will mean that it will not be dropped until next major, so I don't think others will oppose it. |
This PR introduces an object-oriented approach for the storage of events. Before the events were stored as plain arrays of data which were frequently passed through functions. As all know PHP arrays are passed by variable while instead objects are passed by reference, so there should be improvements in term of performance. Does it makes sense to make the
Event
class immutable (like the PSR-7Request
class?