Skip to content

Commit

Permalink
Merge pull request #596 from rollbar/next/4.0/main
Browse files Browse the repository at this point in the history
4.0.0-beta
  • Loading branch information
danielmorell authored Jan 18, 2023
2 parents 4897fa2 + c5fd934 commit 117e4c2
Show file tree
Hide file tree
Showing 92 changed files with 2,728 additions and 1,702 deletions.
54 changes: 54 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [4.0.0-beta]
### Added
* PHP 8 language level mitigations, add typehints by @Chris8934 in #569.
* Added support for `psr/log` v3 by @danielmorell in #577.
* Added comments and type annotations to the `EncodedPayload` class and payload
interfaces by @danielmorell in #581.
* Added typing / comments to `Rollbar` and `RollbarLogger` classes by
@danielmorell in #585.
* Added required public methods to the `DataBuilderInterface` by @danielmorell
in #586.
* Added typing / comments to the `ResponseHandlerInterface` by @danielmorell in
#588.
* Added typing / comments to the `ScrubberInterface` and `Scrubber` class by
@danielmorell in #591.
* Added typing / comments to the `FilterInterface` by @danielmorell in #587.
* Added typing / comments to the `SenderInterface` by @danielmorell in #592.
### Changed
* Renamed `IStrategy` to `StrategyInterface` updated `Truncation` and changed
custom truncation strategy from requiring class extend the `AbstractStrategy`
to now require it implement `StrategyInterface` by @danielmorell in #580.
* Replaced the `FilterInterface::shouldSend()` `$accessΤoken` argument with
`$isUncaught` making it close to `check_ignore` usage @danielmorell in #587.
### Removed
* Removed deprecated log levels and fixed inconsistent use of
`Rollbar/LevelFactory` by @danielmorell in #578.
* Removed previously deprecated reporting methods from `Rollbar` by @danielmorell
in #579.
* Removed the `null` return type from `TransformerInterface::getPayload()`
by @danielmorell in #593.
### Fixed
* Fixed call of method name changed in 8fac418 by @danielmorell in #583.
* Fixed #461 Added support for `psr/log` context exception by @danielmorell in
#582.
* Fixed #469 Added `requireAccessToken()` method to `SenderInterface` by
@danielmorell in #595.

## [3.1.4] - 2022-11-18
This version adds a catch during the serialization process to stop serializaiton
errors from causing reports not to be sent to rollbar.
### Added
* Error catching error during serialization by @stephpy in #576

## [3.1.3] - 2022-05-23
This release patches several bugs.
### Added
* Added Safer `parse_str()` usage by @tanakahisateru in #566
### Fixed
* Fixed comment line number in tests by @matt-h in #563
* Fixed rollbar/rollbar-php-laravel#136 try using `__serialize` when obj
implements `\Serializable` by @pcoutinho in #567.
* Fixed error suppressor context detection for PHP 8 by @tanakahisateru in #565
* Fixed #571 added `null` check on `$filename` by @danielmorell in #572
* Fixed bug in tests on local machine (mac m1) by @Chris53897 in #568

## [3.1.2] - 2022-03-30
This release is a patch to fix a regression in functionality that was introduced
in v3.0.0.
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ From the Settings > Project Access Token menu, click Create New Access Token.
Copy the `post_client_item` value and paste it into the code below.

```php
require 'vendor/autoload.php'; // composer require rollbar/rollbar:^2
require 'vendor/autoload.php'; // composer require rollbar/rollbar

\Rollbar\Rollbar::init(
[ 'access_token' => '***', 'environment' => 'development' ]
);
\Rollbar\Rollbar::init([
'access_token' => '***',
'environment' => 'development',
]);
```

For detailed usage instructions and configuration reference, refer to our
Expand All @@ -63,7 +64,7 @@ For detailed usage instructions and configuration reference, refer to our

Major releases of this library support major versions of PHP, as follows:

* For PHP 8, choose the `master` branch.
* For PHP 8, choose the `4.x` or `3.x` branch.
* For PHP 7, choose a `2.x` release.
* For PHP 5, choose a `1.x` release.

Expand All @@ -72,7 +73,9 @@ composer:

```sh
# for PHP 8 compatibility
$ composer require rollbar/rollbar:dev-master
$ composer require rollbar/rollbar:^4
# or
$ composer require rollbar/rollbar:^3

# for PHP 7 compatibility
$ composer require rollbar/rollbar:^2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"require": {
"php": ">=8.0.0 <9.0",
"ext-curl": "*",
"psr/log": "^1 || ^2",
"psr/log": "^1 || ^2 || ^3",
"monolog/monolog": "^2"
},

Expand Down
110 changes: 67 additions & 43 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Rollbar\TransformerInterface;
use Rollbar\UtilitiesTrait;
use Throwable;
use Rollbar\ResponseHandlerInterface;
use Rollbar\Senders\FluentSender;
use Rollbar\FilterInterface;

class Config
{
Expand Down Expand Up @@ -140,11 +143,6 @@ class Config
private $dataBuilder;
private $configArray;

/**
* @var LevelFactory
*/
private $levelFactory;

/**
* @var TransformerInterface
*/
Expand Down Expand Up @@ -195,6 +193,10 @@ class Config
private $mtRandmax;

private $includedErrno;

/**
* @var bool Sets whether to respect current {@see error_reporting()} level or not.
*/
private bool $useErrorReporting = false;

/**
Expand All @@ -204,11 +206,15 @@ class Config
private bool $sendMessageTrace = false;

/**
* @var string (fully qualified class name) The name of the your custom
* truncation strategy class. The class should inherit from
* Rollbar\Truncation\AbstractStrategy.
* The fully qualified class name of a custom truncation strategy class or null if no custom class is specified.
* The class should implement {@see \Rollbar\Truncation\StrategyInterface}.
*
* @var string|null $customTruncation
*
* @since 1.6.0
* @since 4.0.0 Added string|null type, and defaults to null.
*/
private $customTruncation;
private ?string $customTruncation = null;

/**
* @var boolean Should the SDK raise an exception after logging an error.
Expand All @@ -227,8 +233,6 @@ public function __construct(array $configArray)
{
$this->includedErrno = Defaults::get()->includedErrno();

$this->levelFactory = new LevelFactory();

$this->updateConfig($configArray);

$this->errorSampleRates = Defaults::get()->errorSampleRates();
Expand Down Expand Up @@ -287,13 +291,14 @@ protected function updateConfig(array $config): void
$this->setLogPayloadLogger($config);
$this->setVerbose($config);
$this->setVerboseLogger($config);
// The sender must be set before the access token, so we know if it is required.
$this->setSender($config);
$this->setAccessToken($config);
$this->setDataBuilder($config);
$this->setTransformer($config);
$this->setMinimumLevel($config);
$this->setReportSuppressed($config);
$this->setFilters($config);
$this->setSender($config);
$this->setScrubber($config);
$this->setBatched($config);
$this->setBatchSize($config);
Expand Down Expand Up @@ -333,8 +338,14 @@ private function setAccessToken(array $config): void
if (isset($_ENV['ROLLBAR_ACCESS_TOKEN']) && !isset($config['access_token'])) {
$config['access_token'] = $_ENV['ROLLBAR_ACCESS_TOKEN'];
}
$this->utilities()->validateString($config['access_token'], "config['access_token']", 32, false);
$this->accessToken = $config['access_token'];

$this->utilities()->validateString(
$config['access_token'],
"config['access_token']",
32,
!$this->sender->requireAccessToken(),
);
$this->accessToken = $config['access_token'] ?? '';
}

private function setEnabled(array $config): void
Expand Down Expand Up @@ -402,10 +413,6 @@ public function disable(): void

private function setDataBuilder(array $config): void
{
if (!isset($config['levelFactory'])) {
$config['levelFactory'] = $this->levelFactory;
}

if (!isset($config['utilities'])) {
$config['utilities'] = $this->utilities();
}
Expand All @@ -425,13 +432,13 @@ private function setMinimumLevel(array $config): void
{
$this->minimumLevel = \Rollbar\Defaults::get()->minimumLevel();

$override = array_key_exists('minimum_level', $config) ? $config['minimum_level'] : null;
$override = $config['minimum_level'] ?? null;
$override = array_key_exists('minimumLevel', $config) ? $config['minimumLevel'] : $override;

if ($override instanceof Level) {
$this->minimumLevel = $override->toInt();
} elseif (is_string($override)) {
$level = $this->levelFactory->fromName($override);
$level = LevelFactory::fromName($override);
if ($level !== null) {
$this->minimumLevel = $level->toInt();
}
Expand All @@ -454,7 +461,7 @@ private function setReportSuppressed(array $config): void

private function setFilters(array $config): void
{
$this->setupWithOptions($config, "filter", "Rollbar\FilterInterface");
$this->setupWithOptions($config, "filter", FilterInterface::class);
}

private function setSender(array $config): void
Expand Down Expand Up @@ -554,12 +561,29 @@ public function getAllowedCircularReferenceTypes()
return $this->allowedCircularReferenceTypes;
}

public function setCustomTruncation($type)
/**
* Sets the custom truncation strategy class for payloads.
*
* @param string|null $type The fully qualified class name of the custom payload truncation strategy. The class
* must implement {@see \Rollbar\Truncation\StrategyInterface}. If null is given any custom
* strategy will be removed.
*
* @return void
*/
public function setCustomTruncation(?string $type): void
{
$this->customTruncation = $type;
}

public function getCustomTruncation()
/**
* Returns the fully qualified class name of the custom payload truncation strategy.
*
* @return string|null Will return null if a custom truncation strategy was not defined.
*
* @since 1.6.0
* @since 4.0.0 Added may return null.
*/
public function getCustomTruncation(): ?string
{
return $this->customTruncation;
}
Expand Down Expand Up @@ -606,7 +630,7 @@ private function setFluentSenderOptions(array &$config, mixed $default): mixed
if (!isset($config['handler']) || $config['handler'] != 'fluent') {
return $default;
}
$default = "Rollbar\Senders\FluentSender";
$default = FluentSender::class;

if (isset($config['fluent_host'])) {
$config['senderOptions']['fluentHost'] = $config['fluent_host'];
Expand All @@ -625,7 +649,7 @@ private function setFluentSenderOptions(array &$config, mixed $default): mixed

private function setResponseHandler(array $config): void
{
$this->setupWithOptions($config, "responseHandler", "Rollbar\ResponseHandlerInterface");
$this->setupWithOptions($config, "responseHandler", ResponseHandlerInterface::class);
}

private function setCheckIgnoreFunction(array $config): void
Expand Down Expand Up @@ -694,9 +718,7 @@ protected function setupWithOptions(
if ($passWholeConfig) {
$options = $config;
} else {
$options = isset($config[$keyName . "Options"]) ?
$config[$keyName . "Options"] :
array();
$options = $config[$keyName . "Options"] ?? array();
}
$this->$keyName = new $class($options);
} else {
Expand All @@ -710,7 +732,12 @@ protected function setupWithOptions(
}
}

public function logPayloadLogger()
/**
* Returns the logger responsible for logging request payload and response dumps, if enabled.
*
* @return LoggerInterface
*/
public function logPayloadLogger(): LoggerInterface
{
return $this->logPayloadLogger;
}
Expand All @@ -730,11 +757,6 @@ public function getDataBuilder()
return $this->dataBuilder;
}

public function getLevelFactory()
{
return $this->levelFactory;
}

public function getSender()
{
return $this->sender;
Expand Down Expand Up @@ -780,7 +802,7 @@ public function transform(
Level|string $level,
mixed $toLog,
array $context = array ()
): ?Payload {
): Payload {
if (count($this->custom) > 0) {
$this->verboseLogger()->debug("Adding custom data to the payload.");
$data = $payload->getData();
Expand Down Expand Up @@ -818,7 +840,8 @@ public function getSendMessageTrace()
return $this->sendMessageTrace;
}

public function checkIgnored($payload, string $accessToken, $toLog, bool $isUncaught)

public function checkIgnored(Payload $payload, $toLog, bool $isUncaught)
{
if (isset($this->checkIgnore)) {
try {
Expand All @@ -841,7 +864,7 @@ public function checkIgnored($payload, string $accessToken, $toLog, bool $isUnca
}

if (!is_null($this->filter)) {
$filter = $this->filter->shouldSend($payload, $accessToken);
$filter = $this->filter->shouldSend($payload, $isUncaught);
$this->verboseLogger()->debug("Custom filter result: " . var_export($filter, true));
return $filter;
}
Expand All @@ -856,7 +879,7 @@ public function internalCheckIgnored(string $level, mixed $toLog): bool
return true;
}

if ($this->levelTooLow($this->levelFactory->fromName($level))) {
if ($this->levelTooLow(LevelFactory::fromName($level))) {
$this->verboseLogger()->debug("Occurrence's level is too low");
return true;
}
Expand All @@ -873,10 +896,10 @@ public function internalCheckIgnored(string $level, mixed $toLog): bool
}

/**
* Check if the error should be ignored due to `included_errno` config,
* `use_error_reporting` config or `error_sample_rates` config.
* Check if the error should be ignored due to `includedErrno` config, `useErrorReporting` config or
* `errorSampleRates` config.
*
* @param errno
* @param int $errno The PHP error level bitmask.
*
* @return bool
*/
Expand Down Expand Up @@ -1047,7 +1070,8 @@ public function send(EncodedPayload $payload, string $accessToken): ?Response
public function sendBatch(array $batch, string $accessToken): ?Response
{
if ($this->transmitting()) {
return $this->sender->sendBatch($batch, $accessToken);
$this->sender->sendBatch($batch, $accessToken);
return null;
} else {
$response = new Response(0, "Not transmitting (transmitting disabled in configuration)");
$this->verboseLogger()->warning($response->getInfo());
Expand All @@ -1061,7 +1085,7 @@ public function wait(string $accessToken, $max = 0): void
$this->sender->wait($accessToken, $max);
}

public function handleResponse(Payload $payload, mixed $response): void
public function handleResponse(Payload $payload, Response $response): void
{
if (!is_null($this->responseHandler)) {
$this->verboseLogger()->debug(
Expand Down
Loading

0 comments on commit 117e4c2

Please sign in to comment.