Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
16 changes: 16 additions & 0 deletions agent/fw_laravel_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,16 @@ NR_PHP_WRAPPER(nr_laravel_queue_queue_createpayload) {
}
NR_PHP_WRAPPER_END

NR_PHP_WRAPPER(nr_laravel_horizon_end) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

NR_UNUSED_SPECIALFN;
(void)wraprec;

nr_php_txn_end(1, 0 TSRMLS_CC);

nrl_verbosedebug(NRL_TXN, "Ending Laravel Horizon Transaction");
}
NR_PHP_WRAPPER_END

void nr_laravel_queue_enable(TSRMLS_D) {
/*
* Hook the command class that implements Laravel's queue:work command so
Expand Down Expand Up @@ -871,6 +881,12 @@ void nr_laravel_queue_enable(TSRMLS_D) {
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("Illuminate\\Queue\\SyncQueue::raiseAfterJobEvent"),
nr_laravel_queue_worker_raiseAfterJobEvent_before, NULL, NULL);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("Laravel\\Horizon\\Console\\HorizonCommand::handle"),
nr_laravel_horizon_end, NULL, NULL);
nr_php_wrap_user_function_before_after_clean(
NR_PSTR("Laravel\\Horizon\\Console\\SupervisorCommand::handle"),
nr_laravel_horizon_end, NULL, NULL);

#else

Expand Down
17 changes: 17 additions & 0 deletions tests/integration/frameworks/laravel/mock_horizon_error_path.php
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");
}
}
}
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 tests/integration/frameworks/laravel/mock_horizon_happy_path.php
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";
}
}
}
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");
}
}
}
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");
}
}
}
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 tests/integration/frameworks/laravel/test_horizon_error_path.php
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";
}

$horizon = new HorizonCommand();
$horizon->handle();
foobar();
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 tests/integration/frameworks/laravel/test_horizon_happy_path.php
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();
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

This output should be captured in an EXPECT statement of some sort as well as any other echo's - this is true for all tests in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added: c1712c5

echo "\n";
}

$supervisor = new SupervisorCommand();
$supervisor->handle();
foobar();
Loading