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

Expose new ScoutApmAgent endpoint to start a new request #148

Merged
merged 2 commits into from
Dec 18, 2019
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## Pending - [2.1.2]
## Pending - [3.0.0]

- [BC] Added new method `Scoutapm\ScoutApmAgent::startNewRequest` (#148)
- implementors of `Scoutapm\ScoutApmAgent` will now need to implement this new method

## [2.1.1] 2019-12-17

Expand Down
10 changes: 8 additions & 2 deletions src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function __construct(
$this->warnIfConfigValueIsNotSet(ConfigKey::APPLICATION_KEY);
}

$this->request = new Request();
$this->startNewRequest();

$this->ignoredEndpoints = new IgnoredEndpoints($configuration->get(ConfigKey::IGNORED_ENDPOINTS));
}
Expand Down Expand Up @@ -339,7 +339,7 @@ public function send() : bool
$this->connector->sendCommand($this->request)
));

$this->request = new Request();
$this->startNewRequest();

return true;
} catch (NotConnected $notConnected) {
Expand All @@ -353,6 +353,12 @@ public function send() : bool
}
}

/** {@inheritDoc} */
public function startNewRequest() : void
{
$this->request = new Request();
}

private function registerIfRequired() : void
{
if ($this->registered) {
Expand Down
5 changes: 5 additions & 0 deletions src/ScoutApmAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public function changeRequestUri(string $newRequestUri) : void;
*/
public function send() : bool;

/**
* Clears any currently recorded request data/spans, and start a new request.
*/
public function startNewRequest() : void;

/**
* You probably don't need this, it's useful in testing
*
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/AgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,19 @@ public function testRegisterEventIsOnlySentOnceWhenSendingTwoRequestsWithSameAge
$agent->send();
$agent->send();
}

public function testRequestIsResetAfterStartingANewRequest() : void
{
$agent = $this->agentFromConfigArray([
ConfigKey::APPLICATION_NAME => 'My test app',
ConfigKey::APPLICATION_KEY => uniqid('applicationKey', true),
ConfigKey::MONITORING_ENABLED => true,
]);

$requestBeforeReset = $agent->getRequest();

$agent->startNewRequest();

self::assertNotSame($requestBeforeReset, $agent->getRequest());
}
}