Skip to content

Commit

Permalink
Merge branch 'release/2.1.2' into develop
Browse files Browse the repository at this point in the history
* release/2.1.2:
  meta: Update changelog
  meta: Changelog 2.1.2
  Skip integrations not bound to the current client and fetch their options from it (#861)
  Do not set the transaction attribute of the event when in CLI (#864)
  Added OXID eShop to the list of 3rd party integrations (#860)
  Fix error thrown when function name is missing in the stacktrace frame (#823)
  Fix sending of GZIP-compressed requests when the enable_compression option is on (#857)

# Conflicts:
#	CHANGELOG.md
#	tests/ClientBuilderTest.php
  • Loading branch information
HazAT committed Aug 22, 2019
2 parents 5dfc0ed + 646f6ad commit fe688d9
Show file tree
Hide file tree
Showing 22 changed files with 281 additions and 93 deletions.
1 change: 0 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ cache:

init:
- SET PATH=c:\php\%PHP_VERSION%;%PATH%
- SET SYMFONY_DEPRECATIONS_HELPER=strict
- SET ANSICON=121x90 (121x90)
- SET INSTALL_PHP=1

Expand Down
17 changes: 12 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

## Unreleased

- Fix `TypeError` in `Sentry\Monolog\Handler` when the extra data array has numeric keys (#833).
- Changed type hint for both parameter and return value of `HubInterface::getCurrentHub` and `HubInterface::setCurrentHub()` methods (#849)
- Add the `setTags`, `setExtras` and `clearBreadcrumbs` methods to the `Scope` class (#852)
- Silently cast numeric values to strings when trying to set the tags instead of throwing (#858)
- Support force sending events on-demand and fix sending of events in long-running processes (#813)

## 2.1.2 (2019-08-22)

- Fix `TypeError` in `Sentry\Monolog\Handler` when the extra data array has numeric keys (#833).
- Fix sending of GZIP-compressed requests when the `enable_compression` option is `true` (#857)
- Fix error thrown when trying to set the `transaction` attribute of the event in a CLI environment (#862)
- Fix integrations that were not skipped if the client bound to the current hub was not using them (#861)
- Fix undefined index generated by missing function in class (#823)

## 2.1.1 (2019-06-13)

- Fix the behavior of the `excluded_exceptions` option: now it's used to skip capture of exceptions, not to purge the
`exception` data of the event, which resulted in broken or empty chains of exceptions in reported events (#822)
- Fix the behavior of the `excluded_exceptions` option: now it's used to skip capture of exceptions, not to purge the
`exception` data of the event, which resulted in broken or empty chains of exceptions in reported events (#822)
- Fix handling of uploaded files in the `RequestIntegration`, to respect the PSR-7 spec fully (#827)
- Fix use of `REMOTE_ADDR` server variable rather than HTTP header
- Fix exception, open_basedir restriction in effect (#824)
Expand All @@ -37,7 +44,7 @@

## 2.0.0 (2019-02-25)

**Version 2.0.0 is a complete rewrite of the existing SDK. Code Changes are needed. Please see [UPGRADE 2.0](https://github.com/getsentry/sentry-php/blob/master/UPGRADE-2.0.md) for more details.**
**Version 2.0.0 is a complete rewrite of the existing SDK. Code Changes are needed. Please see [UPGRADE 2.0](https://github.com/getsentry/sentry-php/blob/master/UPGRADE-2.0.md) for more details.**

- Updated .gitattributes to reduce package footprint (#770)
- Use multibyte functions to handle unicode paths (#774)
Expand All @@ -54,7 +61,7 @@
- Lower the default `send_attempts` to 3 (#760)
- Fix method argument name handling when Xdebug is enabled (#763)
- Add CI build under Windows with AppVeyor (#758) and fix some bugs
- Change the `ErrorHandler` and default integrations behavior: the handler is now a singleton,
- Change the `ErrorHandler` and default integrations behavior: the handler is now a singleton,
and it's possible to attach a number of callables as listeners for errors and exceptions (#762)
- The `context_lines` options changed the default to `5` and is properly applied (#743)
- Add support for "formatted messages" in `captureEvent` as payload (#752)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The following integrations are available and maintained by members of the Sentry
- [Drupal](https://www.drupal.org/project/raven)
- [OpenCart](https://github.com/BurdaPraha/oc_sentry)
- [TYPO3](https://github.com/networkteam/sentry_client)
- [OXID eShop](https://github.com/OXIDprojects/sentry)
- ... feel free to be famous, create a port to your favourite platform!

## Community
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"phpstan/phpstan-phpunit": "^0.10",
"phpstan/phpstan": "^0.10.3",
"phpunit/phpunit": "^7.0",
"symfony/phpunit-bridge": "^4.1.6"
"symfony/phpunit-bridge": "^4.3"
},
"conflict": {
"php-http/client-common": "1.8.0",
Expand Down
13 changes: 8 additions & 5 deletions src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Http\Message\UriFactory;
use Jean85\PrettyVersions;
use Sentry\HttpClient\Authentication\SentryAuthentication;
use Sentry\HttpClient\Plugin\GzipEncoderPlugin;
use Sentry\Integration\ErrorListenerIntegration;
use Sentry\Integration\ExceptionListenerIntegration;
use Sentry\Integration\FatalErrorListenerIntegration;
Expand Down Expand Up @@ -103,9 +104,9 @@ public function __construct(Options $options = null)
if ($this->options->hasDefaultIntegrations()) {
$this->options->setIntegrations(array_merge([
new ExceptionListenerIntegration(),
new ErrorListenerIntegration($this->options, false),
new FatalErrorListenerIntegration($this->options),
new RequestIntegration($this->options),
new ErrorListenerIntegration(null, false),
new FatalErrorListenerIntegration(),
new RequestIntegration(),
], $this->options->getIntegrations()));
}
}
Expand Down Expand Up @@ -291,13 +292,15 @@ private function createHttpClientInstance(): PluginClient

$this->addHttpClientPlugin(new HeaderSetPlugin(['User-Agent' => $this->sdkIdentifier . '/' . $this->getSdkVersion()]));
$this->addHttpClientPlugin(new AuthenticationPlugin(new SentryAuthentication($this->options, $this->sdkIdentifier, $this->getSdkVersion())));
$this->addHttpClientPlugin(new RetryPlugin(['retries' => $this->options->getSendAttempts()]));
$this->addHttpClientPlugin(new ErrorPlugin());

if ($this->options->isCompressionEnabled()) {
$this->addHttpClientPlugin(new GzipEncoderPlugin());
$this->addHttpClientPlugin(new DecoderPlugin());
}

$this->addHttpClientPlugin(new RetryPlugin(['retries' => $this->options->getSendAttempts()]));
$this->addHttpClientPlugin(new ErrorPlugin());

return new PluginClient($this->httpClient, $this->httpClientPlugins);
}

Expand Down
10 changes: 2 additions & 8 deletions src/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Sentry\Exception\EventCreationException;
use Sentry\Serializer\RepresentationSerializerInterface;
use Sentry\Serializer\SerializerInterface;
use Zend\Diactoros\ServerRequestFactory;

/**
* Factory for the {@see Event} class.
Expand Down Expand Up @@ -93,13 +92,8 @@ public function create(array $payload): Event

if (isset($payload['transaction'])) {
$event->setTransaction($payload['transaction']);
} else {
$request = ServerRequestFactory::fromGlobals();
$serverParams = $request->getServerParams();

if (isset($serverParams['PATH_INFO'])) {
$event->setTransaction($serverParams['PATH_INFO']);
}
} elseif (isset($_SERVER['PATH_INFO'])) {
$event->setTransaction($_SERVER['PATH_INFO']);
}

if (isset($payload['logger'])) {
Expand Down
47 changes: 47 additions & 0 deletions src/HttpClient/Plugin/GzipEncoderPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Sentry\HttpClient\Plugin;

use Http\Client\Common\Plugin as PluginInterface;
use Http\Message\Encoding\GzipEncodeStream;
use Http\Promise\Promise as PromiseInterface;
use Psr\Http\Message\RequestInterface;

/**
* This plugin encodes the request body by compressing it with Gzip.
*
* @author Stefano Arlandini <sarlandini@alice.it>
*/
final class GzipEncoderPlugin implements PluginInterface
{
/**
* Constructor.
*
* @throws \RuntimeException If the zlib extension is not enabled
*/
public function __construct()
{
if (!\extension_loaded('zlib')) {
throw new \RuntimeException('The "zlib" extension must be enabled to use this plugin.');
}
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): PromiseInterface
{
$requestBody = $request->getBody();

if ($requestBody->isSeekable()) {
$requestBody->rewind();
}

$request = $request->withHeader('Content-Encoding', 'gzip');
$request = $request->withBody(new GzipEncodeStream($requestBody));

return $next($request);
}
}
34 changes: 25 additions & 9 deletions src/Integration/ErrorListenerIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
final class ErrorListenerIntegration implements IntegrationInterface
{
/**
* @var Options The options, to know which error level to use
* @var Options|null The options, to know which error level to use
*/
private $options;

Expand All @@ -29,17 +29,21 @@ final class ErrorListenerIntegration implements IntegrationInterface
/**
* Constructor.
*
* @param Options $options The options to be used with this integration
* @param bool $handleFatalErrors Whether to handle fatal errors or not
* @param Options|null $options The options to be used with this integration
* @param bool $handleFatalErrors Whether to handle fatal errors or not
*/
public function __construct(Options $options, bool $handleFatalErrors = true)
public function __construct(?Options $options = null, bool $handleFatalErrors = true)
{
$this->options = $options;
$this->handleFatalErrors = $handleFatalErrors;
if (null !== $options) {
@trigger_error(sprintf('Passing the options as argument of the constructor of the "%s" class is deprecated since version 2.1 and will not work in 3.0.', self::class), E_USER_DEPRECATED);
}

if ($handleFatalErrors) {
@trigger_error(sprintf('Handling fatal errors with the "%s" class is deprecated since version 2.1. Use the "%s" integration instead.', self::class, FatalErrorListenerIntegration::class), E_USER_DEPRECATED);
}

$this->options = $options;
$this->handleFatalErrors = $handleFatalErrors;
}

/**
Expand All @@ -53,15 +57,27 @@ public function setupOnce(): void
return;
}

if ($exception instanceof SilencedErrorException && !$this->options->shouldCaptureSilencedErrors()) {
$currentHub = Hub::getCurrent();
$integration = $currentHub->getIntegration(self::class);
$client = $currentHub->getClient();

// The client bound to the current hub, if any, could not have this
// integration enabled. If this is the case, bail out
if (null === $integration || null === $client) {
return;
}

$options = $this->options ?? $client->getOptions();

if ($exception instanceof SilencedErrorException && !$options->shouldCaptureSilencedErrors()) {
return;
}

if (!($this->options->getErrorTypes() & $exception->getSeverity())) {
if (!($options->getErrorTypes() & $exception->getSeverity())) {
return;
}

Hub::getCurrent()->captureException($exception);
$currentHub->captureException($exception);
});
}
}
11 changes: 10 additions & 1 deletion src/Integration/ExceptionListenerIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ public function setupOnce(): void
{
$errorHandler = ErrorHandler::registerOnce(ErrorHandler::DEFAULT_RESERVED_MEMORY_SIZE, false);
$errorHandler->addExceptionHandlerListener(static function (\Throwable $exception): void {
Hub::getCurrent()->captureException($exception);
$currentHub = Hub::getCurrent();
$integration = $currentHub->getIntegration(self::class);

// The client bound to the current hub, if any, could not have this
// integration enabled. If this is the case, bail out
if (null === $integration) {
return;
}

$currentHub->captureException($exception);
});
}
}
26 changes: 21 additions & 5 deletions src/Integration/FatalErrorListenerIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
final class FatalErrorListenerIntegration implements IntegrationInterface
{
/**
* @var Options The options, to know which error level to use
* @var Options|null The options, to know which error level to use
*/
private $options;

/**
* Constructor.
*
* @param Options $options The options to be used with this integration
* @param Options|null $options The options to be used with this integration
*/
public function __construct(Options $options)
public function __construct(?Options $options = null)
{
if (null !== $options) {
@trigger_error(sprintf('Passing the options as argument of the constructor of the "%s" class is deprecated since version 2.1 and will not work in 3.0.', self::class), E_USER_DEPRECATED);
}

$this->options = $options;
}

Expand All @@ -38,11 +42,23 @@ public function setupOnce(): void
{
$errorHandler = ErrorHandler::registerOnceFatalErrorHandler();
$errorHandler->addFatalErrorHandlerListener(function (FatalErrorException $exception): void {
if (!($this->options->getErrorTypes() & $exception->getSeverity())) {
$currentHub = Hub::getCurrent();
$integration = $currentHub->getIntegration(self::class);
$client = $currentHub->getClient();

// The client bound to the current hub, if any, could not have this
// integration enabled. If this is the case, bail out
if (null === $integration || null === $client) {
return;
}

$options = $this->options ?? $client->getOptions();

if (!($options->getErrorTypes() & $exception->getSeverity())) {
return;
}

Hub::getCurrent()->captureException($exception);
$currentHub->captureException($exception);
});
}
}
8 changes: 5 additions & 3 deletions src/Integration/ModulesIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ final class ModulesIntegration implements IntegrationInterface
public function setupOnce(): void
{
Scope::addGlobalEventProcessor(function (Event $event) {
$self = Hub::getCurrent()->getIntegration(self::class);
$integration = Hub::getCurrent()->getIntegration(self::class);

if ($self instanceof self) {
self::applyToEvent($self, $event);
// The integration could be bound to a client that is not the one
// attached to the current hub. If this is the case, bail out
if ($integration instanceof self) {
self::applyToEvent($integration, $event);
}

return $event;
Expand Down
Loading

0 comments on commit fe688d9

Please sign in to comment.