Coder Social home page Coder Social logo

swoole-newrelic's Introduction

New Relic Monitoring of Swoole

This library enables monitoring of PHP applications powered by Swoole web-server via New Relic products.

Features:

  • New Relic APM integration
  • New Relic Browser integration

Demo

New Relic APM dashboard

Installation

The library is to be installed via Composer as a dependency:

composer require upscale/swoole-newrelic

Usage

Production

Monitoring of requests from start to finish can be activated by adding a few lines of code to the server entry point. The monitoring instrumentation is by design completely transparent to an application running on the server.

Install the monitoring instrumentation for all requests:

use Upscale\Swoole\Newrelic;

$page = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Example page</title>
</head>
<body>
    Served by Swoole server
</body>
</html>

HTML;

$server = new \Swoole\Http\Server('127.0.0.1', 8080);
$server->on('request', function ($request, $response) use ($page) {
    // PHP processing within request boundary...
    usleep(1000 * rand(100, 300));
    
    // Send response
    $response->end($page);
    
    // PHP processing outside of request boundary...
    usleep(1000 * rand(50, 150));
});

// Real user monitoring (RUM)
$rum = new Newrelic\Browser(new Newrelic\Browser\TransactionFactory());
$rum->instrument($server);

// Application performnce monitoring (APM)
$apm = new Newrelic\Apm(new Newrelic\Apm\TransactionFactory());
$apm->instrument($server);

unset($rum, $apm);

$server->start();

APM can be standalone or used in conjunction with the real user monitoring. RUM must be instrumented first.

Browser instrumentation is applied to non-AJAX requests having text/html response MIME type (the default).

Development

Having to install the New Relic PHP extension locally may be inconvenient and outright undesirable for developers. The workaround is to replace the New Relic reporting functionality with the "stub" implementation doing nothing:

{
    "require": {
        "upscale/swoole-newrelic": "^1.0",
        "killmails/polyfill-newrelic": "^1.0"
    },
    "replace": {
        "ext-newrelic": "*"
    }
}

The PHP extension is used when installed and substituted with the polyfill otherwise.

Limitations

Concurrent requests subject to coroutine multi-tasking are reported as part of the first in-flight transaction.

Contributing

Pull Requests with fixes and improvements are welcome!

License

Copyright © Upscale Software. All rights reserved.

Licensed under the Apache License, Version 2.0.

swoole-newrelic's People

Contributors

sshymko avatar websmurf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swoole-newrelic's Issues

Issue with New Relic Transaction Traces

Hi,

We currently don't use custom instrumentation with New Relic.

After migrating from PHP artisan/laravel to swoole, all transactions on New Relic don't have traces anymore. So when selecting one transaction, it doesn't show up the full tracing information that showed before swoole.

I'm wondering if this is intrinsic to the Swoole use or there is a parameter/function to set up.

Do you have any experience on the transaction tracing working with Swoole?

New Relic transactions marked as Non-Web transactions

Transactions reported by this library could still be marked as "Web Transactions" even outside SAPI by telling New Relic the transactions is not a background job:

newrelic_start_transaction(...);
newrelic_background_job(false);
(...)
newrelic_end_transaction();

(see https://docs.newrelic.com/docs/agents/php-agent/php-agent-api/newrelic_background_job)

This limitation would be then lifted:

Transactions are classified by New Relic APM as "Non-web transactions" due to the CLI SAPI environment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.