Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"clue/mq-react": "^1.6",
"react/http": "^1.11",
"react/socket": "^1.16",
"sentry/sentry": "^4.10"
"sentry/sentry": "^4.11.1"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 5 additions & 0 deletions src/Envelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public function getItems(): array
return $this->items;
}

public function isEmpty(): bool
{
return empty($this->items);
}

/**
* @param callable(EnvelopeItem): bool $callback if the callback returns true, the item will be removed from the envelope
*/
Expand Down
17 changes: 7 additions & 10 deletions src/EnvelopeForwarder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Psr\Http\Message\ResponseInterface;
use React\Http\Browser;
use React\Promise\Internal\FulfilledPromise;
use React\Promise\PromiseInterface;
use Sentry\Dsn;
use Sentry\HttpClient\Response;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function __construct(float $timeout, callable $onEnvelopeSent, callable $
}

/**
* @return PromiseInterface<void>
* @return PromiseInterface<void|null>
*/
public function forward(Envelope $envelope): PromiseInterface
{
Expand All @@ -72,17 +73,13 @@ public function forward(Envelope $envelope): PromiseInterface
$rateLimiter = $this->getRateLimiter($dsn);

$envelope->rejectItems(static function (EnvelopeItem $envelopeItem) use ($rateLimiter) {
$envelopeItemType = $envelopeItem->getItemType();

// @TODO: We should make the rate limiter accept an arbitrary item type to allow for flexibility when adding new item types
if ($envelopeItemType === null) {
return false;
}

return $rateLimiter->isRateLimited($envelopeItemType);
return $rateLimiter->isRateLimited($envelopeItem->getHeader()['type']);
});

// @TODO: If we rate limit all the items we have an empty envelope which we should not send and just return
// When the envelope is empty, we don't need to send it
if ($envelope->isEmpty()) {
return new FulfilledPromise();
}

$authHeader = [
'sentry_version=' . self::PROTOCOL_VERSION,
Expand Down
16 changes: 0 additions & 16 deletions src/EnvelopeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Sentry\Agent;

use Sentry\EventType;

/**
* @internal
*
Expand Down Expand Up @@ -43,20 +41,6 @@ public function getHeader(): array
return $this->header;
}

public function getItemType(): ?EventType
{
switch ($this->header['type']) {
case (string) EventType::event():
return EventType::event();
case (string) EventType::transaction():
return EventType::transaction();
case (string) EventType::checkIn():
return EventType::checkIn();
default:
return null;
}
}

public function getData(): string
{
return $this->data;
Expand Down