Instrument commands/workers/custom code with datadog, newrelic, tideways, symfony, spx.

Overview

sourceability/instrumentation

This library provides a simple interface to start and stop instrumenting code with APMs.

Symfony commands and messenger workers have built in symfony event listeners which is convenient because most APMs usually don't support profiling workers out of the box.

Install the library using composer:

$ composer require sourceability/instrumentation

Bundle

This library includes an optional Symfony bundle that you can install by updating config/bundles.php:

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    // ...
    Sourceability\Instrumentation\Bundle\SourceabilityInstrumentationBundle::class => ['all' => true],
];

Bundle configuration reference:

# Default configuration for extension with alias: "sourceability_instrumentation"
sourceability_instrumentation:
    profilers:

        # See https://support.tideways.com/documentation/features/application-monitoring/application-performance-overview.html
        tideways:
            enabled:              false

        # See https://docs.newrelic.com/docs/agents/php-agent/getting-started/introduction-new-relic-php/
        # This requires https://github.com/ekino/EkinoNewRelicBundle
        newrelic:
            enabled:              false

        # See https://docs.datadoghq.com/tracing/setup_overview/setup/php/
        datadog:
            enabled:              false

        # This "hacks" the symfony web profiler to create profiles in non web contexts like workers, commands.
        # This is really useful for development along with https://github.com/sourceability/console-toolbar-bundle
        symfony:
            enabled:              false

        # See https://github.com/NoiseByNorthwest/php-spx
        spx:
            enabled:              false
    listeners:

        # Automatically instrument commands
        command:
            enabled:              false

        # Automatically instrument messenger workers
        messenger:
            enabled:              false

Messenger profiling is also available with a middleware:

framework:
    messenger:
        buses:
            messenger.bus.default:
                middleware:
                    - Sourceability\Instrumentation\Messenger\ProfilerMiddleware

Instrumenting a long running command



namespace App\Command;

use Sourceability\Instrumentation\Profiler\ProfilerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class IndexCommand extends Command
{
    /**
     * @var ProfilerInterface
     */
    private $profiler;

    public function __construct(ProfilerInterface $profiler)
    {
        parent::__construct();

        $this->profiler = $profiler;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $this->profiler->stop();

        $pager = new Pagerfanta(...);

        foreach ($pager as $pageResults) {
            $this->profiler->start('index_batch');

            $this->indexer->index($pageResults);

            $this->profiler->stop();
        };

        return 0;
    }
}
Comments
  • Profiling messenger in Datadog seems off

    Profiling messenger in Datadog seems off

    Hi :)

    I'm struggling to give meaning to how data goes to Datadog. Traces & spans seems to mix the messenger:consume command, and the individual consumed messages

    Here's an example :

    image

    You can see individual messages around a ~2-5s, but the first consumed one is always -5-7minutes, which is likely to be the worker process restart time (10 min),

    My config is the following:

    # config/sourceability_instrumentation.yaml
    sourceability_instrumentation:
      profilers:
        datadog:
          enabled: true
    
      listeners:
        command:
          enabled: true
    
        messenger:
          enabled: true
    
    #config/messenger.yaml
    framework:
        messenger:
            buses:
                messenger.bus.default:
                    middleware:
                        - Sourceability\Instrumentation\Messenger\ProfilerMiddleware
    

    Am I doing something wrong? Are the messenger listener & messenger middlewares stepping on each others toes?

    opened by clemherreman 5
  • Make symfony bundle optional

    Make symfony bundle optional

    I moved all the symfony bundle specific files into a new namespace Bundle. Also I removed the requirement for symfony/framework and instead added the necessary symfony components as dev-dependencies and suggestions.

    See this conversation: https://twitter.com/jkrzefski/status/1402881774535970817

    opened by jkrzefski 5
  • Fix support for symfony 4.4 in SymfonyProfiler

    Fix support for symfony 4.4 in SymfonyProfiler

    Symfony 4.4 uses the older method getMasterRequest() instead of getMainRequest(). Since 4.4 is supported by this library at this time, I propose this change so it correctly works using symfony 4.4.

    opened by Zombaya 2
  • Adds Symfony 6 Support

    Adds Symfony 6 Support

    This widens the composer requires to allow Symfony 6.0.

    Symfony 5.1 deprecated the method named getMasterRequest on RequestStack in favor of getMainRequest. This commit updates the two spots in the codebase that uses that method.

    opened by magikid 1
  • Update messenger profiler listener priority to wrap other subscribers

    Update messenger profiler listener priority to wrap other subscribers

    Hi,

    This PR update the priority of the messenger profiler listener to make sure that the profiler is start before any other listener and is stop after any other listeners.

    opened by blazarecki 1
  • Use entire class name of message instead of short name

    Use entire class name of message instead of short name

    This is helpful when messages have FQCNs like Acme\MessageQueue\EmailSender\Message. The short name is simply Message which is super not-helpful. So my change now uses the full class name.

    opened by jkrzefski 1
  • Unwrap Messenger HandlerFailedException

    Unwrap Messenger HandlerFailedException

    Messenger wraps any exception that happens in a handler with HandlerFailedException. This is even worse, because the actual exception is not set as Exception::getPrevious(). So the only valuable information from the initial exception that makes its way to the profiler, is the message. No stack trace ... 😱

    This fixes that issue!

    opened by adrienbrault 0
Owner
null
PHP daemon for managing gearman workers

Running Gearman workers can be a tedious task. Many many files with the same lines of code over and over for creating a worker, connecting to a server, adding functions to the worker, etc. etc. The aim of GearmanManager is to make running workers more of an operational task and less of a development task.

Brian Moon 684 Dec 5, 2022
Silverstripe-searchable - Adds to the default Silverstripe search by adding a custom results controller and allowing properly adding custom data objects and custom fields for searching

SilverStripe Searchable Module UPDATE - Full Text Search This module now uses Full Text Support for MySQL/MariaDB databases in version 3.* Adds more c

ilateral 13 Apr 14, 2022
The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API.

netz98 magerun CLI tools for Magento 2 The n98 magerun cli tools provides some handy tools to work with Magento from command line. Build Status Latest

netz98 758 Dec 28, 2022
Glz custom fields - Unlimited Custom Fields for Textpattern

Unlimited custom fields for Textpattern This plugin sits under the Extensions tab in the back-end and gives your custom fields new life. You can final

Gerhard Lazu 21 Dec 1, 2019
Magento 2 custom extension to add custom attributes(longitude, latitude) to customer address

Magento 2 custom extension to add custom attributes(longitude, latitude) to customer address. Then save them to quote model and copy them from quote address to order address on bakend, frontend, rest api

MageArab 2 Jul 14, 2022
Custom code snippets and examples for SkyVerge-built WooCommerce extensions

SkyVerge WooCommerce Plugins Welcome to the wc-plugins-snippets repository! This repository stores code snippets related to SkyVerge WooCommerce plugi

SkyVerge 255 Nov 16, 2022
Simple Symfony API-Platform Template which you can use to start to develop with symfony and api-platform

symfony-api-platform-skeleton Simple Template for Symfony API You can fork it and change the git remote to your Repo git remote set-url <your-git-remo

null 1 Jan 23, 2022
Dockerise Symfony Application (Symfony 6 + Clean Architecture+ DDD+ CQRS + Docker + Xdebug + PHPUnit + Doctrine ORM + JWT Auth + Static analysis)

Symfony Dockerise Symfony Application Install Docker Install Docker Compose Docker PHP & Nginx Create Symfony Application Debugging Install Xdebug Con

null 48 Jan 5, 2023
Execute Artisan commands on remote servers

Execute Artisan commands on remote servers This package provides a command to execute Artisan command on a remote server. Here's an example that will

Spatie 238 Dec 29, 2022
A Pocketmine Plug-in For Executing Commands While You Click on a item

ItemInteract What This Plugin Do? well This Plugin Is Usefull For Some Servers Like minigames,Skyblock,Lobby etc. This plugin can execute commands whi

null 6 May 31, 2022
This is a PocketMine plugin that helps staffs track players using commands.

Track This is a PocketMine plugin that helps staffs track players using commands. Features Allows selected staffs to watch players use commands to fac

Nguyễn Thành Nhân 6 Jun 23, 2022
Run the following commands in your terminal to setup the project

Run the following commands in your terminal to setup the project You must have the LAMP installed on your system git clone https://github.com/Bashar-A

null 1 Nov 6, 2021
Easy management of Virtualization technologies including KVM, Xen, OpenVZ, Virtuozzo, and LXC/LXD including unified commands, monitoring, template management, and many more features.

ProVirted About Easy management of Virtualization technologies including KVM, Xen, OpenVZ, Virtuozzo, and LXC/LXD including unified commands, monitori

null 2 Aug 22, 2022
Prepare your Laravel apps incredibly fast, with various commands, services, facades and boilerplates.

Grafite Builder Grafite has archived this project and no longer supports or develops the code. We recommend using only as a source of ideas for your o

Grafite Inc 997 Dec 22, 2022
Dispatcher is a Laravel artisan command scheduling tool used to schedule artisan commands within your project so you don't need to touch your crontab when deploying.

Dispatcher Dispatcher allows you to schedule your artisan commands within your Laravel project, eliminating the need to touch the crontab when deployi

Indatus 1.1k Dec 21, 2022
This Plugin runs commands when a player does a certain emote

The EmoteCommands Plugin This Plugin runs commands when a player does a certain emote You will need a pocketmine server of at least version 4.0.0 Usag

DiamondStrider1 1 Jan 24, 2022
Commands and implementations for common tasks for the PHP Content Repository (PHPCR) API.

PHPCR Utilities Commands and implementations for common tasks for the PHP Content Repository (PHPCR) API. If you are using or implementing PHPCR you p

PHPCR 65 Nov 20, 2022
A multi-purpose web-shell that simplifies running shell commands on webserver

This webshell can be used for multi-purposed especially most if you want to manage your web server but you are in an emergency , so why not use a webshell:)

urchinsec 5 Oct 13, 2022
Simple configurable plugin to see all commands executed by players

About [FR] Simple plugin configurable permettant de voir toutes les commandes exécutées par les joueurs [ENG] Simple configurable plugin to see all co

leo 1 Feb 4, 2022