Git Product home page Git Product logo

instrumentation's Introduction

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.

Please note that you should use either the middleware, or the listener, but not both, as this will distort the statistics sent to your APM/monitoring.

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

Instrumenting a long running command

<?php

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;
    }
}

instrumentation's People

Contributors

adrienbrault avatar clemherreman avatar jkrzefski avatar

Watchers

 avatar

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.