Syntax
newrelic_add_custom_tracer(string $function_name)
Specify functions or methods for the agent to instrument with custom instrumentation.
Requirements
Compatible with all agent versions.
Description
Specify functions or methods for the agent to target for custom instrumentation. This is the API equivalent of the newrelic.transaction_tracer.custom
setting.
You cannot apply custom tracing to internal PHP functions.
Parameters
Parameter | Description |
---|---|
string | Required. The name can be formatted either as |
Return values
Returns true
if the tracer was added successfully.
Examples
Instrument a function
function example_function() { if (extension_loaded('newrelic')) { // Ensure PHP agent is available newrelic_add_custom_tracer("example_function"); }}
Instrument a method within a class
class ExampleClass { function example_method() { if (extension_loaded('newrelic')) { // Ensure PHP agent is available newrelic_add_custom_tracer("ExampleClass::example_method"); } }}
Instrument a method within a namespaced class
namespace Foo\Bar;
class ExampleClass { function example_method() { if (extension_loaded('newrelic')) { // Ensure PHP agent is available newrelic_add_custom_tracer("Foo\\Bar\\ExampleClass::example_method"); } }}
Alternatively, on PHP 5.5 or later, the ::class
syntax can be used instead:
namespace Foo\Bar { class ExampleClass { function example_method() { // ... } }}
namespace { use Foo\Bar;
if (extension_loaded('newrelic')) { // Ensure PHP agent is available newrelic_add_custom_tracer(Bar::class . "::example_method"); }}