Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto on session tracking #517

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f9d9b38
AOST: Configuration changes
Cawllec Feb 5, 2019
4ec3855
AOST: Client reflection changes and tests
Cawllec Feb 5, 2019
7168505
AOST: Update Client guzzle creation and HTTP calls
Cawllec Feb 5, 2019
488c4fe
AOST: Update Client & HttpClient tests to new interface
Cawllec Feb 5, 2019
3c71e1e
Merge pull request #516 from bugsnag/master
Cawllec Feb 6, 2019
b8b2020
AOST: Update session tracker to check SessionsEnabled, added tests
Cawllec Feb 6, 2019
93b2d4c
Merge branch 'next' into aost/base-changes
Cawllec Feb 6, 2019
b3aa1b0
AOST: Improve tests
Cawllec Feb 6, 2019
45b401a
AOST: Add correct responses to storage calls
Cawllec Feb 6, 2019
fa0bcc8
AOST: Remove deprecated deploy function
Cawllec Feb 8, 2019
1a4f433
AOST: Update UPGRADING guide
Cawllec Feb 8, 2019
bcd2058
AOST: Remove deploy tests
Cawllec Feb 8, 2019
e2b6269
AOST: Add updating examples
Cawllec Feb 8, 2019
8b8b3cc
AOST: Add deploy->build example
Cawllec Feb 8, 2019
bde1c08
AOST: Make upgrading examples language more explicit
Cawllec Feb 11, 2019
ab3cc78
AOST: Close code block in upgrading
Cawllec Feb 11, 2019
7acfea6
AOST: Remove release changes
Cawllec Feb 12, 2019
4e8b739
AOST: Line formatting
Cawllec Feb 12, 2019
6fa5b16
AOST: Replace deploy in HTTPClient
Cawllec Feb 12, 2019
660abaa
AOST: Use correct exception class
Cawllec Feb 12, 2019
bccd728
AOST: Break SessionTracker changes into new PR
Cawllec Feb 12, 2019
9d466c0
AOST: Retain previous API
Cawllec Feb 12, 2019
27143e8
AOST: Return to original shouldCaptureSessions name
Cawllec Feb 12, 2019
00a6a88
AOST: Re-add original session methods
Cawllec Feb 12, 2019
e2898c1
AOST: Don't check sessionsEnabled if autoCaptureSessions is disabled
Cawllec Feb 12, 2019
8f5ab58
AOST: Make uri acquisition compatible with different guzzle versions
Cawllec Feb 13, 2019
c91f17d
AOST: Minor fixes
Cawllec Feb 13, 2019
9a7ca29
AOST: Add tests to cover original interface expectations
Cawllec Feb 13, 2019
d959d3e
AOST: Ensure method calls and docs are correct
Cawllec Feb 13, 2019
19ab537
AOST: Formatting
Cawllec Feb 13, 2019
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
68 changes: 66 additions & 2 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,78 @@
Upgrading
=========

## 3.x to 4.x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than bumping the major version why not support backwards compat?


#### Setting Endpoints

The way endpoints will be configured has been change slightly, in order to make sure all of your requests get send to the correct place. You'll no longer be able to pass the `endpoint` parameter to your `Bugsnag\Client::make` calls, and should instead use the [`setEndpoints` configuration option](https://docs.bugsnag.com/platforms/php/other/configuration-options/#endpoints). If you've previously used the `BUGSNAG_ENDPOINT` environment variable, it's now been renamed to `BUGSNAG_NOTIFY_ENDPOINT`, and will only work in conjunction with the `BUGSNAG_SESSION_ENDPOINT` environment variable, to make sure that both endpoints are being used correctly.
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
Cawllec marked this conversation as resolved.
Show resolved Hide resolved

Old way:

```
$bugsnag = Bugsnag\Client::make("YOUR_API_KEY", "http://bugsnag-notify.example.com);
$bugsnag->setSessionEndpoint("http://bugsnag-session.example.com);
```

New way:

```
$bugnsag = Bugsnag\Client::make("YOUR_API_KEY");
$bugsnag->setEndpoints(
"http://bugsnag-notify.example.com",
"http://bugsnag-session.example.com"
);
```

#### Configuring the GuzzleHttp Client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required for always on session tracking?


If you've previously customized the GuzzleHttp Client we use to deliver notifications, you'll no longer be able to pass it in to a `new Bugsnag\Client` call. Instead you'll need to add it to Bugsnag using the [`setGuzzleClient` configuration option.](https://docs.bugsnag.com/platforms/php/other/configuration-options/#guzzle-client)

Old way:

```
$bugsnag = new Bugsnag\Client(new Bugsnag\Configuration("YOUR_API_KEY"), null, $myCustomGuzzle);
```

New way:

```
$bugsnag = new Bugsnag\Client::make("YOUR_API_KEY");
$bugsnag->setGuzzleClient($myCustomGuzzle);
```

#### Deprecation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change required for always on session tracking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't, but should be removed if this is a major release. I've removed it as it'll be a part of a release PR instead.


The `deploy` method has been removed, so in order to report a new version build to bugsnag you should use the `build` method, [as described here.](https://docs.bugsnag.com/platforms/php/other/#tracking-releases)

Old way:

```
$bugsnag->deploy(
"https://github.com/owner/repo", // Your repository
"master", // The branch being deployed from, this has been removed from the build API
"52097f461bf76a824212eb11de53467c094d0cd4" // The revision, or commit hash, of the deployment
);
```

New way:

```
$bugsnag->build(
"https://github.com/owner/repo", // Your repository
"52097f461bf76a824212eb11de53467c094d0cd4", // The revision, or commit hash, of the build
"github", // The provider of the source control repository
"Joe Summer" // The name of the person or machine making the build
);
```

## 2.x to 3.x

*Our PHP library has gone through some major improvements, and there are some small changes you'll need to make to get onto the new version.*

#### PHP 5.5+

We now require PHP 5.5 or higher. If you're using an older version of PHP, you can still use v2. We will containue to maintain v2 along side v3. For more information, see the [legacy PHP integration guide](https://docs.bugsnag.com/platforms/php/other/legacy/).
We now require PHP 5.5 or higher. If you're using an older version of PHP, you can still use v2. We will continue to maintain v2 along side v3. For more information, see the [legacy PHP integration guide](https://docs.bugsnag.com/platforms/php/other/legacy/).

#### Namespaces

Expand All @@ -22,7 +86,7 @@ The method for setting the application type (`setType`) has also been removed in

#### Configuration

We've changed how our configuration system works. You can now build up our config object in a similar way to how you configured the client in v2, and then pass that as the first paramater when you construct the client object. In addition, we've removed some configuration options in favour of using our new notification pipeline system. Now you can register multiple callbacks to have maximum flexibility. We've also switched to using [Guzzle](http://guzzlephp.org), so you can change the base URI and proxy details by directly interacting with guzzle. For more information, see the [advanced configuration guide](https://docs.bugsnag.com/platforms/php/other/advanced-client-configuration).
We've changed how our configuration system works. You can now build up our config object in a similar way to how you configured the client in v2, and then pass that as the first parameter when you construct the client object. In addition, we've removed some configuration options in favour of using our new notification pipeline system. Now you can register multiple callbacks to have maximum flexibility. We've also switched to using [Guzzle](http://guzzlephp.org), so you can change the base URI and proxy details by directly interacting with guzzle. For more information, see the [advanced configuration guide](https://docs.bugsnag.com/platforms/php/other/advanced-client-configuration).

#### Customizing handled errors

Expand Down
134 changes: 65 additions & 69 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Bugsnag\Middleware\SessionData;
use Bugsnag\Request\BasicResolver;
use Bugsnag\Request\ResolverInterface;
use Composer\CaBundle\CaBundle;
use Bugsnag\Utils;
use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\ClientInterface;
use ReflectionClass;
Expand Down Expand Up @@ -80,18 +80,18 @@ class Client
* If you don't pass in a key, we'll try to read it from the env variables.
*
* @param string|null $apiKey your bugsnag api key
* @param string|null $endpoint your bugsnag endpoint
* @param bool $default if we should register our default callbacks
*
* @return static
*/
public static function make($apiKey = null, $endpoint = null, $defaults = true)
public static function make($apiKey = null, $defaults = true)
{
$config = new Configuration($apiKey ?: getenv('BUGSNAG_API_KEY'));
$guzzle = static::makeGuzzle($endpoint ?: getenv('BUGSNAG_ENDPOINT'));

$client = new static($config, null, $guzzle);
if (($notifyEndpoint = getenv('BUGSNAG_NOTIFY_ENDPOINT')) && ($sessionEndpoint = getenv('BUGSNAG_SESSION_ENDPOINT'))) {
$config->setEndpoints($notifyEndpoint, $sessionEndpoint);
}

$client = new static($config, null);
if ($defaults) {
$client->registerDefaultCallbacks();
}
Expand All @@ -104,17 +104,16 @@ public static function make($apiKey = null, $endpoint = null, $defaults = true)
*
* @param \Bugsnag\Configuration $config
* @param \Bugsnag\Request\ResolverInterface|null $resolver
* @param \GuzzleHttp\ClientInterface|null $guzzle
*
* @return void
*/
public function __construct(Configuration $config, ResolverInterface $resolver = null, ClientInterface $guzzle = null)
public function __construct(Configuration $config, ResolverInterface $resolver = null)
{
$this->config = $config;
$this->resolver = $resolver ?: new BasicResolver();
$this->recorder = new Recorder();
$this->pipeline = new Pipeline();
$this->http = new HttpClient($config, $guzzle ?: static::makeGuzzle());
$this->http = new HttpClient($config);
$this->sessionTracker = new SessionTracker($config);

$this->registerMiddleware(new NotificationSkipper($config));
Expand All @@ -124,40 +123,7 @@ public function __construct(Configuration $config, ResolverInterface $resolver =
register_shutdown_function([$this, 'flush']);
}

/**
* Make a new guzzle client instance.
*
* @param string|null $base
* @param array $options
*
* @return \GuzzleHttp\ClientInterface
*/
public static function makeGuzzle($base = null, array $options = [])
{
$key = version_compare(ClientInterface::VERSION, '6') === 1 ? 'base_uri' : 'base_url';

$options[$key] = $base ?: static::ENDPOINT;

if ($path = static::getCaBundlePath()) {
$options['verify'] = $path;
}

return new Guzzle($options);
}

/**
* Get the ca bundle path if one exists.
*
* @return string|false
*/
protected static function getCaBundlePath()
{
if (!class_exists(CaBundle::class)) {
return false;
}

return realpath(CaBundle::getSystemCaRootBundlePath());
}


/**
* Get the config instance.
Expand Down Expand Up @@ -326,22 +292,6 @@ public function notify(Report $report, callable $callback = null)
}
}

/**
* Notify Bugsnag of a deployment.
*
* @deprecated This function is being deprecated in favour of `build`.
*
* @param string|null $repository the repository from which you are deploying the code
* @param string|null $branch the source control branch from which you are deploying
* @param string|null $revision the source control revision you are currently deploying
*
* @return void
*/
public function deploy($repository = null, $branch = null, $revision = null)
{
$this->build($repository, $revision);
}

/**
* Notify Bugsnag of a build.
*
Expand Down Expand Up @@ -785,37 +735,83 @@ public function setAutoCaptureSessions($track)
}

/**
* Set session delivery endpoint.
* Sets the notify and session endpoints
*
* @param string $endpoint the session endpoint
* @param string $notifyEndpoint the notify endpoint
* @param string $sessionEndpoint the session endpoint
*
* @return $this
*/
public function setSessionEndpoint($endpoint)
public function setEndpoints($notifyEndpoint, $sessionEndpoint)
{
$this->config->setEndpoints($notifyEndpoint, $sessionEndpoint);

return $this;
}

/**
* Gets the notify endpoint
*
* @return string
*/
public function getNotifyEndpoint()
{
return $this->config->getNotifyEndpoint();
}

/**
* Gets the session endpoint
*
* @return string
*/
public function getSessionEndpoint()
{
$this->config->setSessionEndpoint($endpoint);
return $this->config->getSessionEndpoint();
}

/**
* Gets the current guzzle client.
*
* @return GuzzleHttp\ClientInterface
*/
public function getGuzzleClient()
{
return $this->config->getGuzzleClient();
}

/**
* Sets the guzzle client
*
* Delivery URLs should be set using the "setEndpoints" method
*
* @param GuzzleHttp\ClientInterface $guzzleClient the new guzzle client
*
* @return $this
*/
public function setGuzzleClient($guzzleClient)
{
$this->config->setGuzzleClient($guzzleClient);
return $this;
}

/**
* Get the session client.
* Whether any sessions are enabled.
*
* @return \Guzzle\ClientInterface
* @return bool
*/
public function getSessionClient()
public function sessionsEnabled()
{
return $this->config->getSessionClient();
return $this->config->sessionsEnabled();
}

/**
* Whether should be auto-capturing sessions.
*
* @return bool
*/
public function shouldCaptureSessions()
public function shouldAutoCaptureSessions()
{
return $this->config->shouldCaptureSessions();
return $this->config->shouldAutoCaptureSessions();
}

/**
Expand Down
Loading