🔭 Proof of concept on adding observability features (tracing and metrics) to a Nano microservice (using existing Hyperf components).

Overview

🔭 Tracing Nano

Proof of concept on adding observability features (tracing and metrics) to a Nano microservice (using existing Hyperf components 🚀 ).

Run Prometheus, Grafana and Jaeger using Docker:

docker compose up

Then link Prometheus as a data source in Grafana using service's name as host (i.e.: http://prometheus:9090).

Run Nano with:

php app.php start

Thanks to @huangdijia for the help with AOP + Nano.

You might also like...
A Restful PHP Microservice Framework!

SLIM 4 FRAMEWORK Introduction This project was built with php SLIM 4 framework with ADR mode, whcich is a compatible resolution of RESTful Api. Featur

Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container, http, log and route.

Kit What is it Kit is a lightweight, high-performance and event-driven web services framework that provides core components such as config, container,

Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components
Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components

Spiral HTTP Application Skeleton Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components.

📦 This is a repository of centralized management of all swoft core components

Swoft Component This repository is used to manage all swoft core components. 中文说明 中文说明请查看 README.zh-CN.md IMPORTANT All components will NOT be modifie

Fast PHP framework made with very loose optional components.
Fast PHP framework made with very loose optional components.

Nimble is a super fast mini-framework for PHP built on top of optional loose components. Installation Clone the repository $ git clone [email protected]:

Coole is a PHP framework built on open source components
Coole is a PHP framework built on open source components

Coole is a PHP framework built on open source components. - Coole 是一个基于开源组件包构建的 PHP 框架。

An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)
An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)

yii2-widget-fileinput The FileInput widget is a customized file input widget based on Krajee's Bootstrap FileInput JQuery Plugin. The widget enhances

Hello, this is simple attribute validation for PHP Models, based on the new features, presented in PHP 8

Hello, this is simple attribute validation for PHP Models, based on the new features, presented in PHP 8 It works as a standalone and can be use in custom projects or in libraries like Symfony and Laravel.

Comments
  • Replacing the config configuration file with a ConfigProvider

    Replacing the config configuration file with a ConfigProvider

    • app.php
    <?php
    
    declare(strict_types=1);
    
    use Hyperf\Contract\StdoutLoggerInterface;
    use Hyperf\Di\ClassLoader;
    use Hyperf\Metric\Adapter\Prometheus\Constants;
    use Hyperf\Metric\Adapter\Prometheus\MetricFactory;
    use Hyperf\Nano\Factory\AppFactory;
    use Hyperf\Tracer\Adapter\JaegerTracerFactory;
    use Hyperf\Utils\Composer;
    use Jaeger\Config;
    use Psr\Log\LogLevel;
    
    use const Jaeger\SAMPLER_TYPE_CONST;
    
    define('BASE_PATH', __DIR__);
    
    require_once BASE_PATH . '/vendor/autoload.php';
    
    class ConfigProvider
    {
        public function __invoke()
        {
            return [
                'app_name' => 'tracing-nano',
                'app_env' => 'dev',
                'scan_cacheable' => false,
                'annotations' => [
                    'scan' => [
                        'paths' => [
                            // BASE_PATH . '/',
                        ],
                    ],
                ],
                StdoutLoggerInterface::class => [
                    'log_level' => [
                        LogLevel::ALERT,
                        LogLevel::CRITICAL,
                        LogLevel::DEBUG,
                        LogLevel::EMERGENCY,
                        LogLevel::ERROR,
                        LogLevel::INFO,
                        LogLevel::NOTICE,
                        LogLevel::WARNING,
                    ],
                ],
                'aspects' => [
                    // ...
                ],
                'metric' => [
                    'default' => 'prometheus',
                    'metric' => [
                        'prometheus' => [
                            'driver' => MetricFactory::class,
                            'mode' => Constants::SCRAPE_MODE,
                            'namespace' => 'tracing_nano',
                            'scrape_host' => '0.0.0.0',
                            'scrape_port' => '9502',
                            'scrape_path' => '/metrics',
                        ],
                    ],
                ],
                'middlewares' => [
                    'http' => [
                        MetricMiddleware::class,
                        TraceMiddleware::class,
                    ],
                ],
                'opentracing' => [
                    'default' => 'jaeger',
                    'enable' => [
                        'guzzle' => true,
                    ],
                    'tracer' => [
                        'jaeger' => [
                            'driver' => JaegerTracerFactory::class,
                            'name' => 'tracing-nano',
                            'options' => [
                                'sampler' => [
                                    'type' => SAMPLER_TYPE_CONST,
                                    'param' => true,
                                ],
                                'logging' => true,
                                'dispatch_mode' => Config::JAEGER_OVER_BINARY_HTTP,
                            ],
                        ],
                    ],
                ],
            ];
        }
    }
    
    // Inject ConfigProvider into Hyperf\Utils\Composer::$extra
    Closure::bind(function () {
        self::getLockContent();
        self::$extra[uniqid()] = [
            'hyperf' => [
                'config' => ConfigProvider::class,
            ],
        ];
    }, null, Composer::class)();
    ClassLoader::init();
    
    $app = AppFactory::createBase('0.0.0.0', 9501);
    
    $app->addCommand('foo', function () {
        var_dump(config('annotations.scan'));
    });
    
    $app->run();
    
    
    enhancement 
    opened by huangdijia 1
Owner
Leo Cavalcante
Staff Software Engineer @ PicPay
Leo Cavalcante
🚀 Developing Rocketseat's Next Level Week (NLW#05) Application using PHP/Swoole + Hyperf

Inmana PHP ?? Developing Rocketseat 's Next Level Week (NLW#05) Application using Swoole + Hyperf. This is the app of the Elixir track. I know PHP/Swo

Leo Cavalcante 18 Jun 1, 2022
An issue tracking tool based on hyperf+reactjs for small and medium-sized enterprises, open-source and free, similar to Jira.

介绍 本项目以 actionview 为蓝本,使用 Hyperf 框架进行重写。 本项目为 Hyperf 框架的 DEMO 项目 原 ActionView 介绍 English | 中文 一个类Jira的问题需求跟踪工具,前端基于reactjs+redux、后端基于php laravel-frame

Gemini-D 14 Nov 15, 2022
🚀Hyperf is an extremely performant and flexible PHP CLI framework

Hyperf is an extremely performant and flexible PHP CLI framework, powered by a state-of-the-art coroutine server and a large number of battle-tested components. Aside from decisively beating PHP-FPM frameworks in benchmarks, Hyperf is unique in its focus on flexibility and composition.

Hyperf 4.9k Dec 30, 2022
Hyperf is an extremely performant and flexible PHP CLI framework

?? A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.

Hyperf 5k Jan 4, 2023
🎲 This project provides an integration for the Doctrine ORM and the Hyperf framework

Hyperf ?? Doctrine This project provides an integration for the Doctrine ORM and the Hyperf framework. Install composer require leocavalcante/hyperf-d

Leo Cavalcante 49 Dec 3, 2022
🚀 PHP Microservice Full Coroutine Framework

PHP microservice coroutine framework 中文说明 Introduction Swoft is a PHP microservices coroutine framework based on the Swoole extension. Like Go, Swoft

Swoft Cloud 5.5k Dec 28, 2022
Hyperf instant messaging program based on swoole framework

Hyperf instant messaging program based on swoole framework

null 20 Aug 12, 2022
Files Course Laravel Microservice E-mail

Curso Laravel Microservices com RabbitMQ (micro e-mail) Saiba Mais Sobre o Curso Requisitos Este micro e-mail depende do microservice 01, portanto, pr

EspecializaTi 9 Oct 21, 2021
DoraRPC is an RPC For the PHP MicroService by The Swoole

Dora RPC 简介(Introduction) Dora RPC 是一款基础于Swoole定长包头通讯协议的最精简的RPC, 用于复杂项目前后端分离,分离后项目都通过API工作可更好的跟踪、升级、维护及管理。 问题提交: Issue For complex projects separation

Chang Long Xu 468 Jan 5, 2023
A Restful PHP Microservice Framework!

SLIM 4 FRAMEWORK Introduction This project was built with php SLIM 4 framework with ADR mode, whcich is a compatible resolution of RESTful Api. Featur

POABOB 4 Nov 22, 2022