Search by

leocavalcante / newrelic-telemetry-sdk

leocavalcante

Unofficial PHP library for sending telemetry data to New Relic

Package info

github.com/leocavalcante/newrelic-telemetry-sdk-php

pkg:composer/leocavalcante/newrelic-telemetry-sdk

Statistics

Installs: 1 081

Dependents: 0

Suggesters: 0

Stars: 7

Open Issues: 0

v0.1.1 2021-02-18 12:54 UTC

This package is auto-updated.

Last update: 2026-09-19 01:08:05 UTC


README

Unofficial PHP library for sending telemetry data to New Relic.

Status API Description
✅ Trace API Used to send distributed tracing data to New Relic (New Relic's format).
✅ Metric API Used to send metric data to New Relic.
✅ Event API Is one way to report custom events to New Relic.
- Log API Not planned.
  • ⚠️ Heavily under development, but open-sourced seeking for contributions.
  • It is not an agent wrapper, it calls the New Relic Ingest APIs.

Usage

Example

Sending a Gauge metric.

use NewRelic\Adapter;
use NewRelic\Metric;

$metric_api = new Metric\API(new Adapter\Curl(getenv('NR_API_KEY')));
$metric_api->setCommonAttrs(['service.name' => 'PHP-SDK']);
$metric_api->send(new Metric\Gauge('memory.heap', 2.3));

$response = $metric_api->commit();

if ($response->isOk()) {
    echo sprintf("Request ID: %s\n", $response->getId());
} else {
    echo sprintf("Metric send error: %s\n", $response->getMessage());
}

Companion resources

Tips

Why

Main reasons includes:

  • Too many segfaults with the regular agent.
  • Even for simple use cases the regular agent doesn't play well with Swoole. This small snippet is enough to throw a segfault:
    Co\run(static function () {
      go(static function () {
        (new Co\Http\Client('swoole.co.uk'))->get('/');
      });
    });
  • There are other SDKs for other languages, this is an unofficial PHP version.
  • Could be used to build a New Relic exporter for the upcoming OpenTelemetry PHP library.