|
8 | 8 | use Sentry\Client; |
9 | 9 | use Sentry\ClientReport\ClientReportAggregator; |
10 | 10 | use Sentry\ClientReport\Reason; |
| 11 | +use Sentry\Logs\LogLevel; |
| 12 | +use Sentry\Logs\LogsAggregator; |
11 | 13 | use Sentry\Options; |
12 | 14 | use Sentry\SentrySdk; |
| 15 | +use Sentry\State\Hub; |
13 | 16 | use Sentry\Tests\StubLogger; |
14 | 17 | use Sentry\Tests\StubTransport; |
15 | 18 | use Sentry\Transport\DataCategory; |
@@ -84,4 +87,50 @@ public function testZeroQuantityDiscarded(): void |
84 | 87 | $this->assertCount(1, StubLogger::$logs); |
85 | 88 | $this->assertSame(['level' => 'debug', 'message' => 'Dropping Client report with category={category} and reason={} because quantity is zero or negative ({quantity})', 'context' => ['category' => 'profile', 'reason' => 'event_processor', 'quantity' => 0]], StubLogger::$logs[0]); |
86 | 89 | } |
| 90 | + |
| 91 | + public function testNegativeQuantityDiscardedWhenNoClientIsBound(): void |
| 92 | + { |
| 93 | + SentrySdk::setCurrentHub(new Hub()); |
| 94 | + |
| 95 | + ClientReportAggregator::getInstance()->add(DataCategory::profile(), Reason::eventProcessor(), -10); |
| 96 | + |
| 97 | + SentrySdk::setCurrentHub(new Hub(new Client(new Options([ |
| 98 | + 'logger' => StubLogger::getInstance(), |
| 99 | + ]), StubTransport::getInstance()))); |
| 100 | + |
| 101 | + ClientReportAggregator::getInstance()->flush(); |
| 102 | + |
| 103 | + $this->assertEmpty(StubTransport::$events); |
| 104 | + $this->assertEmpty(StubLogger::$logs); |
| 105 | + } |
| 106 | + |
| 107 | + public function testLogCategoriesAreCanonical(): void |
| 108 | + { |
| 109 | + $this->assertSame('log_item', DataCategory::logItem()->getValue()); |
| 110 | + $this->assertSame('log_byte', DataCategory::logBytes()->getValue()); |
| 111 | + } |
| 112 | + |
| 113 | + public function testLogOverflowReportsLogItemCount(): void |
| 114 | + { |
| 115 | + SentrySdk::init()->bindClient(new Client(new Options([ |
| 116 | + 'enable_logs' => true, |
| 117 | + ]), StubTransport::getInstance())); |
| 118 | + |
| 119 | + $logsAggregator = new LogsAggregator(); |
| 120 | + |
| 121 | + for ($i = 0; $i < 8; ++$i) { |
| 122 | + $logsAggregator->add(LogLevel::info(), 'Log %d', [$i]); |
| 123 | + } |
| 124 | + |
| 125 | + ClientReportAggregator::getInstance()->flush(); |
| 126 | + |
| 127 | + $this->assertCount(1, StubTransport::$events); |
| 128 | + $reports = StubTransport::$events[0]->getClientReports(); |
| 129 | + $this->assertCount(1, $reports); |
| 130 | + |
| 131 | + $report = $reports[0]; |
| 132 | + $this->assertSame(DataCategory::logItem()->getValue(), $report->getCategory()); |
| 133 | + $this->assertSame(Reason::bufferOverflow()->getValue(), $report->getReason()); |
| 134 | + $this->assertSame(2, $report->getQuantity()); |
| 135 | + } |
87 | 136 | } |
0 commit comments