-
Notifications
You must be signed in to change notification settings - Fork 36
Introduce PSR-14 Event for Intercepting and Modifying Data Sent to Sentry #114
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
Open
balatD
wants to merge
3
commits into
networkteam:main
Choose a base branch
from
balatD:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Networkteam\SentryClient\Event; | ||
|
||
use Psr\EventDispatcher\StoppableEventInterface; | ||
use Throwable; | ||
|
||
/** | ||
* Event dispatched just before an exception is sent to Sentry. | ||
* | ||
* Listeners can use this event to: | ||
* - Modify the exception before it's sent. | ||
* - Add specific context/tags to Sentry scope for this exception. | ||
* - Prevent the exception from being sent entirely by calling stopPropagation(). | ||
*/ | ||
class BeforeSentryCaptureEvent implements StoppableEventInterface | ||
{ | ||
private bool $propagationStopped = false; | ||
private Throwable $exception; | ||
|
||
public function __construct(Throwable $exception) | ||
{ | ||
$this->exception = $exception; | ||
} | ||
|
||
public function getException(): Throwable | ||
{ | ||
return $this->exception; | ||
} | ||
|
||
public function setException(Throwable $exception): void | ||
{ | ||
$this->exception = $exception; | ||
} | ||
|
||
public function isPropagationStopped(): bool | ||
{ | ||
return $this->propagationStopped; | ||
} | ||
|
||
public function stopPropagation(): void | ||
{ | ||
$this->propagationStopped = true; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Resources/Public/JavaScript/remove-usercentrics-glitchtip-cookie.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function removeCookieByName(name) { | ||
const cookieName = name; | ||
const pastDate = 'Thu, 01 Jan 1970 00:00:00 GMT'; | ||
|
||
document.cookie = `${cookieName}=; expires=${pastDate}; path=/; SameSite=Lax; Secure`; | ||
|
||
console.log(`Attempted to remove cookie "${cookieName}". Check browser developer tools to confirm.`); | ||
} | ||
|
||
const cookieNameToRemove = 'allow-glitchtip'; | ||
removeCookieByName(cookieNameToRemove); |
15 changes: 15 additions & 0 deletions
15
Resources/Public/JavaScript/set-usercentrics-glitchtip-cookie.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function setPersistentCookie(name, value, days) { | ||
let expires = ""; | ||
if (days) { | ||
const date = new Date(); | ||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | ||
expires = "; expires=" + date.toUTCString(); | ||
} | ||
document.cookie = name + "=" + (value || "") + expires + "; path=/; SameSite=Lax; Secure"; | ||
} | ||
|
||
const cookieName = 'allow-glitchtip'; | ||
const cookieValue = 'true'; | ||
const expirationInDays = 365; | ||
|
||
setPersistentCookie(cookieName, cookieValue, expirationInDays); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
IMHO
isPropagationStopped()
check is used wrong here: the event dispatcher takes care to check if other listeners in the queue should be called (isPropagationStopped()
returns true). You use this to avoid the sending of exceptions to Sentry - which is wrong IMHO.There may be valid use cases in an installation to define two event listeners where the first one says: I am the one, the second shouldn't be called - then modifies the exception for storage in Sentry and sets propagation stopped - and in your implementation the exception is not send to Sentry altogether. Think of an extension plugin which has a token (person-referenced) in a URL or a user id which the appropriate listener want to obfuscate. Other listeners are not needed to be called therefore.
So, I suggest to decouple that and introduce a separate method to disable the sending of exceptions. Maybe the implementation of the stoppable interface is not needed altogether and can be removed.