PHP agent API
The PHP agent API allows you to extend the functionality of the PHP agent. The agent API is included by default with your installation, so no additional configuration is required to use the agent.
Among other things, you can use the API to customize your app name; collect errors; record custom attributes, custom events, and custom metrics; and enable or disable browser monitoring. For an introduction to this API, see Guide to PHP agent API.
Enclose these API calls in a conditional check for the PHP agent so that your code will work even if the agent is not present:
if (extension_loaded('newrelic')) { newrelic_set_appname($name); }
- newrelic_insert_distributed_trace_headers
- Inserts W3C Trace Context headers and New Relic Distributed Tracing headers into an outbound array of headers.
- newrelic_accept_distributed_trace_headers
- Accepts an array of distributed trace headers.
- newrelic_accept_distributed_trace_payload
- Accepts a distributed trace payload.
- newrelic_accept_distributed_trace_payload_httpsafe
- Accepts a distributed trace payload that includes an HTTPSafe (Base64 encoded) JSON string.
- newrelic_add_custom_parameter
- Attaches a custom attribute (key/value pair) to the current transaction and the current span (if enabled).
- newrelic_add_custom_span_parameter
- Attaches a custom attribute (key/value pair) to the current span.
- newrelic_add_custom_tracer
- Specify functions or methods for the agent to instrument with custom instrumentation.
- newrelic_background_job
- Manually specify that a transaction is a background job or a web transaction.
- newrelic_capture_params
- Enable or disable the capture of URL parameters.
- newrelic_create_distributed_trace_payload
- Creates a distributed trace payload.
- newrelic_custom_metric
- Add a custom metric (in milliseconds) to time a component of your app not captured by default.
- newrelic_disable_autorum
- Disable automatic injection of the browser monitoring snippet on particular pages.
- newrelic_end_of_transaction
- Stop timing the current transaction, but continue instrumenting it.
- newrelic_end_transaction
- Stop instrumenting the current transaction immediately.
- Returns a browser monitoring snippet to inject at the end of the HTML output.
- newrelic_get_browser_timing_header
- Returns a browser monitoring snippet to inject in the head of your HTML output.
- newrelic_get_linking_metadata
- Returns a collection of metadata necessary for linking data to a trace or an entity.
- newrelic_get_trace_metadata
- Returns an associative array containing the identifiers of the current trace and the parent span.
- newrelic_ignore_apdex
- Ignore the current transaction when calculating Apdex.
- newrelic_ignore_transaction
- Do not instrument the current transaction.
- newrelic_is_sampled
- Returns a value indicating whether or not the current transaction is marked as sampled.
- newrelic_name_transaction
- Set custom name for current transaction.
- newrelic_notice_error
- Use these calls to collect errors that the PHP agent does not collect automatically and to set the callback for your own error and exception handler.
- newrelic_record_custom_event
- Record a custom event with the given name and attributes.
- newrelic_record_datastore_segment
- Records a datastore segment.
- newrelic_set_appname
- Sets the New Relic app name, which controls data rollup.
- newrelic_set_user_attributes
- Create user-related custom attributes. newrelic_add_custom_parameter is more flexible.
- newrelic_start_transaction
- Starts a new transaction, usually after manually ending a transaction.