Skip to content

Commit

Permalink
test: add regression tests for tt_detail off
Browse files Browse the repository at this point in the history
Split tt_detail_off_with_custom_wrapper into two tests that verify agent
wraps user functions correctly using API and configuration and that it
correctly sends span events for custom wrapped functions when tt_detail
is off.
  • Loading branch information
lavarou committed Jan 13, 2025
1 parent 9490d7b commit d17755a
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 11 deletions.
100 changes: 100 additions & 0 deletions tests/regression/test_tt_detail_off_with_custom_wrapper_api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/*DESCRIPTION
When transaction tracer details are disabled, test that only calls to custom wrapped functions appear as spans in span events after they have been wrapped using API.
*/

/*INI
newrelic.transaction_tracer.detail = 0
newrelic.special.expensive_node_min = 50us
*/

/*EXPECT
function_exceeding_tt_detail_threshold called
custom_function_not_exceeding_tt_detail_threshold called
function_exceeding_tt_detail_threshold called
custom_function_not_exceeding_tt_detail_threshold called
No alarms and no surprises.
*/

/*EXPECT_SPAN_EVENTS
[
"?? agent run id",
{
"reservoir_size": 10000,
"events_seen": 2
},
[
[
{
"category": "generic",
"type": "Span",
"guid": "??",
"traceId": "??",
"transactionId": "??",
"name": "OtherTransaction/php__FILE__",
"timestamp": "??",
"duration": "??",
"priority": "??",
"sampled": true,
"nr.entryPoint": true,
"transaction.name": "OtherTransaction/php__FILE__"
},
{},
{}
],
[
{
"category": "generic",
"type": "Span",
"guid": "??",
"traceId": "??",
"transactionId": "??",
"name": "Custom\/custom_function_not_exceeding_tt_detail_threshold",
"timestamp": "??",
"duration": "??",
"priority": "??",
"sampled": true,
"parentId": "??"
},
{},
{
"code.lineno": "??",
"code.filepath": "__FILE__",
"code.function": "custom_function_not_exceeding_tt_detail_threshold"
}
]
]
]
*/

function function_exceeding_tt_detail_threshold() {
error_reporting(error_reporting()); // prevent from optimizing this function away
time_nanosleep(0, 100 * 1000); // 100 microseconds should be enough (= 2 x newrelic.special.expensive_node_min)
echo 'function_exceeding_tt_detail_threshold called' . PHP_EOL;
}

function custom_function_not_exceeding_tt_detail_threshold() {
error_reporting(error_reporting()); // prevent from optimizing this function away
time_nanosleep(0, 100 * 1000); // 100 microseconds should be enough (= 2 x newrelic.special.expensive_node_min)
echo 'custom_function_not_exceeding_tt_detail_threshold called' . PHP_EOL;
}

// These calls will not be a span in span events
function_exceeding_tt_detail_threshold();
custom_function_not_exceeding_tt_detail_threshold();

// Add a custom wrapper to ensure that all future calls will be recorded as spans in span events
newrelic_add_custom_tracer('custom_function_not_exceeding_tt_detail_threshold');

// This call will not be a span in span events
function_exceeding_tt_detail_threshold();

// This call will be a span in span events
custom_function_not_exceeding_tt_detail_threshold();

echo 'No alarms and no surprises.' . PHP_EOL;
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*/

/*DESCRIPTION
When transaction tracer details are disabled, test that only calls to custom wrapped functions appear as spans in span events after they have been wrapped.
When transaction tracer details are disabled, test that only calls to custom wrapped functions appear as spans in span events after they have been wrapped using config.
*/

/*INI
newrelic.transaction_tracer.detail = 0
newrelic.special.expensive_node_min = 50us
newrelic.transaction_tracer.custom = "custom_function_not_exceeding_tt_detail_threshold"
*/

/*EXPECT
Expand Down Expand Up @@ -52,7 +53,7 @@
"guid": "??",
"traceId": "??",
"transactionId": "??",
"name": "Custom\/my_custom_function",
"name": "Custom\/custom_function_not_exceeding_tt_detail_threshold",
"timestamp": "??",
"duration": "??",
"priority": "??",
Expand All @@ -63,26 +64,29 @@
{
"code.lineno": "??",
"code.filepath": "__FILE__",
"code.function": "my_custom_function"
"code.function": "custom_function_not_exceeding_tt_detail_threshold"
}
]
]
]
*/

function my_custom_function() {
function function_exceeding_tt_detail_threshold() {
error_reporting(error_reporting()); // prevent from optimizing this function away
time_nanosleep(0, 100 * 1000); // 100 microseconds should be enough (= 2 x newrelic.special.expensive_node_min)
echo 'my_custom_function called' . PHP_EOL;
echo 'function_exceeding_tt_detail_threshold called' . PHP_EOL;
}

// This call will not be a span in span events
my_custom_function();

// Add a custom wrapper to ensure that all future calls will be recorded as spans in span events
newrelic_add_custom_tracer('my_custom_function');
function custom_function_not_exceeding_tt_detail_threshold() {
error_reporting(error_reporting()); // prevent from optimizing this function away
time_nanosleep(0, 100 * 1000); // 100 microseconds should be enough (= 2 x newrelic.special.expensive_node_min)
echo 'custom_function_not_exceeding_tt_detail_threshold called' . PHP_EOL;
}

// This call will not be a span in span events
my_custom_function();
function_exceeding_tt_detail_threshold();

// This call will be a span in span events
custom_function_not_exceeding_tt_detail_threshold();

echo 'No alarms and no surprises.' . PHP_EOL;

0 comments on commit d17755a

Please sign in to comment.