Skip to content

Commit

Permalink
fix: check if events are enabled when calling flushEvents (#194)
Browse files Browse the repository at this point in the history
* fix: check if events are enabled when calling flushEvents

* chore: update CHANGELOG.md
  • Loading branch information
subzero10 authored Jul 6, 2024
1 parent b0690ef commit e53c24d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [2.19.2] - 2024-07-06
### Fixed
- Events: Honeybadger.flushEvents() should check if events are enabled before sending to Honeybadger
### Changed
- Events: Register shutdown handler by default

## [2.19.1] - 2024-06-29
### Fixed
- Events: Allow Honeybadger.event() without event_type
Expand Down
4 changes: 3 additions & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ private function mergeConfig($config = []): array
], $config);

if (!isset($result['handlers']['shutdown'])) {
$result['handlers']['shutdown'] = false;
// the 'shutdown' field is new, array_merge only merges on the first level
// so we need to manually set it if the config has a 'handlers' key but not a 'shutdown' key inside
$result['handlers']['shutdown'] = true;
}

return $result;
Expand Down
6 changes: 5 additions & 1 deletion src/Honeybadger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Honeybadger implements Reporter
/**
* SDK Version.
*/
const VERSION = '2.19.1';
const VERSION = '2.19.2';

/**
* Honeybadger API URL.
Expand Down Expand Up @@ -249,6 +249,10 @@ public function event($eventTypeOrPayload, array $payload = null): void
*/
public function flushEvents(): void
{
if (!$this->config['events']['enabled']) {
return;
}

$this->events->flushEvents();
}

Expand Down
62 changes: 62 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,66 @@ public function it_merges_configuration_values()
],
], $config);
}

/** @test */
public function it_set_shutdown_handler_to_true_by_default()
{
$config = (new Config([
'api_key' => '1234',
'handlers' => [
'exception' => true,
'error' => true,
],
]))->all();

$this->assertArrayHasKey('service_exception_handler', $config);
unset($config['service_exception_handler']);

$this->assertEquals([
'api_key' => '1234',
'personal_auth_token' => null,
'endpoint' => Honeybadger::API_URL,
'notifier' => [
'name' => 'honeybadger-php',
'url' => 'https://github.com/honeybadger-io/honeybadger-php',
'version' => Honeybadger::VERSION,
],
'environment' => [
'filter' => [],
'include' => [],
],
'request' => [
'filter' => [],
],
'version' => '',
'hostname' => gethostname(),
'project_root' => '',
'environment_name' => 'production',
'handlers' => [
'exception' => true,
'error' => true,
'shutdown' => true,
],
'client' => [
'timeout' => 15,
'proxy' => [],
'verify' => true,
],
'excluded_exceptions' => [],
'capture_deprecations' => false,
'report_data' => true,
'vendor_paths' => [
'vendor\/.*',
],
'breadcrumbs' => [
'enabled' => true,
],
'checkins' => [],
'events' => [
'enabled' => false,
'bulk_threshold' => 50,
'dispatch_interval_seconds' => 2,
],
], $config);
}
}

0 comments on commit e53c24d

Please sign in to comment.