Skip to content

Commit

Permalink
Do not set the transaction attribute of the event when in CLI (getsen…
Browse files Browse the repository at this point in the history
  • Loading branch information
ste93cry authored Aug 9, 2019
1 parent 75118ea commit 19e629d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix `TypeError` in `Sentry\Monolog\Handler` when the extra data array has numeric keys (#833).
- Fix sending of GZIP-compressed requests when the `enable_compression` option is `true` (#857)
- Fix error thrown when trying to set the `transaction` attribute of the event in a CLI environment (#862)

## 2.1.1 (2019-06-13)

Expand Down
10 changes: 2 additions & 8 deletions src/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Sentry\Exception\EventCreationException;
use Sentry\Serializer\RepresentationSerializerInterface;
use Sentry\Serializer\SerializerInterface;
use Zend\Diactoros\ServerRequestFactory;

/**
* Factory for the {@see Event} class.
Expand Down Expand Up @@ -93,13 +92,8 @@ public function create(array $payload): Event

if (isset($payload['transaction'])) {
$event->setTransaction($payload['transaction']);
} else {
$request = ServerRequestFactory::fromGlobals();
$serverParams = $request->getServerParams();

if (isset($serverParams['PATH_INFO'])) {
$event->setTransaction($serverParams['PATH_INFO']);
}
} elseif (isset($_SERVER['PATH_INFO'])) {
$event->setTransaction($_SERVER['PATH_INFO']);
}

if (isset($payload['logger'])) {
Expand Down
6 changes: 3 additions & 3 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

class ClientTest extends TestCase
{
/**
* @backupGlobals
*/
public function testTransactionEventAttributeIsPopulated(): void
{
$_SERVER['PATH_INFO'] = '/foo';
Expand All @@ -39,9 +42,6 @@ public function testTransactionEventAttributeIsPopulated(): void

$client = new Client(new Options(), $transport, $this->createEventFactory());
$client->captureMessage('test');

unset($_SERVER['PATH_INFO']);
unset($_SERVER['REQUEST_METHOD']);
}

public function testTransactionEventAttributeIsNotPopulatedInCli(): void
Expand Down
3 changes: 3 additions & 0 deletions tests/EventFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

class EventFactoryTest extends TestCase
{
/**
* @backupGlobals
*/
public function testCreateEventWithDefaultValues(): void
{
$options = new Options();
Expand Down

0 comments on commit 19e629d

Please sign in to comment.