Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive committed Sep 25, 2020
1 parent b31f435 commit 9368b24
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
14 changes: 4 additions & 10 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco
}
}

$this->addMissingStacktraceToEvent($event);

$event->setSdkIdentifier($this->sdkIdentifier);
$event->setSdkVersion($this->sdkVersion);
$event->setServerName($this->options->getServerName());
$event->setRelease($this->options->getRelease());
$event->setTags($this->options->getTags());
$event->setEnvironment($this->options->getEnvironment());

$this->addMissingStacktraceToEvent($event, $hint);

$sampleRate = $this->options->getSampleRate();

if (EventType::transaction() !== $event->getType() && $sampleRate < 1 && mt_rand(1, 100) / 100.0 > $sampleRate) {
Expand Down Expand Up @@ -264,20 +264,14 @@ private function prepareEvent(Event $event, ?EventHint $hint = null, ?Scope $sco
/**
* Optionally adds a missing stacktrace to the Event if the client is configured to do so.
*
* @param Event $event The Event to add the missing stacktrace to
* @param EventHint|null $hint May contain additional information about the event
* @param Event $event The Event to add the missing stacktrace to
*/
private function addMissingStacktraceToEvent(Event $event, ?EventHint $hint): void
private function addMissingStacktraceToEvent(Event $event): void
{
if (!$this->options->shouldAttachStacktrace()) {
return;
}

// If the hint contains an exception the stacktrace will be generated for that exception
if (null !== $hint && null !== $hint->exception) {
return;
}

// We should not add a stacktrace when the event already has one or contains exceptions
if (null !== $event->getStacktrace() || !empty($event->getExceptions())) {
return;
Expand Down
6 changes: 3 additions & 3 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ public function testCaptureException(): void

public function testCaptureEvent(): void
{
$event = Event::createEvent($eventId = EventId::generate());
$event = Event::createEvent();

/** @var ClientInterface|MockObject $client */
$client = $this->createMock(ClientInterface::class);
$client->expects($this->once())
->method('captureEvent')
->with($event)
->willReturn($eventId);
->willReturn($event->getId());

SentrySdk::getCurrentHub()->bindClient($client);

$this->assertSame($eventId, captureEvent($event));
$this->assertSame($event->getId(), captureEvent($event));
}

public function testCaptureLastError()
Expand Down
31 changes: 22 additions & 9 deletions tests/Integration/TransactionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,12 @@ public function setupOnceDataProvider(): \Generator
null,
];

$event = Event::createEvent();
$event->setTransaction('/foo/bar');

yield [
$event,
true,
Event::createEvent(),
false,
null,
[],
'/foo/bar',
null,
];

yield [
Expand Down Expand Up @@ -101,17 +98,33 @@ public function setupOnceDataProvider(): \Generator

yield [
$event,
true,
false,
null,
[],
'/foo/bar',
];

yield [
Event::createEvent(),
true,
EventHint::fromArray([
'extra' => [
'transaction' => '/some/other',
],
]),
['PATH_INFO' => '/foo/bar'],
'/some/other',
];

yield [
Event::createEvent(),
false,
null,
[],
EventHint::fromArray([
'extra' => [
'transaction' => '/some/other',
],
]),
['PATH_INFO' => '/foo/bar'],
null,
];
}
Expand Down

0 comments on commit 9368b24

Please sign in to comment.