-
Notifications
You must be signed in to change notification settings - Fork 69
feat(agent): end transaction for laravel horizon #1123
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
Open
hahuja2
wants to merge
12
commits into
dev
Choose a base branch
from
laravel_horizon
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
de6f6cf
feat(agent): end transaction for laravel horizon
hahuja2 ed39176
chore(agent): change function location to inside of conditional
hahuja2 a858026
chore(tests): add integration tests for laravel horizon
hahuja2 3c1cf7e
chore(tests): update string
hahuja2 3244b68
chore(tests): update description
hahuja2 61a0d34
chore(tests): update string
hahuja2 e98209e
chore(tests): add skipif
hahuja2 c777c6f
chore(agent): add comment
hahuja2 c1712c5
chore(tests): update tests with EXPECT_REGEX
hahuja2 f049a15
chore(agent): change function name
hahuja2 d8e9adb
chore(agent): ensure transaction is always stopped when laravel horiz…
hahuja2 819903e
chore(agent): change verbosedebug to use NRL_FRAMEWORK logging subsystem
hahuja2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/integration/frameworks/laravel/mock_horizon_error_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Mock enough bits of Laravel framework to test the HorizonCommand */ | ||
|
||
namespace Laravel\Horizon\Console { | ||
class HorizonCommand { | ||
public function handle() { | ||
echo "Error handle function\n"; | ||
throw new \Error("Error occurred"); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/integration/frameworks/laravel/mock_horizon_exception_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Mock enough bits of Laravel framework to test the HorizonCommand */ | ||
|
||
namespace Laravel\Horizon\Console { | ||
class HorizonCommand { | ||
public function handle() { | ||
echo "Exception handle function\n"; | ||
throw new \Exception("Exception occurred"); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/integration/frameworks/laravel/mock_horizon_happy_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Mock enough bits of Laravel framework to test the HorizonCommand */ | ||
|
||
namespace Laravel\Horizon\Console { | ||
class HorizonCommand { | ||
public function handle() { | ||
echo "handle function\n"; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/integration/frameworks/laravel/mock_supervisor_error_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Mock enough bits of Laravel framework to test the SupervisorCommand */ | ||
|
||
namespace Laravel\Horizon\Console { | ||
class SupervisorCommand { | ||
public function handle() { | ||
echo "Error handle function\n"; | ||
throw new \Error("Error occurred"); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/integration/frameworks/laravel/mock_supervisor_exception_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Mock enough bits of Laravel framework to test the SupervisorCommand */ | ||
|
||
namespace Laravel\Horizon\Console { | ||
class SupervisorCommand { | ||
public function handle() { | ||
echo "Exception handle function\n"; | ||
throw new \Exception("Exception occurred"); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/integration/frameworks/laravel/mock_supervisor_happy_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Mock enough bits of Laravel framework to test the SupervisorCommand */ | ||
|
||
namespace Laravel\Horizon\Console { | ||
class SupervisorCommand { | ||
public function handle() { | ||
echo "handle function\n"; | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tests/integration/frameworks/laravel/test_horizon_error_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
Ensure that when HorizonCommand::handle is executed, the transaction is properly stopped. | ||
This test verifies this behavior by first making sure the transaction exists and the | ||
transaction trace is not empty. Then it calls the HorizonCommand::handle method and | ||
verifies that the transaction has been stopped by checking that there was no harvest received. | ||
It also verifies that no traced errors and no error events were recorded. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "8.0", "<")) { | ||
die("skip: PHP < 8.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
newrelic.framework = laravel | ||
*/ | ||
|
||
/*EXPECT_HARVEST | ||
no | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS | ||
null | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS | ||
null | ||
*/ | ||
|
||
require_once(__DIR__ . '/mock_horizon_error_path.php'); | ||
require_once(__DIR__.'/../../../include/integration.php'); | ||
|
||
use Laravel\Horizon\Console\HorizonCommand; | ||
use NewRelic\Integration\Transaction; | ||
|
||
function foobar() { | ||
echo "foobar\n"; | ||
} | ||
function get_txn() { | ||
return new Transaction; | ||
} | ||
|
||
newrelic_add_custom_tracer('foobar'); | ||
foobar(); | ||
|
||
$txn = get_txn(); | ||
foreach ($txn->getTrace()->findSegmentsByName('Custom/foobar') as $segment) { | ||
echo $segment->name; | ||
echo "\n"; | ||
} | ||
bduranleau-nr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$horizon = new HorizonCommand(); | ||
$horizon->handle(); | ||
foobar(); |
62 changes: 62 additions & 0 deletions
62
tests/integration/frameworks/laravel/test_horizon_exception_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
Ensure that when HorizonCommand::handle is executed, the transaction is properly stopped. | ||
This test verifies this behavior by first making sure the transaction exists and the | ||
transaction trace is not empty. Then it calls the HorizonCommand::handle method and | ||
verifies that the transaction has been stopped by checking that there was no harvest received. | ||
It also verifies that no traced errors and no error events were recorded. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "8.0", "<")) { | ||
die("skip: PHP < 8.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
newrelic.framework = laravel | ||
*/ | ||
|
||
/*EXPECT_HARVEST | ||
no | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS | ||
null | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS | ||
null | ||
*/ | ||
|
||
require_once(__DIR__ . '/mock_horizon_exception_path.php'); | ||
require_once(__DIR__.'/../../../include/integration.php'); | ||
|
||
use Laravel\Horizon\Console\HorizonCommand; | ||
use NewRelic\Integration\Transaction; | ||
|
||
function foobar() { | ||
echo "foobar\n"; | ||
} | ||
function get_txn() { | ||
return new Transaction; | ||
} | ||
|
||
newrelic_add_custom_tracer('foobar'); | ||
foobar(); | ||
|
||
$txn = get_txn(); | ||
foreach ($txn->getTrace()->findSegmentsByName('Custom/foobar') as $segment) { | ||
echo $segment->name; | ||
echo "\n"; | ||
} | ||
|
||
$horizon = new HorizonCommand(); | ||
$horizon->handle(); | ||
foobar(); |
60 changes: 60 additions & 0 deletions
60
tests/integration/frameworks/laravel/test_horizon_happy_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
Ensure that when HorizonCommand::handle is executed, the transaction is properly stopped. | ||
This test verifies this behavior by first making sure the transaction exists and the | ||
transaction trace is not empty. Then it calls the HorizonCommand::handle method and | ||
verifies that the transaction has been stopped by checking that there was no harvest received. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "8.0", "<")) { | ||
die("skip: PHP < 8.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
newrelic.framework = laravel | ||
*/ | ||
|
||
/*EXPECT_HARVEST | ||
no | ||
*/ | ||
|
||
/*EXPECT | ||
foobar | ||
Custom/foobar | ||
handle function | ||
foobar | ||
*/ | ||
|
||
require_once(__DIR__ . '/mock_horizon_happy_path.php'); | ||
require_once(__DIR__.'/../../../include/integration.php'); | ||
|
||
use Laravel\Horizon\Console\HorizonCommand; | ||
use NewRelic\Integration\Transaction; | ||
|
||
function foobar() { | ||
echo "foobar\n"; | ||
} | ||
function get_txn() { | ||
return new Transaction; | ||
} | ||
|
||
newrelic_add_custom_tracer('foobar'); | ||
foobar(); | ||
|
||
$txn = get_txn(); | ||
foreach ($txn->getTrace()->findSegmentsByName('Custom/foobar') as $segment) { | ||
echo $segment->name; | ||
echo "\n"; | ||
} | ||
|
||
$horizon = new HorizonCommand(); | ||
$horizon->handle(); | ||
foobar(); |
62 changes: 62 additions & 0 deletions
62
tests/integration/frameworks/laravel/test_supervisor_error_path.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
Ensure that when SupervisorCommand::handle is executed, the transaction is properly stopped. | ||
This test verifies this behavior by first making sure the transaction exists and the | ||
transaction trace is not empty. Then it calls the SupervisorCommand::handle method and | ||
verifies that the transaction has been stopped by checking that there was no harvest received. | ||
It also verifies that no traced errors and no error events were recorded. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "8.0", "<")) { | ||
die("skip: PHP < 8.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
newrelic.framework = laravel | ||
*/ | ||
|
||
/*EXPECT_HARVEST | ||
no | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS | ||
null | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS | ||
null | ||
*/ | ||
|
||
require_once(__DIR__ . '/mock_supervisor_error_path.php'); | ||
require_once(__DIR__.'/../../../include/integration.php'); | ||
|
||
use Laravel\Horizon\Console\SupervisorCommand; | ||
use NewRelic\Integration\Transaction; | ||
|
||
function foobar() { | ||
echo "foobar\n"; | ||
} | ||
function get_txn() { | ||
return new Transaction; | ||
} | ||
|
||
newrelic_add_custom_tracer('foobar'); | ||
foobar(); | ||
|
||
$txn = get_txn(); | ||
foreach ($txn->getTrace()->findSegmentsByName('Custom/foobar') as $segment) { | ||
echo $segment->name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This output should be captured in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added: c1712c5 |
||
echo "\n"; | ||
} | ||
|
||
$supervisor = new SupervisorCommand(); | ||
$supervisor->handle(); | ||
foobar(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a name like
nr_laravel_horizon_end_txn
to be more clear what this function does.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, updated the name: f049a15