• /
  • EnglishEspañol日本語한국어Português
  • Log inStart now

newrelic_add_custom_tracer (PHP agent API)

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

$function_name

string

Required. The name can be formatted either as function_name for procedural functions, or as "ClassName::method" for methods. Both static and instance methods will be instrumented if the method syntax is used, and the class name must be fully qualified: it must include the full namespace if the class was defined within a namespace.

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");
}
}
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.