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
10 changes: 0 additions & 10 deletions src/Logs/LogsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ public function add(
$options = $client->getOptions();
$sdkLogger = $options->getLogger();

if (!$options->getEnableLogs()) {
if ($sdkLogger !== null) {
$sdkLogger->info(
'Log will be discarded because "enable_logs" is "false".'
);
}

return;
}

$formattedMessage = Str::vsprintfOrNull($message, $values);

if ($formattedMessage === null) {
Expand Down
4 changes: 0 additions & 4 deletions src/Metrics/MetricsAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ public function add(
$options = $client->getOptions();
$metricFlushThreshold = $options->getMetricFlushThreshold();

if ($options->getEnableMetrics() === false) {
return;
}

$defaultAttributes = [
'sentry.environment' => $options->getEnvironment() ?? Event::DEFAULT_ENVIRONMENT,
'server.address' => $options->getServerName(),
Expand Down
4 changes: 2 additions & 2 deletions src/Monolog/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* hub instance.
*
* @deprecated since version 4.24. To be removed in version 5.0. Use {@see LogsHandler}
* with the `enable_logs` SDK option for Sentry logs, {@see ExceptionToSentryIssueHandler}
* to send Monolog exceptions to Sentry issues, and {@see LogToSentryIssueHandler}
* for Sentry logs, {@see ExceptionToSentryIssueHandler} to send Monolog exceptions
* to Sentry issues, and {@see LogToSentryIssueHandler}
* to send Monolog log messages to Sentry issues.
*
* @author Stefano Arlandini <sarlandini@alice.it>
Expand Down
24 changes: 22 additions & 2 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ public function getEnableTracing(): ?bool
/**
* Sets if logs should be enabled or not.
*
* This option no longer gates the manual logging API or logging integrations.
* To implement a kill switch, use a `before_send_log` callback that returns `null`.
*
* @param bool|null $enableLogs Boolean if logs should be enabled or not
*
* @deprecated since version 4.31. To be removed in version 5.0
*/
public function setEnableLogs(?bool $enableLogs): self
{
Expand All @@ -160,6 +165,11 @@ public function setEnableLogs(?bool $enableLogs): self

/**
* Gets if logs is enabled or not.
*
* This option no longer gates the manual logging API or logging integrations.
* To implement a kill switch, use a `before_send_log` callback that returns `null`.
*
* @deprecated since version 4.31. To be removed in version 5.0
*/
public function getEnableLogs(): bool
{
Expand Down Expand Up @@ -212,14 +222,24 @@ public function setMetricFlushThreshold(?int $metricFlushThreshold): self

/**
* Sets if metrics should be enabled or not.
*
* This option no longer gates the manual metrics API or metrics integrations.
* To implement a kill switch, use a `before_send_metric` callback that returns `null`.
*
* @deprecated since version 4.31. To be removed in version 5.0
*/
public function setEnableMetrics(bool $enableTracing): self
public function setEnableMetrics(bool $enableMetrics): self
{
return $this->updateOptions(['enable_metrics' => $enableTracing]);
return $this->updateOptions(['enable_metrics' => $enableMetrics]);
}

/**
* Returns whether metrics are enabled or not.
*
* This option no longer gates the manual metrics API or metrics integrations.
* To implement a kill switch, use a `before_send_metric` callback that returns `null`.
*
* @deprecated since version 4.31. To be removed in version 5.0
*/
public function getEnableMetrics(): bool
{
Expand Down
20 changes: 4 additions & 16 deletions tests/Logs/LogsAggregatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ final class LogsAggregatorTest extends TestCase
*/
public function testAttributes(array $attributes, array $expected): void
{
$client = ClientBuilder::create([
'enable_logs' => true,
])->getClient();
$client = ClientBuilder::create()->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
Expand Down Expand Up @@ -89,9 +87,7 @@ public static function attributesDataProvider(): \Generator
*/
public function testMessageFormatting(string $message, array $values, string $expected): void
{
$client = ClientBuilder::create([
'enable_logs' => true,
])->getClient();
$client = ClientBuilder::create()->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
Expand Down Expand Up @@ -163,7 +159,6 @@ public static function messageFormattingDataProvider(): \Generator
public function testAttributesAreAddedToLogMessage(): void
{
$client = ClientBuilder::create([
'enable_logs' => true,
'send_default_pii' => true,
'release' => '1.0.0',
'environment' => 'production',
Expand Down Expand Up @@ -214,7 +209,6 @@ public function testAttributesAreAddedToLogMessage(): void
public function testUserAttributesCanBeSetManuallyWithDefaultPiiOff(): void
{
$client = ClientBuilder::create([
'enable_logs' => true,
'send_default_pii' => false,
])->getClient();

Expand Down Expand Up @@ -248,7 +242,6 @@ public function testFlushesImmediatelyWhenThresholdIsReached(): void

$transport = new StubTransport();
$client = ClientBuilder::create([
'enable_logs' => true,
'log_flush_threshold' => 2,
])->setTransport($transport)->getClient();

Expand Down Expand Up @@ -277,7 +270,6 @@ public function testDoesNotFlushImmediatelyWhenThresholdIsNull(): void

$transport = new StubTransport();
$client = ClientBuilder::create([
'enable_logs' => true,
'log_flush_threshold' => null,
])->setTransport($transport)->getClient();

Expand All @@ -295,9 +287,7 @@ public function testDoesNotFlushImmediatelyWhenThresholdIsNull(): void

public function testDoesNotUsePropagationContextSpanIdAsParentSpanIdWhenNoLocalSpanExists(): void
{
$client = ClientBuilder::create([
'enable_logs' => true,
])->getClient();
$client = ClientBuilder::create()->getClient();

$propagationContext = PropagationContext::fromDefaults();
$propagationContext->setTraceId(new TraceId('771a43a4192642f0b136d5159a501700'));
Expand All @@ -321,9 +311,7 @@ public function testDoesNotUsePropagationContextSpanIdAsParentSpanIdWhenNoLocalS

public function testUsesExternalPropagationContextWhenNoLocalSpanExists(): void
{
$client = ClientBuilder::create([
'enable_logs' => true,
])->getClient();
$client = ClientBuilder::create()->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
Expand Down
33 changes: 10 additions & 23 deletions tests/Logs/LogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Sentry\Event;
use Sentry\Logs\Log;
use Sentry\Logs\LogLevel;
use Sentry\Options;
use Sentry\SentrySdk;
use Sentry\State\Hub;
use Sentry\Transport\Result;
Expand All @@ -22,29 +21,21 @@

final class LogsTest extends TestCase
{
public function testLogNotSentWhenDisabled(): void
public function testLogSentWhenEnableLogsIsFalse(): void
{
/** @var ClientInterface&MockObject $client */
$client = $this->createMock(ClientInterface::class);
$client->expects($this->any())
->method('getOptions')
->willReturn(new Options([
'dsn' => 'https://public@example.com/1',
'enable_logs' => false,
]));

$client->expects($this->never())
->method('captureEvent');

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
$this->assertEvent(function (Event $event) {
$this->assertCount(1, $event->getLogs());
$this->assertSame('Some info message', $event->getLogs()[0]->getBody());
}, [
'enable_logs' => false,
]);

logger()->info('Some info message');

$this->assertNull(logger()->flush());
$this->assertNotNull(logger()->flush());
}

public function testLogSentWhenEnabled(): void
public function testLogSentWithoutEnableLogsOption(): void
{
$this->assertEvent(function (Event $event) {
$this->assertCount(1, $event->getLogs());
Expand Down Expand Up @@ -180,11 +171,7 @@ private function assertEvent(callable $assert, array $options = []): ClientInter
return new Result(ResultStatus::success(), $event);
});

$clientOptions = array_merge([
'enable_logs' => true,
], $options);

$client = ClientBuilder::create($clientOptions)->setTransport($transport)->getClient();
$client = ClientBuilder::create($options)->setTransport($transport)->getClient();

$hub = new Hub($client);
SentrySdk::setCurrentHub($hub);
Expand Down
6 changes: 4 additions & 2 deletions tests/Metrics/TraceMetricsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function testMetricsBufferFullWhenMetricFlushThresholdIsNull(): void
$this->assertCount(MetricsAggregator::METRICS_BUFFER_SIZE, $metrics);
}

public function testEnableMetrics(): void
public function testMetricSentWhenEnableMetricsIsFalse(): void
{
HubAdapter::getInstance()->bindClient(new Client(new Options([
'enable_metrics' => false,
Expand All @@ -138,7 +138,9 @@ public function testEnableMetrics(): void
traceMetrics()->count('test-count', 2, ['foo' => 'bar']);
traceMetrics()->flush();

$this->assertEmpty(StubTransport::$events);
$this->assertCount(1, StubTransport::$events);
$this->assertCount(1, StubTransport::$events[0]->getMetrics());
$this->assertSame('test-count', StubTransport::$events[0]->getMetrics()[0]->getName());
}

public function testBeforeSendMetricAltersContent(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Monolog/LogsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void
{
Logs::getInstance()->flush();
$client = ClientBuilder::create([
'enable_logs' => true,
'enable_logs' => false,
'before_send' => static function () {
return null; // we don't need to send the event, we are just testing the Monolog handler
},
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testLogsHandlerDestructor(): void
{
$transport = new StubTransport();
$client = ClientBuilder::create([
'enable_logs' => true,
'enable_logs' => false,
])->setTransport($transport)
->getClient();

Expand Down
Loading