{"id":23905813,"url":"https://github.com/mts88/laravel-zipkin","last_synced_at":"2025-04-11T03:21:17.262Z","repository":{"id":57021680,"uuid":"211052040","full_name":"mts88/laravel-zipkin","owner":"mts88","description":"A useful library to use Openzipkin in Laravel","archived":false,"fork":false,"pushed_at":"2020-01-16T15:14:48.000Z","size":15,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T01:03:34.741Z","etag":null,"topics":["distributed-log","distributed-logging-system","distributed-tracing","laravel","laravel-zipkin","logger","logger-middleware","logging","openzipkin","openzipkin-php","zipkin","zipkin-client"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mts88.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-26T09:31:18.000Z","updated_at":"2024-12-09T08:33:44.000Z","dependencies_parsed_at":"2022-08-23T12:20:44.296Z","dependency_job_id":null,"html_url":"https://github.com/mts88/laravel-zipkin","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mts88%2Flaravel-zipkin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mts88%2Flaravel-zipkin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mts88%2Flaravel-zipkin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mts88%2Flaravel-zipkin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mts88","download_url":"https://codeload.github.com/mts88/laravel-zipkin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248334112,"owners_count":21086316,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-log","distributed-logging-system","distributed-tracing","laravel","laravel-zipkin","logger","logger-middleware","logging","openzipkin","openzipkin-php","zipkin","zipkin-client"],"created_at":"2025-01-05T01:17:48.312Z","updated_at":"2025-04-11T03:21:17.243Z","avatar_url":"https://github.com/mts88.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n  \n# Laravel MongoDB GridFS\n\n[![Latest Stable Version](https://poser.pugx.org/mts88/laravel-zipkin/v/stable)](https://packagist.org/packages/mts88/laravel-zipkin)\n[![Total Downloads](https://poser.pugx.org/mts88/laravel-zipkin/downloads)](https://packagist.org/packages/mts88/laravel-zipkin)\n[![License](https://poser.pugx.org/mts88/laravel-zipkin/license)](https://packagist.org/packages/mts88/laravel-zipkin)\n\nA library wants to help the use Openzipkin for Laravel. \n\n# Table of contents\n* [Installation](#installation)\n* [Configuration](#configuration)\n* [Automatic API tracing](#automatic-api-tracing)\n* [Usage](#usage)\n\t* [Dependency](#dependency)\n\t* [BaseController](#basecontroller)\n\t* [Create trace and rootSpan](#create-trace-and-rootspan)\n\t* [Child span](#child-span)\n* [Contact](#contact)\n* [License](#license)\n# Installation\n\n### Laravel version Compatibility\n\n| Laravel | Package |\n|--|--|\n| 5.x | not tested |\n| \u003e= 6.x.x | 1.0.x |\n\n### Requirements\nNo requirements are necessary.\n\n### Installation\n1. Installation using composer:\n```\ncomposer require mts88/laravel-zipkin\n```\n2. And add the service provider in  `config/app.php`:\n```php\nMts88\\LaravelZipkin\\Providers\\LaravelZipkinServiceProvider::class\n```\n3. You may also register an alias for the ZipkinService by adding the following to the alias array in  `config/app.php`:\n```php\n'Zipkin'       =\u003e Mts88\\LaravelZipkin\\Facades\\Zipkin,\n```\n\n## Configuration\n\nRun the command below to publish the package config file  `config/zipkin.php`:\n```php\nphp artisan vendor:publish\n```\nin your `.env` file define these parameters and set up your configuration: \n```php\nZIPKIN_HOST=http://localhost\nZIPKIN_PORT=9411\n```\n\n## Automatic API tracing\nThe library offer an automatic tracing of request, in particular about your API.  In order to use this automatic tracing you have:\n1. Insert the middleware in your `app/Kernel.php` where do you want automatic tracing. For example you can use in api block:\n```php\n'api' =\u003e [\n\t'throttle:60,1',\n\t'bindings',\n\t// Others middleware\n\t\\Mts88\\LaravelZipkin\\Middlewares\\ZipkinRequestLogger::class,\n],\n```\n2. **Each controller** of Api must extends `ZipkinBaseController` (check [BaseController](#basecontroller)):\n```php\nclass MyApiController extends ZipkinBaseController{\n// My Api Methods\n}\n```\n## Usage\n### Dependency\nYou can easly access to ZipkinService by dependency injection. In your `Controller` you can access in this way:\n```php\nuse Mts88\\LaravelZipkin\\Services\\ZipkinService;\n\nclass MyAwesomeController extends Controller{\n\tpublic  function  __construct(ZipkinService  $zipkinService)\n\t{\n\t\t// Do something with $zipkinService\n\t}\n}\n```\n\n### BaseController\nIf you want to automatize child span between controllers and methods, you can use `ZipkinBaseController` and foreach method called in Controller he create automatically a span for the current rootSpan instance.\n**note**: ZipkinBaseController doen't create rootSpan, so you have to create before methods are called. For example in middleware.\n```php\nuse Mts88\\LaravelZipkin\\Controllers\\ZipkinBaseController;\n\nclass MyAwesomeController  extends  ZipkinBaseController {\n\t// My Awesome Methods\n}\n```\nIn this way you don't need to access to `$zipkinService` in `__construct`, but if you need to override it you **have** to call parent constructor:\n```php\nuse Mts88\\LaravelZipkin\\Services\\ZipkinService;\nuse Mts88\\LaravelZipkin\\Controllers\\ZipkinBaseController;\n\nclass MyAwesomeController extends ZipkinBaseController{\n\n\tpublic  function  __construct(ZipkinService  $zipkinService)\n\t{\n\t\tparent::__construct($zipkinService);\n\t\t// Do something with your override\n\t}\n}\n```\n\n**note**: in your `MyAwesomeController` now you can access to ZipkinService with public variable of `ZipkinBaseController` :\n```php\n\t// zipkinService instance\n\t$this-\u003ezipkinService;\t\n```\n\n### Create trace and rootSpan\nIn order to create a rootSpan you can use this code\n```php\n$this-\u003ezipkinService = new ZipkinService(); // or you can access in others way\n\n// Create trace\n$this-\u003ezipkinService-\u003esetTracer('my_trace_name', $request-\u003eip());\n\n$tags = [\n\t\"my_value1\" =\u003e \"hello\",\n\t\"my_value2\" =\u003e \"world\"\n];\n\n// Create RootSpan\n$this-\u003ezipkinService-\u003ecreateRootSpan('root_span_of_request', $tags);\n\n// Set Annotation\n$this-\u003ezipkinService-\u003esetRootSpanAnnotation('my_annotation_1', \\Zipkin\\Timestamp\\Timestamp\\now());\n\n// Dedicated Tags Methods\n$this-\u003ezipkinService-\u003esetRootSpanMethod('GET') // Method of request\n\t-\u003esetRootSpanPath('/') // Path of request\n\t-\u003esetRootSpanStatusCode(\"200\") // Response Code Server\n\t-\u003esetRootAuthUser(Auth::user()); // User that perform request\n\t\n// Insert others tags\n$this-\u003esetRootSpanTag('my_value3', \"ciao\")\n\t-\u003esetRootSpanTag('my_value4', \"mondo\");\n\n\n// Close rootSpan and tracer\n$this-\u003ezipkinService-\u003ecloseSpan();\n```\n\n### Child span\nTo create a child span:\n```php\n// Create tracer\n$tracing = $this-\u003ezipkinService-\u003ecreateTracing('child_span_tracing', $request-\u003eip());\n$tracer = $tracing-\u003egetTracer(); \n\n// Create Span\n$span = $tracer-\u003enextSpan($this-\u003ezipkinService-\u003egetRootSpanContext());\n$span-\u003eannotate(\"Start\", \\Zipkin\\Timestamp\\Timestamp\\now());\n$span-\u003esetName('Child span method');\n$span-\u003estart(\\Zipkin\\Timestamp\\Timestamp\\now());\n\n// Create Tag for Child Span\n$span-\u003etag(\"my_tag_1\", 'Hello');\n$span-\u003etag(\"my_tag_2\", 'World');\n// Make annotation\n$span-\u003eannotate(\"End\", \\Zipkin\\Timestamp\\Timestamp\\now());\n\n// Close Span\n$span-\u003efinish(\\Zipkin\\Timestamp\\Timestamp\\now());\n$tracer-\u003eflush();\n```\n\n## Contact\nOpen an issue on GitHub if you have any problems or suggestions.\n## License\nThe contents of this repository is released under the  [MIT license](http://opensource.org/licenses/MIT).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmts88%2Flaravel-zipkin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmts88%2Flaravel-zipkin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmts88%2Flaravel-zipkin/lists"}