diff options
Diffstat (limited to 'vendor/opentracing')
40 files changed, 3007 insertions, 0 deletions
diff --git a/vendor/opentracing/opentracing/.github/ISSUE_TEMPLATE.md b/vendor/opentracing/opentracing/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..f99dd606b --- /dev/null +++ b/vendor/opentracing/opentracing/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,21 @@ +<!-- +Welcome to the OpenTracing PHP repo! 👋🎉 + +- Please search for existing issues in order to ensure we don't have duplicate bugs/feature requests.) +- Please be respectful and considerate of others when commenting on issues) +- Please provide as much information as possible so we all understand the issue.) +- Please don't ask questions here. If you have any question head to our gitter chat https://gitter.im/opentracing/opentracing-php +--> + + +## Background +Something that gives context about why this is an issue. + +## Problem +Describe the problem. If the issue is about an improvement you can skip this. If possible, include a description of the impact of the problem. + +## Proposal +A proposal that from your POV would solve the problem or improve the existing situation. It should also include the impact. + +## Questions to address +Questions that should be answered as outcome of this issue. diff --git a/vendor/opentracing/opentracing/.github/PULL_REQUEST_TEMPLATE.md b/vendor/opentracing/opentracing/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..d81c08379 --- /dev/null +++ b/vendor/opentracing/opentracing/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,24 @@ +<!-- +We appreciate the effort for this pull request but before that please make sure you read the contribution guidelines given above, then fill out the blanks below. + +Please don't open huge pull requests and keep one pull request solving one problem. + +Please enter the issue number you are resolving in your PR after one of the following words [Fixes, Closes, Resolves]. This will auto-link these issues and close them when this PR is merged! +e.g. +Fixes #1 +Closes #2 +--> + +### Short description of what this PR does: +- +- + +### Checklist +- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar) +- [ ] I have read the [Contribution Guide] and my PR follows them. +- [ ] I updated my branch with the master branch. +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] I have added necessary documentation about the functionality in the appropriate .md file +- [ ] I have added in line documentation to the code I modified + +Closes #
\ No newline at end of file diff --git a/vendor/opentracing/opentracing/.github/workflows/ci.yml b/vendor/opentracing/opentracing/.github/workflows/ci.yml new file mode 100644 index 000000000..8fba7baf8 --- /dev/null +++ b/vendor/opentracing/opentracing/.github/workflows/ci.yml @@ -0,0 +1,44 @@ +name: Build +on: + push: + branches: + - master + paths-ignore: + - "**/*.md" + - "LICENSE" + pull_request: +jobs: + test: + name: OpenTracing (PHP version ${{ matrix.php-versions }} on ${{ matrix.operating-system }}) + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest, windows-latest, macos-latest] + php-versions: ["7.1", "7.2", "7.3", "7.4", "8.0", "8.1"] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache composer dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Composer dependencies + run: | + composer install --no-progress --prefer-dist --optimize-autoloader + - name: Run lint + if: matrix.operating-system != 'windows-latest' + run: composer lint + - name: Run static check + run: composer static-check + - name: Run tests + run: composer test diff --git a/vendor/opentracing/opentracing/.gitignore b/vendor/opentracing/opentracing/.gitignore new file mode 100644 index 000000000..56e80855d --- /dev/null +++ b/vendor/opentracing/opentracing/.gitignore @@ -0,0 +1,4 @@ +.idea/ +.phpunit.result.cache +composer.lock +vendor
\ No newline at end of file diff --git a/vendor/opentracing/opentracing/CONTRIBUTING.md b/vendor/opentracing/opentracing/CONTRIBUTING.md new file mode 100644 index 000000000..a13c0fe1d --- /dev/null +++ b/vendor/opentracing/opentracing/CONTRIBUTING.md @@ -0,0 +1,75 @@ +Contributing +============ + +Thank you for contributing to this project! + +Bug reports +----------- + +If you find a bug, please submit an issue. Try to be as detailed as possible +in your problem description to help us fix the bug. + +Feature requests +---------------- + +If you wish to propose a feature, please submit an issue. Try to explain your +use case as fully as possible to help us understand why you think the feature +should be added. + +License +------- + +By contributing your code, you agree to license your contribution under the terms of the APLv2: +https://github.com/opentracing/opentracing-php/blob/master/LICENSE + +All files are released with the Apache 2.0 license. + +Creating a pull request (PR) +---------------------------- + +First [fork the repository](https://help.github.com/articles/fork-a-repo/) on +GitHub. + +Then clone your fork: + +```bash +$ git clone https://github.com/your-name/opentracing-php.git +$ git checkout -b bug-or-feature-description +``` + +And install the dependencies: + +```bash +$ composer install +``` + +Write your code and add tests. Then run the static check and the tests: + +```bash +$ composer run static-check +$ composer run test +``` + +Commit your changes and push them to GitHub: + +```bash +$ git commit -m "Fix nasty bug" +$ git push -u origin bug-or-feature-description +``` + +Then [create a pull request](https://help.github.com/articles/creating-a-pull-request/) +on GitHub. + +If you need to make some changes, commit and push them as you like. When asked +to squash your commits, do so as follows: + +```bash +git rebase -i +git push origin bug-or-feature-description -f +``` + +Coding standard +--------------- + +This project follows the [PSR-2](http://www.php-fig.org/psr/psr-2/) coding style. +Please make sure your pull requests adhere to this standard. diff --git a/vendor/opentracing/opentracing/LICENSE b/vendor/opentracing/opentracing/LICENSE new file mode 100644 index 000000000..8dada3eda --- /dev/null +++ b/vendor/opentracing/opentracing/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/opentracing/opentracing/README.md b/vendor/opentracing/opentracing/README.md new file mode 100644 index 000000000..ce03bc951 --- /dev/null +++ b/vendor/opentracing/opentracing/README.md @@ -0,0 +1,306 @@ +# OpenTracing API for PHP + +[![Build](https://github.com/opentracing/opentracing-php/actions/workflows/ci.yml/badge.svg)](https://github.com/opentracing/opentracing-php/actions/workflows/ci.yml) +[![OpenTracing Badge](https://img.shields.io/badge/OpenTracing-enabled-blue.svg)](http://opentracing.io) +[![Total Downloads](https://poser.pugx.org/opentracing/opentracing/downloads)](https://packagist.org/packages/opentracing/opentracing) +[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg)](https://php.net/) +[![License](https://img.shields.io/github/license/opentracing/opentracing-php.svg)](https://github.com/opentracing/opentracing-php/blob/master/LICENSE) +[![Join the chat at https://gitter.im/opentracing/opentracing-php](https://badges.gitter.im/opentracing/opentracing-php.svg)](https://gitter.im/opentracing/opentracing-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +PHP library for the OpenTracing's API. + +## Required Reading + +In order to understand the library, one must first be familiar with the +[OpenTracing project](http://opentracing.io) and +[specification](http://opentracing.io/documentation/pages/spec.html) more specifically. + +## Installation + +OpenTracing-PHP can be installed via Composer: + +```bash +composer require opentracing/opentracing +``` + +## Usage + +When consuming this library one really only need to worry about a couple of key +abstractions: the `Tracer::startActiveSpan` and `Tracer::startSpan` method, +the `Span` interface, the `Scope` interface and binding a `Tracer` at bootstrap time. Here are code snippets +demonstrating some important use cases: + +### Singleton initialization + +The simplest starting point is to set the global tracer. As early as possible, do: + +```php +use OpenTracing\GlobalTracer; + +GlobalTracer::set(new MyTracerImplementation()); +``` + +### Creating a Span given an existing Request + +To start a new `Span`, you can use the `startSpan` method. + +```php +use OpenTracing\Formats; +use OpenTracing\GlobalTracer; + +... + +// extract the span context +$spanContext = GlobalTracer::get()->extract( + Formats\HTTP_HEADERS, + getallheaders() +); + +function doSomething() { + ... + + // start a new span called 'my_span' and make it a child of the $spanContext + $span = GlobalTracer::get()->startSpan('my_span', ['child_of' => $spanContext]); + + ... + + // add some logs to the span + $span->log([ + 'event' => 'soft error', + 'type' => 'cache timeout', + 'waiter.millis' => 1500, + ]) + + // finish the the span + $span->finish(); +} +``` + +### Starting a new trace by creating a "root span" + +It's always possible to create a "root" `Span` with no parent or other causal reference. + +```php +$span = $tracer->startSpan('my_first_span'); +... +$span->finish(); +``` + +### Active Spans and Scope Manager + +For most use cases, it is recommended that you use the `Tracer::startActiveSpan` function for +creating new spans. + +An example of a linear, two level deep span tree using active spans looks like +this in PHP code: +```php +// At dispatcher level +$scope = $tracer->startActiveSpan('request'); +... +$scope->close(); +``` +```php +// At controller level +$scope = $tracer->startActiveSpan('controller'); +... +$scope->close(); +``` + +```php +// At RPC calls level +$scope = $tracer->startActiveSpan('http'); +file_get_contents('http://php.net'); +$scope->close(); +``` + +When using the `Tracer::startActiveSpan` function the underlying tracer uses an +abstraction called scope manager to keep track of the currently active span. + +Starting an active span will always use the currently active span as a parent. +If no parent is available, then the newly created span is considered to be the +root span of the trace. + +Unless you are using asynchronous code that tracks multiple spans at the same +time, such as when using cURL Multi Exec or MySQLi Polling it is recommended that you +use `Tracer::startActiveSpan` everywhere in your application. + +The currently active span gets automatically finished when you call `$scope->close()` +as you can see in the previous examples. + +If you don't want a span to automatically close when `$scope->close()` is called +then you must specify `'finish_span_on_close'=> false,` in the `$options` +argument of `startActiveSpan`. + +#### Creating a child span assigning parent manually + +```php +$parent = GlobalTracer::get()->startSpan('parent'); + +$child = GlobalTracer::get()->startSpan('child', [ + 'child_of' => $parent +]); + +... + +$child->finish(); + +... + +$parent->finish(); +``` + +#### Creating a child span using automatic active span management + +Every new span will take the active span as parent and it will take its spot. + +```php +$parent = GlobalTracer::get()->startActiveSpan('parent'); + +... + +/* + * Since the parent span has been created by using startActiveSpan we don't need + * to pass a reference for this child span + */ +$child = GlobalTracer::get()->startActiveSpan('my_second_span'); + +... + +$child->close(); + +... + +$parent->close(); +``` + +### Serializing to the wire + +```php +use GuzzleHttp\Client; +use OpenTracing\Formats; + +... + +$tracer = GlobalTracer::get(); + +$spanContext = $tracer->extract( + Formats\HTTP_HEADERS, + getallheaders() +); + +try { + $span = $tracer->startSpan('my_span', ['child_of' => $spanContext]); + + $client = new Client; + + $headers = []; + + $tracer->inject( + $span->getContext(), + Formats\HTTP_HEADERS, + $headers + ); + + $request = new \GuzzleHttp\Psr7\Request('GET', 'http://myservice', $headers); + $client->send($request); + ... + +} catch (\Exception $e) { + ... +} +... +``` + +### Deserializing from the wire + +When using http header for context propagation you can use either the `Request` or the `$_SERVER` +variable: + +```php +use OpenTracing\GlobalTracer; +use OpenTracing\Formats; + +$tracer = GlobalTracer::get(); +$spanContext = $tracer->extract(Formats\HTTP_HEADERS, getallheaders()); +$tracer->startSpan('my_span', [ + 'child_of' => $spanContext, +]); +``` + +### Flushing Spans + +PHP as a request scoped language has no simple means to pass the collected spans +data to a background process without blocking the main request thread/process. +The OpenTracing API makes no assumptions about this, but for PHP that might +cause problems for Tracer implementations. This is why the PHP API contains a +`flush` method that allows to trigger a span sending out of process. + +```php +use OpenTracing\GlobalTracer; + +$application->run(); + +register_shutdown_function(function() { + /* Flush the tracer to the backend */ + $tracer = GlobalTracer::get(); + $tracer->flush(); +}); +``` + +This is optional, tracers can decide to immediately send finished spans to a +backend. The flush call can be implemented as a NO-OP for these tracers. + +### Using `StartSpanOptions` + +Passing options to the pass can be done using either an array or the +SpanOptions wrapper object. The following keys are valid: + +- `start_time` is a float, int or `\DateTime` representing a timestamp with arbitrary precision. +- `child_of` is an object of type `OpenTracing\SpanContext` or `OpenTracing\Span`. +- `references` is an array of `OpenTracing\Reference`. +- `tags` is an array with string keys and scalar values that represent OpenTracing tags. +- `finish_span_on_close` is a boolean that determines whether a span should be finished or not when the +scope is closed. + +```php +$span = $tracer->startActiveSpan('my_span', [ + 'child_of' => $spanContext, + 'tags' => ['foo' => 'bar'], + 'start_time' => time(), +]); +``` + +### Propagation Formats + +The propagation formats should be implemented consistently across all tracers. +If you want to implement your own format, then don't reuse the existing constants. +Tracers will throw an exception if the requested format is not handled by them. + +- `Tracer::FORMAT_TEXT_MAP` should represent the span context as a key value map. There is no + assumption about the semantics where the context is coming from and sent to. + +- `Tracer::FORMAT_HTTP_HEADERS` should represent the span context as HTTP header lines + in an array list. For two context details "Span-Id" and "Trace-Id", the + result would be `['Span-Id: abc123', 'Trace-Id: def456']`. This definition can be + passed directly to `curl` and `file_get_contents`. + +- `Tracer::FORMAT_BINARY` makes no assumptions about the data format other than it is + proprietary and each Tracer can handle it as it wants. + +## Mock implementation + +OpenTracing PHP comes with a mock implementation, it has three purposes: + +1. Helps to iron the API. +2. Works as a reference implementation. +3. Enhances vendor agnostic unit testing as it allows developers to inspect the tracing objects +in order to do assertions about them. + +## Coding Style + +OpenTracing PHP follows the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) +coding standard and the [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md) autoloading standard. + +## License + +All the open source contributions are under the terms of the [Apache-2.0 License](https://opensource.org/licenses/Apache-2.0). diff --git a/vendor/opentracing/opentracing/composer.json b/vendor/opentracing/opentracing/composer.json new file mode 100644 index 000000000..b00b67381 --- /dev/null +++ b/vendor/opentracing/opentracing/composer.json @@ -0,0 +1,44 @@ +{ + "name": "opentracing/opentracing", + "type": "library", + "description": "OpenTracing API for PHP", + "license": "Apache-2.0", + "minimum-stability": "stable", + "authors": [ + { + "name": "José Carlos Chávez", + "email": "[email protected]" + } + ], + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "~0.12", + "phpunit/phpunit": "^7.0 || ^9.0", + "squizlabs/php_codesniffer": "3.*" + }, + "config": { + "sort-packages": true + }, + "autoload": { + "psr-4": { + "OpenTracing\\": "src/OpenTracing/" + }, + "files": [ + "src/OpenTracing/Tags.php", + "src/OpenTracing/Formats.php" + ] + }, + "autoload-dev": { + "psr-4": { + "OpenTracing\\Tests\\": "tests/OpenTracing" + } + }, + "scripts": { + "fix-lint": "phpcbf --standard=ZEND --standard=PSR2 --ignore=*/vendor/* ./", + "lint": "phpcs --standard=ZEND --standard=PSR2 --ignore=*/vendor/* ./", + "test": "phpunit tests", + "static-check": "phpstan analyse" + } +} diff --git a/vendor/opentracing/opentracing/phpstan.neon b/vendor/opentracing/opentracing/phpstan.neon new file mode 100644 index 000000000..c9e64bf1f --- /dev/null +++ b/vendor/opentracing/opentracing/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + paths: + - src + + level: 5 diff --git a/vendor/opentracing/opentracing/phpunit.xml b/vendor/opentracing/opentracing/phpunit.xml new file mode 100644 index 000000000..2083a425c --- /dev/null +++ b/vendor/opentracing/opentracing/phpunit.xml @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" + backupGlobals="true" + backupStaticAttributes="false" + bootstrap="./vendor/autoload.php" + colors="false" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + forceCoversAnnotation="false" + processIsolation="false" + stopOnError="false" + stopOnFailure="false" + stopOnIncomplete="false" + stopOnSkipped="false" + stopOnRisky="false" + timeoutForSmallTests="1" + timeoutForMediumTests="10" + timeoutForLargeTests="60" + verbose="false"> + <testsuites> + <testsuite name="suite"> + <directory>tests</directory> + </testsuite> + </testsuites> +</phpunit> diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Formats.php b/vendor/opentracing/opentracing/src/OpenTracing/Formats.php new file mode 100644 index 000000000..f26c5ecf1 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Formats.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Formats; + +/** + * Used a (single) arbitrary binary blob representing a SpanContext + * + * For both Tracer::inject() and Tracer::extract() the carrier must be a `string`. + */ +const BINARY = 'binary'; + +/** + * Used for an arbitrary string-to-string map with an unrestricted character set for both keys and values + * + * Unlike `HTTP_HEADERS`, the `TEXT_MAP` format does not restrict the key or + * value character sets in any way. + * + * For both Tracer::inject() and Tracer::extract() the carrier must be a `array|ArrayObject`. + */ +const TEXT_MAP = 'text_map'; + +/** + * Used for a string-to-string map with keys and values that are suitable for use in HTTP headers (a la RFC 7230. + * In practice, since there is such "diversity" in the way that HTTP headers are treated in the wild, it is strongly + * recommended that Tracer implementations use a limited HTTP header key space and escape values conservatively. + * + * Unlike `TEXT_MAP`, the `HTTP_HEADERS` format requires that the keys and values be valid as HTTP headers as-is + * (i.e., character casing may be unstable and special characters are disallowed in keys, values should be + * URL-escaped, etc). + * + * For both Tracer::inject() and Tracer::extract() the carrier must be a `array|ArrayObject`. + * + * For example, Tracer::inject(): + * + * $headers = [] + * $tracer->inject($span->getContext(), Formats\HTTP_HEADERS, $headers) + * $request = new GuzzleHttp\Psr7\Request($uri, $body, $headers); + * + * Or Tracer::extract(): + * + * $headers = $request->getHeaders() + * $clientContext = $tracer->extract(Formats\HTTP_HEADERS, $headers) + * + * @see http://www.php-fig.org/psr/psr-7/#12-http-headers + * @see http://php.net/manual/en/function.getallheaders.php + */ +const HTTP_HEADERS = 'http_headers'; diff --git a/vendor/opentracing/opentracing/src/OpenTracing/GlobalTracer.php b/vendor/opentracing/opentracing/src/OpenTracing/GlobalTracer.php new file mode 100644 index 000000000..aafdba121 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/GlobalTracer.php @@ -0,0 +1,60 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class GlobalTracer +{ + /** + * @var Tracer + */ + private static $instance; + + /** + * @var bool + */ + private static $isRegistered = false; + + /** + * GlobalTracer::set sets the [singleton] Tracer returned by get(). + * Those who use GlobalTracer (rather than directly manage a Tracer instance) + * should call GlobalTracer::set as early as possible in bootstrap, prior to + * start a new span. Prior to calling GlobalTracer::set, any Spans started + * via the `Tracer::startActiveSpan` (etc) globals are noops. + * + * @param Tracer $tracer + * @return void + */ + public static function set(Tracer $tracer): void + { + self::$instance = $tracer; + self::$isRegistered = true; + } + + /** + * GlobalTracer::get returns the global singleton `Tracer` implementation. + * Before `GlobalTracer::set` is called, the `GlobalTracer::get` is a noop + * implementation that drops all data handed to it. + * + * @return Tracer + */ + public static function get(): Tracer + { + if (self::$instance === null) { + self::$instance = new NoopTracer(); + } + + return self::$instance; + } + + /** + * Returns true if a global tracer has been registered, otherwise returns false. + * + * @return bool + */ + public static function isRegistered(): bool + { + return self::$isRegistered; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferenceArgumentException.php b/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferenceArgumentException.php new file mode 100644 index 000000000..128360393 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferenceArgumentException.php @@ -0,0 +1,33 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use InvalidArgumentException; + +/** + * Thrown when passing an invalid argument for a reference + */ +final class InvalidReferenceArgumentException extends InvalidArgumentException +{ + /** + * @return InvalidReferenceArgumentException + */ + public static function forEmptyType(): InvalidReferenceArgumentException + { + return new self('Reference type can not be an empty string'); + } + + /** + * @param mixed $context + * @return InvalidReferenceArgumentException + */ + public static function forInvalidContext($context): InvalidReferenceArgumentException + { + return new self(sprintf( + 'Reference expects \OpenTracing\Span or \OpenTracing\SpanContext as context, got %s', + is_object($context) ? get_class($context) : gettype($context) + )); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferencesSetException.php b/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferencesSetException.php new file mode 100644 index 000000000..de7d907c8 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/InvalidReferencesSetException.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use DomainException; + +/** + * Thrown when a reference has more than one parent in the SpanOptions + */ +final class InvalidReferencesSetException extends DomainException +{ + /** + * @param string $message + * @return InvalidReferencesSetException + */ + public static function create(string $message): InvalidReferencesSetException + { + return new self($message); + } + + /** + * @return InvalidReferencesSetException + */ + public static function forMoreThanOneParent(): InvalidReferencesSetException + { + return new self('Span can not have more than one parent, either one as child_of or either one as follows_from'); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/InvalidSpanOptionException.php b/vendor/opentracing/opentracing/src/OpenTracing/InvalidSpanOptionException.php new file mode 100644 index 000000000..f9b8003ff --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/InvalidSpanOptionException.php @@ -0,0 +1,131 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use InvalidArgumentException; + +/** + * Thrown when passing an invalid option on Span creation + */ +final class InvalidSpanOptionException extends InvalidArgumentException +{ + /** + * @return InvalidSpanOptionException + */ + public static function forIncludingBothChildOfAndReferences(): InvalidSpanOptionException + { + return new self('Either "childOf" or "references" options are accepted but not both.'); + } + + /** + * @param mixed $reference + * @return InvalidSpanOptionException + */ + public static function forInvalidReference($reference): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid reference. Expected OpenTracing\Reference, got %s.', + is_object($reference) ? get_class($reference) : gettype($reference) + )); + } + + /** + * @return InvalidSpanOptionException + */ + public static function forInvalidStartTime(): InvalidSpanOptionException + { + return new self('Invalid start_time option. Expected int or float got string.'); + } + + /** + * @param mixed $childOfOption + * @return InvalidSpanOptionException + */ + public static function forInvalidChildOf($childOfOption): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid child_of option. Expected Span or SpanContext, got %s', + is_object($childOfOption) ? get_class($childOfOption) : gettype($childOfOption) + )); + } + + /** + * @param string $key + * @return InvalidSpanOptionException + */ + public static function forUnknownOption(string $key): InvalidSpanOptionException + { + return new self(sprintf('Invalid option %s.', $key)); + } + + /** + * @param mixed $tag + * @return InvalidSpanOptionException + */ + public static function forInvalidTag($tag): InvalidSpanOptionException + { + return new self(sprintf('Invalid tag. Expected string, got %s', gettype($tag))); + } + + /** + * @param mixed $tagValue + * @return InvalidSpanOptionException + */ + public static function forInvalidTagValue($tagValue): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid tag value. Expected scalar or object with __toString method, got %s', + is_object($tagValue) ? get_class($tagValue) : gettype($tagValue) + )); + } + + /** + * @param mixed $value + * @return InvalidSpanOptionException + */ + public static function forInvalidTags($value): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid tags value. Expected a associative array of tags, got %s', + is_object($value) ? get_class($value) : gettype($value) + )); + } + + /** + * @param mixed $value + * @return InvalidSpanOptionException + */ + public static function forInvalidReferenceSet($value): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid references set. Expected Reference or Reference[], got %s', + is_object($value) ? get_class($value) : gettype($value) + )); + } + + /** + * @param mixed $value + * @return InvalidSpanOptionException + */ + public static function forFinishSpanOnClose($value): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid type for finish_span_on_close. Expected bool, got %s', + is_object($value) ? get_class($value) : gettype($value) + )); + } + + /** + * @param mixed $value + * @return InvalidSpanOptionException + */ + public static function forIgnoreActiveSpan($value): InvalidSpanOptionException + { + return new self(sprintf( + 'Invalid type for ignore_active_span. Expected bool, got %s', + is_object($value) ? get_class($value) : gettype($value) + )); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScope.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScope.php new file mode 100644 index 000000000..a814b45b5 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScope.php @@ -0,0 +1,62 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\Scope; +use OpenTracing\Span; + +final class MockScope implements Scope +{ + /** + * @var Span + */ + private $span; + + /** + * @var MockScopeManager + */ + private $scopeManager; + + /** + * @var bool + */ + private $finishSpanOnClose; + + /** + * @param MockScopeManager $scopeManager + * @param Span $span + * @param bool $finishSpanOnClose + */ + public function __construct( + MockScopeManager $scopeManager, + Span $span, + bool $finishSpanOnClose + ) { + $this->scopeManager = $scopeManager; + $this->span = $span; + $this->finishSpanOnClose = $finishSpanOnClose; + } + + /** + * {@inheritdoc} + */ + public function close(): void + { + if ($this->finishSpanOnClose) { + $this->span->finish(); + } + + $this->scopeManager->deactivate($this); + } + + /** + * {@inheritdoc} + * @return Span|MockSpan + */ + public function getSpan(): Span + { + return $this->span; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScopeManager.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScopeManager.php new file mode 100644 index 000000000..c75c71942 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockScopeManager.php @@ -0,0 +1,49 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\Scope; +use OpenTracing\ScopeManager; +use OpenTracing\Span; + +final class MockScopeManager implements ScopeManager +{ + /** + * @var Scope[] + */ + private $scopes = []; + + /** + * {@inheritdoc} + */ + public function activate(Span $span, bool $finishSpanOnClose = ScopeManager::DEFAULT_FINISH_SPAN_ON_CLOSE): Scope + { + $scope = new MockScope($this, $span, $finishSpanOnClose); + $this->scopes[] = $scope; + + return $scope; + } + + /** + * {@inheritdoc} + */ + public function getActive(): ?Scope + { + if (empty($this->scopes)) { + return null; + } + + return $this->scopes[count($this->scopes) - 1]; + } + + public function deactivate(MockScope $scope): void + { + foreach ($this->scopes as $scopeIndex => $scopeItem) { + if ($scope === $scopeItem) { + unset($this->scopes[$scopeIndex]); + } + } + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpan.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpan.php new file mode 100644 index 000000000..db53649bf --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpan.php @@ -0,0 +1,145 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\Span; +use OpenTracing\SpanContext; + +final class MockSpan implements Span +{ + /** + * @var string + */ + private $operationName; + + /** + * @var SpanContext + */ + private $context; + + /** + * @var array + */ + private $tags = []; + + /** + * @var array + */ + private $logs = []; + + /** + * @var int + */ + private $startTime; + + /** + * @var int|null + */ + private $duration; + + public function __construct( + string $operationName, + SpanContext $context, + ?int $startTime = null + ) { + $this->operationName = $operationName; + $this->context = $context; + $this->startTime = $startTime ?: time(); + } + + /** + * {@inheritdoc} + */ + public function getOperationName(): string + { + return $this->operationName; + } + + /** + * {@inheritdoc} + * @return SpanContext|MockSpanContext + */ + public function getContext(): SpanContext + { + return $this->context; + } + + public function getStartTime(): ?int + { + return $this->startTime; + } + + /** + * {@inheritdoc} + */ + public function finish($finishTime = null): void + { + $finishTime = ($finishTime ?: time()); + $this->duration = $finishTime - $this->startTime; + } + + public function isFinished(): bool + { + return $this->duration !== null; + } + + public function getDuration(): ?int + { + return $this->duration; + } + + /** + * {@inheritdoc} + */ + public function overwriteOperationName(string $newOperationName): void + { + $this->operationName = (string)$newOperationName; + } + + /** + * {@inheritdoc} + */ + public function setTag(string $key, $value): void + { + $this->tags[$key] = $value; + } + + public function getTags(): array + { + return $this->tags; + } + + /** + * {@inheritdoc} + */ + public function log(array $fields = [], $timestamp = null): void + { + $this->logs[] = [ + 'timestamp' => $timestamp ?: time(), + 'fields' => $fields, + ]; + } + + public function getLogs(): array + { + return $this->logs; + } + + /** + * {@inheritdoc} + */ + public function addBaggageItem(string $key, string $value): void + { + $this->context = $this->context->withBaggageItem($key, $value); + } + + /** + * {@inheritdoc} + */ + public function getBaggageItem(string $key): ?string + { + return $this->context->getBaggageItem($key); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpanContext.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpanContext.php new file mode 100644 index 000000000..d094ea0e0 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockSpanContext.php @@ -0,0 +1,100 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\SpanContext; +use ArrayIterator; + +final class MockSpanContext implements SpanContext +{ + /** + * @var int + */ + private $traceId; + + /** + * @var int + */ + private $spanId; + + /** + * @var bool + */ + private $isSampled; + + /** + * @var array + */ + private $items; + + private function __construct(int $traceId, int $spanId, bool $isSampled, array $items) + { + $this->traceId = $traceId; + $this->spanId = $spanId; + $this->isSampled = $isSampled; + $this->items = $items; + } + + public static function create(int $traceId, int $spanId, bool $sampled = true, array $items = []): SpanContext + { + return new self($traceId, $spanId, $sampled, $items); + } + + public static function createAsRoot(bool $sampled = true, array $items = []): SpanContext + { + $traceId = $spanId = self::nextId(); + return new self($traceId, $spanId, $sampled, $items); + } + + public static function createAsChildOf(MockSpanContext $spanContext): SpanContext + { + $spanId = self::nextId(); + return new self($spanContext->traceId, $spanId, $spanContext->isSampled, $spanContext->items); + } + + public function getTraceId(): int + { + return $this->traceId; + } + + public function getSpanId(): int + { + return $this->spanId; + } + + public function isSampled(): bool + { + return $this->isSampled; + } + + /** + * {@inheritdoc} + */ + public function getIterator(): ArrayIterator + { + return new ArrayIterator($this->items); + } + + /** + * {@inheritdoc} + */ + public function getBaggageItem(string $key): ?string + { + return array_key_exists($key, $this->items) ? $this->items[$key] : null; + } + + /** + * {@inheritdoc} + */ + public function withBaggageItem(string $key, string $value): SpanContext + { + return new self($this->traceId, $this->spanId, $this->isSampled, array_merge($this->items, [$key => $value])); + } + + private static function nextId(): int + { + return mt_rand(0, 99999); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockTracer.php b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockTracer.php new file mode 100644 index 000000000..f4f4577a1 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Mock/MockTracer.php @@ -0,0 +1,152 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Mock; + +use OpenTracing\InvalidReferenceArgumentException; +use OpenTracing\UnsupportedFormatException; +use OpenTracing\Scope; +use OpenTracing\ScopeManager; +use OpenTracing\Span; +use OpenTracing\SpanContext; +use OpenTracing\StartSpanOptions; +use OpenTracing\Tracer; + +final class MockTracer implements Tracer +{ + /** + * @var array|MockSpan[] + */ + private $spans = []; + + /** + * @var array|callable[] + */ + private $injectors; + + /** + * @var array|callable[] + */ + private $extractors; + + /** + * @var ScopeManager + */ + private $scopeManager; + + public function __construct(array $injectors = [], array $extractors = []) + { + $this->injectors = $injectors; + $this->extractors = $extractors; + $this->scopeManager = new MockScopeManager(); + } + + /** + * {@inheritdoc} + */ + public function startActiveSpan(string $operationName, $options = []): Scope + { + if (!($options instanceof StartSpanOptions)) { + $options = StartSpanOptions::create($options); + } + + if (($activeSpan = $this->getActiveSpan()) !== null) { + $options = $options->withParent($activeSpan); + } + + $span = $this->startSpan($operationName, $options); + + return $this->scopeManager->activate($span, $options->shouldFinishSpanOnClose()); + } + + /** + * {@inheritdoc} + */ + public function startSpan(string $operationName, $options = []): Span + { + if (!($options instanceof StartSpanOptions)) { + $options = StartSpanOptions::create($options); + } + + if (empty($options->getReferences())) { + $spanContext = MockSpanContext::createAsRoot(); + } else { + $referenceContext = $options->getReferences()[0]->getSpanContext(); + if (!$referenceContext instanceof MockSpanContext) { + throw InvalidReferenceArgumentException::forInvalidContext($referenceContext); + } + $spanContext = MockSpanContext::createAsChildOf($referenceContext); + } + + $span = new MockSpan($operationName, $spanContext, $options->getStartTime()); + + foreach ($options->getTags() as $key => $value) { + $span->setTag($key, $value); + } + + $this->spans[] = $span; + + return $span; + } + + /** + * {@inheritdoc} + */ + public function inject(SpanContext $spanContext, string $format, &$carrier): void + { + if (!array_key_exists($format, $this->injectors)) { + throw UnsupportedFormatException::forFormat($format); + } + + $this->injectors[$format]($spanContext, $carrier); + } + + /** + * {@inheritdoc} + */ + public function extract(string $format, $carrier): ?SpanContext + { + if (!array_key_exists($format, $this->extractors)) { + throw UnsupportedFormatException::forFormat($format); + } + + return $this->extractors[$format]($carrier); + } + + /** + * {@inheritdoc} + */ + public function flush(): void + { + $this->spans = []; + } + + /** + * @return array|MockSpan[] + */ + public function getSpans(): array + { + return $this->spans; + } + + /** + * {@inheritdoc} + */ + public function getScopeManager(): ScopeManager + { + return $this->scopeManager; + } + + /** + * {@inheritdoc} + */ + public function getActiveSpan(): ?Span + { + if (null !== ($activeScope = $this->scopeManager->getActive())) { + return $activeScope->getSpan(); + } + + return null; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopScope.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopScope.php new file mode 100644 index 000000000..7170c846a --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopScope.php @@ -0,0 +1,23 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class NoopScope implements Scope +{ + /** + * {@inheritdoc} + */ + public function close(): void + { + } + + /** + * {@inheritdoc} + */ + public function getSpan(): Span + { + return new NoopSpan(); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopScopeManager.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopScopeManager.php new file mode 100644 index 000000000..5576171a8 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopScopeManager.php @@ -0,0 +1,24 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class NoopScopeManager implements ScopeManager +{ + /** + * {@inheritdoc} + */ + public function activate(Span $span, bool $finishSpanOnClose = ScopeManager::DEFAULT_FINISH_SPAN_ON_CLOSE): Scope + { + return new NoopScope(); + } + + /** + * {@inheritdoc} + */ + public function getActive(): ?Scope + { + return new NoopScope(); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopSpan.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopSpan.php new file mode 100644 index 000000000..c1af8dfc7 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopSpan.php @@ -0,0 +1,67 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class NoopSpan implements Span +{ + /** + * {@inheritdoc} + */ + public function getOperationName(): string + { + return 'noop_span'; + } + + /** + * {@inheritdoc} + */ + public function getContext(): SpanContext + { + return new NoopSpanContext(); + } + + /** + * {@inheritdoc} + */ + public function finish($finishTime = null): void + { + } + + /** + * {@inheritdoc} + */ + public function overwriteOperationName(string $newOperationName): void + { + } + + /** + * {@inheritdoc} + */ + public function setTag(string $key, $value): void + { + } + + /** + * {@inheritdoc} + */ + public function log(array $fields = [], $timestamp = null): void + { + } + + /** + * {@inheritdoc} + */ + public function addBaggageItem(string $key, string $value): void + { + } + + /** + * {@inheritdoc} + */ + public function getBaggageItem(string $key): ?string + { + return null; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopSpanContext.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopSpanContext.php new file mode 100644 index 000000000..5b0de7c93 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopSpanContext.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use EmptyIterator; +use Traversable; + +final class NoopSpanContext implements SpanContext +{ + /** + * {@inheritdoc} + */ + public function getIterator(): Traversable + { + return new EmptyIterator(); + } + + /** + * {@inheritdoc} + */ + public function getBaggageItem(string $key): ?string + { + return null; + } + + /** + * {@inheritdoc} + */ + public function withBaggageItem(string $key, string $value): SpanContext + { + return new self(); + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/NoopTracer.php b/vendor/opentracing/opentracing/src/OpenTracing/NoopTracer.php new file mode 100644 index 000000000..267823bb9 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/NoopTracer.php @@ -0,0 +1,62 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +final class NoopTracer implements Tracer +{ + /** + * {@inheritdoc} + */ + public function getActiveSpan(): ?Span + { + return new NoopSpan(); + } + + /** + * {@inheritdoc} + */ + public function getScopeManager(): ScopeManager + { + return new NoopScopeManager(); + } + + /** + * {@inheritdoc} + */ + public function startSpan(string $operationName, $options = []): Span + { + return new NoopSpan(); + } + + /** + * {@inheritdoc} + */ + public function startActiveSpan(string $operationName, $options = []): Scope + { + return new NoopScope(); + } + + /** + * {@inheritdoc} + */ + public function inject(SpanContext $spanContext, string $format, &$carrier): void + { + } + + /** + * {@inheritdoc} + */ + public function extract(string $format, $carrier): ?SpanContext + { + return new NoopSpanContext(); + } + + /** + * {@inheritdoc} + */ + public function flush(): void + { + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Reference.php b/vendor/opentracing/opentracing/src/OpenTracing/Reference.php new file mode 100644 index 000000000..7dadf1785 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Reference.php @@ -0,0 +1,77 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use OpenTracing\InvalidReferenceArgumentException; + +final class Reference +{ + /** + * A Span may be the ChildOf a parent Span. In a ChildOf reference, + * the parent Span depends on the child Span in some capacity. + */ + public const CHILD_OF = 'child_of'; + + /** + * Some parent Spans do not depend in any way on the result of their + * child Spans. In these cases, we say merely that the child Span + * FollowsFrom the parent Span in a causal sense. + */ + public const FOLLOWS_FROM = 'follows_from'; + + /** + * @var string + */ + private $type; + + /** + * @var SpanContext + */ + private $spanContext; + + /** + * @param string $type + * @param SpanContext $spanContext + */ + public function __construct(string $type, SpanContext $spanContext) + { + if (empty($type)) { + throw InvalidReferenceArgumentException::forEmptyType(); + } + + $this->type = $type; + $this->spanContext = $spanContext; + } + + /** + * @param string $type + * @param Span $span + * @return Reference when context is invalid + * @throws InvalidReferenceArgumentException on empty type + */ + public static function createForSpan(string $type, Span $span): Reference + { + return new self($type, $span->getContext()); + } + + /** + * @return SpanContext + */ + public function getSpanContext(): SpanContext + { + return $this->spanContext; + } + + /** + * Checks whether a Reference is of one type. + * + * @param string $type the type for the reference + * @return bool + */ + public function isType(string $type): bool + { + return $this->type === $type; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Scope.php b/vendor/opentracing/opentracing/src/OpenTracing/Scope.php new file mode 100644 index 000000000..174495434 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Scope.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +/** + * A {@link Scope} formalizes the activation and deactivation of a {@link Span}, usually from a CPU standpoint. + * + * Many times a {@link Span} will be extant (in that {@link Span#finish()} has not been called) despite being in a + * non-runnable state from a CPU/scheduler standpoint. For instance, a {@link Span} representing the client side of an + * RPC will be unfinished but blocked on IO while the RPC is still outstanding. A {@link Scope} defines when a given + * {@link Span} <em>is</em> scheduled and on the path. + */ +interface Scope +{ + /** + * Mark the end of the active period for the current thread and {@link Scope}, + * updating the {@link ScopeManager#active()} in the process. + * + * NOTE: Calling {@link #close} more than once on a single {@link Scope} instance leads to undefined + * behavior. + * + * @return void + */ + public function close(): void; + + /** + * @return Span the {@link Span} that's been scoped by this {@link Scope} + */ + public function getSpan(): Span; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/ScopeManager.php b/vendor/opentracing/opentracing/src/OpenTracing/ScopeManager.php new file mode 100644 index 000000000..db5fcaa47 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/ScopeManager.php @@ -0,0 +1,40 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +/** + * Keeps track of the current active `Span`. + */ +interface ScopeManager +{ + public const DEFAULT_FINISH_SPAN_ON_CLOSE = true; + + /** + * Activates an `Span`, so that it is used as a parent when creating new spans. + * The implementation must keep track of the active spans sequence, so + * that previous spans can be resumed after a deactivation. + * + * @param Span $span the {@link Span} that should become the {@link #active()} + * @param bool $finishSpanOnClose whether span should automatically be finished + * when {@link Scope#close()} is called. Its default value is true. + * + * @return Scope instance to control the end of the active period for the {@link Span}. It is a + * programming error to neglect to call {@link Scope#close()} on the returned instance. + */ + public function activate(Span $span, bool $finishSpanOnClose = self::DEFAULT_FINISH_SPAN_ON_CLOSE): Scope; + + /** + * Return the currently active {@link Scope} which can be used to access the + * currently active {@link Scope#getSpan()}. + * + * If there is an {@link Scope non-null scope}, its wrapped {@link Span} becomes an implicit parent + * (as {@link References#CHILD_OF} reference) of any + * newly-created {@link Span} at {@link Tracer.SpanBuilder#startActive(boolean)} or {@link SpanBuilder#start()} + * time rather than at {@link Tracer#buildSpan(String)} time. + * + * @return Scope|null + */ + public function getActive(): ?Scope; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Span.php b/vendor/opentracing/opentracing/src/OpenTracing/Span.php new file mode 100644 index 000000000..9fa8c2bc2 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Span.php @@ -0,0 +1,95 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use DateTimeInterface; + +interface Span +{ + /** + * @return string + */ + public function getOperationName(): string; + + /** + * Yields the SpanContext for this Span. Note that the return value of + * Span::getContext() is still valid after a call to Span::finish(), as is + * a call to Span::getContext() after a call to Span::finish(). + * + * @return SpanContext + */ + public function getContext(): SpanContext; + + /** + * Sets the end timestamp and finalizes Span state. + * + * With the exception of calls to getContext() (which are always allowed), + * finish() must be the last call made to any span instance, and to do + * otherwise leads to undefined behavior but not returning an exception. + * + * As an implementor, make sure you call {@see Tracer::deactivate()} + * otherwise new spans might try to be child of this one. + * + * If the span is already finished, a warning should be logged. + * + * @param float|int|DateTimeInterface|null $finishTime if passing float or int + * it should represent the timestamp (including as many decimal places as you need) + * @return void + */ + public function finish($finishTime = null): void; + + /** + * If the span is already finished, a warning should be logged. + * + * @param string $newOperationName + * @return void + */ + public function overwriteOperationName(string $newOperationName): void; + + /** + * Adds a tag to the span. + * + * If there is a pre-existing tag set for key, it is overwritten. + * + * As an implementor, consider using "standard tags" listed in {@see \OpenTracing\Tags} + * + * If the span is already finished, a warning should be logged. + * + * @param string $key + * @param string|bool|int|float $value + * @return void + */ + public function setTag(string $key, $value): void; + + /** + * Adds a log record to the span in key => value format, key must be a string and tag must be either + * a string, a boolean value, or a numeric type. + * + * If the span is already finished, a warning should be logged. + * + * @param array $fields + * @param int|float|DateTimeInterface $timestamp + * @return void + */ + public function log(array $fields = [], $timestamp = null): void; + + /** + * Adds a baggage item to the SpanContext which is immutable so it is required to use + * SpanContext::withBaggageItem to get a new one. + * + * If the span is already finished, a warning should be logged. + * + * @param string $key + * @param string $value + * @return void + */ + public function addBaggageItem(string $key, string $value): void; + + /** + * @param string $key + * @return string|null returns null when there is not a item under the provided key + */ + public function getBaggageItem(string $key): ?string; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/SpanContext.php b/vendor/opentracing/opentracing/src/OpenTracing/SpanContext.php new file mode 100644 index 000000000..ca05ff9ac --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/SpanContext.php @@ -0,0 +1,37 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use IteratorAggregate; + +/** + * SpanContext must be immutable in order to avoid complicated lifetime + * issues around Span finish and references. + * + * Baggage items are key => value string pairs that apply to the given Span, + * its SpanContext, and all Spans which directly or transitively reference + * the local Span. That is, baggage items propagate in-band along with the + * trace itself. + */ +interface SpanContext extends IteratorAggregate +{ + /** + * Returns the value of a baggage item based on its key. If there is no + * value with such key it will return null. + * + * @param string $key + * @return string|null + */ + public function getBaggageItem(string $key): ?string; + + /** + * Creates a new SpanContext out of the existing one and the new key => value pair. + * + * @param string $key + * @param string $value + * @return SpanContext + */ + public function withBaggageItem(string $key, string $value): SpanContext; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/StartSpanOptions.php b/vendor/opentracing/opentracing/src/OpenTracing/StartSpanOptions.php new file mode 100644 index 000000000..28b73ff0a --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/StartSpanOptions.php @@ -0,0 +1,206 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use DateTime; +use DateTimeInterface; +use OpenTracing\InvalidReferencesSetException; +use OpenTracing\InvalidSpanOptionException; + +final class StartSpanOptions +{ + /** + * @var Reference[] + */ + private $references = []; + + /** + * @var array + */ + private $tags = []; + + /** + * @var int|float|DateTimeInterface + */ + private $startTime; + + /** + * Only used for spans that are actively managed by scope manager. + * + * @var bool + */ + private $finishSpanOnClose = ScopeManager::DEFAULT_FINISH_SPAN_ON_CLOSE; + + /** + * @var bool + */ + private $ignoreActiveSpan = false; + + /** + * @param array $options + * @return StartSpanOptions + * @throws InvalidReferencesSetException when there are inconsistencies about the references + * @throws InvalidSpanOptionException when one of the options is invalid + */ + public static function create(array $options): StartSpanOptions + { + $spanOptions = new self(); + + foreach ($options as $key => $value) { + switch ($key) { + case 'child_of': + if (!empty($spanOptions->references)) { + throw InvalidSpanOptionException::forIncludingBothChildOfAndReferences(); + } + + $spanOptions->references[] = self::buildChildOf($value); + break; + + case 'references': + if (!empty($spanOptions->references)) { + throw InvalidSpanOptionException::forIncludingBothChildOfAndReferences(); + } + + if ($value instanceof Reference) { + $spanOptions->references = [$value]; + } elseif (is_array($value)) { + $spanOptions->references = self::buildReferences($value); + } else { + throw InvalidSpanOptionException::forInvalidReferenceSet($value); + } + + break; + + case 'tags': + if (!is_array($value)) { + throw InvalidSpanOptionException::forInvalidTags($value); + } + + foreach ($value as $tag => $tagValue) { + if ($tag !== (string)$tag) { + throw InvalidSpanOptionException::forInvalidTag($tag); + } + + $spanOptions->tags[$tag] = $tagValue; + } + break; + + case 'start_time': + if (is_scalar($value) && !is_numeric($value)) { + throw InvalidSpanOptionException::forInvalidStartTime(); + } + + $spanOptions->startTime = $value; + break; + + case 'finish_span_on_close': + if (!is_bool($value)) { + throw InvalidSpanOptionException::forFinishSpanOnClose($value); + } + + $spanOptions->finishSpanOnClose = $value; + break; + + case 'ignore_active_span': + if (!is_bool($value)) { + throw InvalidSpanOptionException::forIgnoreActiveSpan($value); + } + + $spanOptions->ignoreActiveSpan = $value; + break; + + default: + throw InvalidSpanOptionException::forUnknownOption($key); + } + } + + return $spanOptions; + } + + /** + * @param Span|SpanContext $parent + * @return StartSpanOptions + */ + public function withParent($parent): StartSpanOptions + { + $newSpanOptions = new StartSpanOptions(); + $newSpanOptions->references[] = self::buildChildOf($parent); + $newSpanOptions->tags = $this->tags; + $newSpanOptions->startTime = $this->startTime; + $newSpanOptions->finishSpanOnClose = $this->finishSpanOnClose; + $newSpanOptions->ignoreActiveSpan = $this->ignoreActiveSpan; + + return $newSpanOptions; + } + + /** + * @return Reference[] + */ + public function getReferences(): array + { + return $this->references; + } + + /** + * @return array + */ + public function getTags(): array + { + return $this->tags; + } + + /** + * @return int|float|DateTime|null if returning float or int it should represent + * the timestamp (including as many decimal places as you need) + */ + public function getStartTime() + { + return $this->startTime; + } + + /** + * @return bool + */ + public function shouldFinishSpanOnClose(): bool + { + return $this->finishSpanOnClose; + } + + /** + * @return bool + */ + public function shouldIgnoreActiveSpan(): bool + { + return $this->ignoreActiveSpan; + } + + private static function buildChildOf($value): Reference + { + if ($value instanceof Span) { + return Reference::createForSpan(Reference::CHILD_OF, $value); + } + + if ($value instanceof SpanContext) { + return new Reference(Reference::CHILD_OF, $value); + } + + throw InvalidSpanOptionException::forInvalidChildOf($value); + } + + private static function buildReferences(array $referencesArray): array + { + $references = []; + + foreach ($referencesArray as $reference) { + if (!($reference instanceof Reference)) { + throw InvalidSpanOptionException::forInvalidReference($reference); + } + + $references[] = $reference; + } + + return $references; + } +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Tags.php b/vendor/opentracing/opentracing/src/OpenTracing/Tags.php new file mode 100644 index 000000000..5d06627de --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Tags.php @@ -0,0 +1,124 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Tags; + +/** + * SpanKind hints at relationship between spans, e.g. client/server + */ +const SPAN_KIND = 'span.kind'; + +/** + * Marks a span representing the client-side of an RPC or other remote call + */ +const SPAN_KIND_RPC_CLIENT = 'client'; + +/** + * Marks a span representing the server-side of an RPC or other remote call + */ +const SPAN_KIND_RPC_SERVER = 'server'; + +/** + * Marks a span as representing the producer within a messaging context + */ +const SPAN_KIND_MESSAGE_BUS_PRODUCER = 'producer'; + +/** + * Marks a span as representing the consumer within a messaging context + */ +const SPAN_KIND_MESSAGE_BUS_CONSUMER = 'consumer'; + +/** + * Component is a low-cardinality identifier of the module, library, + * or package that is generating a span. + */ +const COMPONENT = 'component'; + +/** + * SAMPLING_PRIORITY (uint16) determines the priority of sampling this Span. + */ +const SAMPLING_PRIORITY = 'sampling.priority'; + +/** + * PeerService records the service name of the peer + */ +const PEER_SERVICE = 'peer.service'; + +/** + * PeerHostname records the host name of the peer + */ +const PEER_HOSTNAME = 'peer.hostname'; + +/** + * PEER_ADDRESS (string) suitable for use in a networking client library. + * This may be a "ip:port", a bare "hostname", a FQDN, or even a # JDBC + * substring like "mysql://prod-db:3306" + */ +const PEER_ADDRESS = 'peer.address'; + +/** + * PEER_HOST_IPV4 (uint32) records IP v4 host address of the peer + */ +const PEER_HOST_IPV4 = 'peer.ipv4'; + +/** + * PEER_HOST_IPV6 (string) records IP v6 host address of the peer + */ +const PEER_HOST_IPV6 = 'peer.ipv6'; + +/** PEER_PORT (uint16) records port number of the peer */ +const PEER_PORT = 'peer.port'; + +/** + * HTTPUrl should be the URL of the request being handled in this segment + * of the trace, in standard URI format. The protocol is optional. + */ +const HTTP_URL = 'http.url'; + +/** + * HTTPMethod is the HTTP method of the request, and is case-insensitive. + */ +const HTTP_METHOD = 'http.method'; + +/** + * HTTPStatusCode is the numeric HTTP status code (200, 404, etc) of the + * HTTP response. + */ +const HTTP_STATUS_CODE = 'http.status_code'; + +/** + * DATABASE_INSTANCE (string) The database instance name. + */ +const DATABASE_INSTANCE = 'db.instance'; + +/** + * DATABASE_STATEMENT (string) A database statement for the given database + * type. E.g., for db.type="SQL", "SELECT * FROM user_table"; # for + * db.type="redis", "SET mykey 'WuValue'". */ +const DATABASE_STATEMENT = 'db.statement'; + +/** + * DATABASE_TYPE (string) For any SQL database, "sql". For others, the lower-case + * database category, e.g. "cassandra", "hbase", or "redis". + */ +const DATABASE_TYPE = 'db.type'; + +/** + * DATABASE_USER (string) Username for accessing database. E.g., "readonly_user" or + * "reporting_user" + */ +const DATABASE_USER = 'db.user'; + +/** + * MESSAGE_BUS_DESTINATION (string) An address at which messages can be # + * exchanged. E.g. A Kafka record has an associated "topic name" that can # + * be extracted by the instrumented producer or consumer and stored # using + * this tag. + */ +const MESSAGE_BUS_DESTINATION = 'message_bus.destination'; + +/** + * Error indicates that operation represented by the span resulted in an error. + */ +const ERROR = 'error'; diff --git a/vendor/opentracing/opentracing/src/OpenTracing/Tracer.php b/vendor/opentracing/opentracing/src/OpenTracing/Tracer.php new file mode 100644 index 000000000..391a5159b --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/Tracer.php @@ -0,0 +1,119 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use OpenTracing\UnsupportedFormatException; +use OpenTracing\InvalidSpanOptionException; +use OpenTracing\InvalidReferencesSetException; + +interface Tracer +{ + /** + * Returns the current {@link ScopeManager}, which may be a noop but may not be null. + * + * @return ScopeManager + */ + public function getScopeManager(): ScopeManager; + + /** + * Returns the active {@link Span}. This is a shorthand for + * Tracer::getScopeManager()->getActive()->getSpan(), + * and null will be returned if {@link Scope#active()} is null. + * + * @return Span|null + */ + public function getActiveSpan(): ?Span; + + /** + * Starts a new span that is activated on a scope manager. + * + * It's also possible to not finish the {@see \OpenTracing\Span} when + * {@see \OpenTracing\Scope} context expires: + * + * $scope = $tracer->startActiveSpan('...', [ + * 'finish_span_on_close' => false, + * ]); + * $span = $scope->getSpan(); + * try { + * $span->setTag(Tags\HTTP_METHOD, 'GET'); + * // ... + * } finally { + * $scope->close(); + * } + * // $span->finish() is not called as part of Scope deactivation as + * // finish_span_on_close is false + * + * @param string $operationName + * @param array|StartSpanOptions $options Same as for startSpan() with + * additional option of `finish_span_on_close` that enables finishing + * of span whenever a scope is closed. It is true by default. + * + * @return Scope A Scope that holds newly created Span and is activated on + * a ScopeManager. + */ + public function startActiveSpan(string $operationName, $options = []): Scope; + + /** + * Starts and returns a new span representing a unit of work. + * + * Whenever `child_of` reference is not passed then + * {@see \OpenTracing\ScopeManager::getActive()} span is used as `child_of` + * reference. In order to ignore implicit parent span pass in + * `ignore_active_span` option set to true. + * + * Starting a span with explicit parent: + * + * $tracer->startSpan('...', [ + * 'child_of' => $parentSpan, + * ]); + * + * @param string $operationName + * @param array|StartSpanOptions $options See StartSpanOptions for + * available options. + * + * @return Span + * + * @throws InvalidSpanOptionException for invalid option + * @throws InvalidReferencesSetException for invalid references set + * @see \OpenTracing\StartSpanOptions + */ + public function startSpan(string $operationName, $options = []): Span; + + /** + * @param SpanContext $spanContext + * @param string $format + * @param mixed $carrier + * @return void + * + * @throws UnsupportedFormatException when the format is not recognized by the tracer + * implementation + * @see Formats + */ + public function inject(SpanContext $spanContext, string $format, &$carrier): void; + + /** + * @param string $format + * @param mixed $carrier + * @return SpanContext|null + * + * @throws UnsupportedFormatException when the format is not recognized by the tracer + * implementation + * @see Formats + */ + public function extract(string $format, $carrier): ?SpanContext; + + /** + * Allow tracer to send span data to be instrumented. + * + * This method might not be needed depending on the tracing implementation + * but one should make sure this method is called after the request is delivered + * to the client. + * + * As an implementor, a good idea would be to use {@see register_shutdown_function} + * or {@see fastcgi_finish_request} in order to not to delay the end of the request + * to the client. + */ + public function flush(): void; +} diff --git a/vendor/opentracing/opentracing/src/OpenTracing/UnsupportedFormatException.php b/vendor/opentracing/opentracing/src/OpenTracing/UnsupportedFormatException.php new file mode 100644 index 000000000..dd4ef56a3 --- /dev/null +++ b/vendor/opentracing/opentracing/src/OpenTracing/UnsupportedFormatException.php @@ -0,0 +1,22 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing; + +use UnexpectedValueException; + +/** + * Thrown when trying to inject or extract in an invalid format + */ +final class UnsupportedFormatException extends UnexpectedValueException +{ + /** + * @param string $format + * @return UnsupportedFormatException + */ + public static function forFormat(string $format): UnsupportedFormatException + { + return new self(sprintf('The format "%s" is not supported.', $format)); + } +} diff --git a/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockScopeManagerTest.php b/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockScopeManagerTest.php new file mode 100644 index 000000000..eeca24497 --- /dev/null +++ b/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockScopeManagerTest.php @@ -0,0 +1,63 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Tests\Mock; + +use OpenTracing\Mock\MockScopeManager; +use OpenTracing\Mock\MockTracer; +use PHPUnit\Framework\TestCase; + +final class MockScopeManagerTest extends TestCase +{ + private const OPERATION_NAME = 'test_name'; + + public function testGetActiveFailsWithNoActiveSpans() + { + $scopeManager = new MockScopeManager(); + + $this->assertNull($scopeManager->getActive()); + } + + public function testActivateSuccess() + { + $tracer = new MockTracer(); + $span = $tracer->startSpan(self::OPERATION_NAME); + $scopeManager = new MockScopeManager(); + $scopeManager->activate($span); + + $this->assertSame($span, $scopeManager->getActive()->getSpan()); + } + + public function testGetScopeReturnsNull() + { + $tracer = new MockTracer(); + $tracer->startSpan(self::OPERATION_NAME); + $scopeManager = new MockScopeManager(); + + $this->assertNull($scopeManager->getActive()); + } + + public function testGetScopeSuccess() + { + $tracer = new MockTracer(); + $span = $tracer->startSpan(self::OPERATION_NAME); + $scopeManager = new MockScopeManager(); + $scopeManager->activate($span); + $scope = $scopeManager->getActive(); + + $this->assertSame($span, $scope->getSpan()); + } + + public function testDeactivateSuccess() + { + $tracer = new MockTracer(); + $span = $tracer->startSpan(self::OPERATION_NAME); + $scopeManager = new MockScopeManager(); + $scopeManager->activate($span); + $scope = $scopeManager->getActive(); + $scopeManager->deactivate($scope); + + $this->assertNull($scopeManager->getActive()); + } +} diff --git a/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockSpanContextTest.php b/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockSpanContextTest.php new file mode 100644 index 000000000..501450b24 --- /dev/null +++ b/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockSpanContextTest.php @@ -0,0 +1,54 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Tests\Mock; + +use OpenTracing\Mock\MockSpanContext; +use PHPUnit\Framework\TestCase; + +final class MockSpanContextTest extends TestCase +{ + private const TRACE_ID = 123987; + private const SPAN_ID = 555632; + private const IS_SAMPLED = true; + private const BAGGAGE_ITEM_KEY = 'test_key'; + private const BAGGAGE_ITEM_VALUE = 'test_value'; + + public function testCreateAsRootSuccess() + { + $parentContext = MockSpanContext::createAsRoot(); + $childContext = MockSpanContext::createAsChildOf($parentContext); + + $this->assertEquals($parentContext->getTraceId(), $childContext->getTraceId()); + } + + public function testCreateMockSpanContextSuccess() + { + $spanContext = MockSpanContext::create( + self::TRACE_ID, + self::SPAN_ID, + self::IS_SAMPLED, + [self::BAGGAGE_ITEM_KEY => self::BAGGAGE_ITEM_VALUE] + ); + + $this->assertEquals($spanContext->getTraceId(), self::TRACE_ID); + $this->assertEquals($spanContext->getSpanId(), self::SPAN_ID); + $this->assertEquals($spanContext->isSampled(), self::IS_SAMPLED); + $this->assertEquals([self::BAGGAGE_ITEM_KEY => self::BAGGAGE_ITEM_VALUE], iterator_to_array($spanContext)); + $this->assertEquals(self::BAGGAGE_ITEM_VALUE, $spanContext->getBaggageItem(self::BAGGAGE_ITEM_KEY)); + } + + public function testAddBaggageItemSuccess() + { + $spanContext = MockSpanContext::create( + self::TRACE_ID, + self::SPAN_ID, + self::IS_SAMPLED + ); + $this->assertEmpty(iterator_to_array($spanContext)); + + $spanContext = $spanContext->withBaggageItem(self::BAGGAGE_ITEM_KEY, self::BAGGAGE_ITEM_VALUE); + $this->assertEquals([self::BAGGAGE_ITEM_KEY => self::BAGGAGE_ITEM_VALUE], iterator_to_array($spanContext)); + } +} diff --git a/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockSpanTest.php b/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockSpanTest.php new file mode 100644 index 000000000..51e4b66f8 --- /dev/null +++ b/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockSpanTest.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Tests\Mock; + +use OpenTracing\Mock\MockSpan; +use OpenTracing\Mock\MockSpanContext; +use PHPUnit\Framework\TestCase; + +/** + * @covers MockSpan + */ +final class MockSpanTest extends TestCase +{ + private const OPERATION_NAME = 'test'; + private const DURATION = 10; + private const TAG_KEY = 'test_key'; + private const TAG_VALUE = 'test_value'; + private const LOG_FIELD = 'test_log'; + + public function testCreateSpanSuccess() + { + $startTime = time(); + $span = new MockSpan(self::OPERATION_NAME, MockSpanContext::createAsRoot(), $startTime); + + $this->assertEquals($startTime, $span->getStartTime()); + $this->assertEmpty($span->getTags()); + $this->assertEmpty($span->getLogs()); + } + + public function testAddTagsAndLogsToSpanSuccess() + { + $span = new MockSpan(self::OPERATION_NAME, MockSpanContext::createAsRoot()); + + $span->setTag(self::TAG_KEY, self::TAG_VALUE); + $span->log([self::LOG_FIELD]); + + $this->assertEquals([self::TAG_KEY => self::TAG_VALUE], $span->getTags()); + $this->assertEquals(self::LOG_FIELD, $span->getLogs()[0]['fields'][0]); + } + + public function testSpanIsFinished() + { + $startTime = time(); + $span = new MockSpan(self::OPERATION_NAME, MockSpanContext::createAsRoot(), $startTime); + $span->finish($startTime + self::DURATION); + + $this->assertTrue($span->isFinished()); + $this->assertEquals(self::DURATION, $span->getDuration()); + } +} diff --git a/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockTracerTest.php b/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockTracerTest.php new file mode 100644 index 000000000..ab2faf159 --- /dev/null +++ b/vendor/opentracing/opentracing/tests/OpenTracing/Mock/MockTracerTest.php @@ -0,0 +1,139 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Tests\Mock; + +use OpenTracing\InvalidReferenceArgumentException; +use OpenTracing\UnsupportedFormatException; +use OpenTracing\Mock\MockTracer; +use OpenTracing\NoopSpanContext; +use OpenTracing\Reference; +use OpenTracing\Span; +use OpenTracing\SpanContext; +use PHPUnit\Framework\TestCase; + +/** + * @covers MockTracer + */ +final class MockTracerTest extends TestCase +{ + private const OPERATION_NAME = 'test_name'; + private const FORMAT = 'test_format'; + + public function testStartActiveSpanSuccess() + { + $tracer = new MockTracer(); + $scope = $tracer->startActiveSpan(self::OPERATION_NAME); + $activeSpan = $tracer->getActiveSpan(); + + $this->assertEquals($scope->getSpan(), $activeSpan); + } + + public function testStartSpanSuccess() + { + $tracer = new MockTracer(); + $tracer->startSpan(self::OPERATION_NAME); + $activeSpan = $tracer->getActiveSpan(); + + $this->assertNull($activeSpan); + } + + public function testStartSpanWithReference(): void + { + $tracer = new MockTracer(); + $tracer->startSpan('parent_name'); + /** @var Span $parentSpan */ + $parentSpan = $tracer->getSpans()[0]; + $tracer->startSpan( + self::OPERATION_NAME, + ['references' => [Reference::createForSpan(Reference::CHILD_OF, $parentSpan)]] + ); + $activeSpan = $tracer->getActiveSpan(); + + self::assertNull($activeSpan); + } + + public function testStartSpanWithReferenceWithoutExpectedContextType(): void + { + $tracer = new MockTracer(); + $notAMockContext = new NoopSpanContext(); + + $this->expectException(InvalidReferenceArgumentException::class); + + $tracer->startSpan( + self::OPERATION_NAME, + ['references' => [new Reference(Reference::CHILD_OF, $notAMockContext)]] + ); + } + + public function testInjectWithNoInjectorsFails() + { + $tracer = new MockTracer(); + $span = $tracer->startSpan(self::OPERATION_NAME); + $carrier = []; + + $this->expectException(UnsupportedFormatException::class); + $tracer->inject($span->getContext(), self::FORMAT, $carrier); + } + + public function testInjectSuccess() + { + $actualSpanContext = null; + $actualCarrier = null; + + $injector = function ($spanContext, &$carrier) use (&$actualSpanContext, &$actualCarrier) { + $actualSpanContext = $spanContext; + $actualCarrier = $carrier; + }; + + $tracer = new MockTracer([self::FORMAT => $injector]); + $span = $tracer->startSpan(self::OPERATION_NAME); + $carrier = []; + $tracer->inject($span->getContext(), self::FORMAT, $carrier); + + $this->assertSame($span->getContext(), $actualSpanContext); + $this->assertSame($carrier, $actualCarrier); + } + + public function testExtractWithNoExtractorsFails() + { + $tracer = new MockTracer(); + $carrier = []; + + $this->expectException(UnsupportedFormatException::class); + $tracer->extract(self::FORMAT, $carrier); + } + + public function testExtractSuccess() + { + $actualSpanContext = null; + $actualCarrier = null; + + $extractor = function ($carrier) use (&$actualCarrier) { + $actualCarrier = $carrier; + return new NoopSpanContext(); + }; + + $tracer = new MockTracer([], [self::FORMAT => $extractor]); + $carrier = [ + 'TRACE_ID' => 'trace_id' + ]; + + $spanContext = $tracer->extract(self::FORMAT, $carrier); + + $this->assertInstanceOf(SpanContext::class, $spanContext); + } + + public function testFlushSuccess() + { + $tracer = new MockTracer(); + $tracer->startSpan(self::OPERATION_NAME); + + $this->assertCount(1, $tracer->getSpans()); + + $tracer->flush(); + + $this->assertCount(0, $tracer->getSpans()); + } +} diff --git a/vendor/opentracing/opentracing/tests/OpenTracing/ReferenceTest.php b/vendor/opentracing/opentracing/tests/OpenTracing/ReferenceTest.php new file mode 100644 index 000000000..cb971a20c --- /dev/null +++ b/vendor/opentracing/opentracing/tests/OpenTracing/ReferenceTest.php @@ -0,0 +1,45 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Tests; + +use TypeError; +use PHPUnit\Framework\TestCase; +use OpenTracing\Reference; +use OpenTracing\NoopSpanContext; +use OpenTracing\InvalidReferenceArgumentException; + +/** + * @covers Reference + */ +final class ReferenceTest extends TestCase +{ + const REFERENCE_TYPE = 'ref_type'; + + public function testCreateAReferenceFailsOnInvalidContext() + { + $context = 'invalid_context'; + + $this->expectException(TypeError::class); + new Reference('child_of', $context); + } + + public function testCreateAReferenceFailsOnEmptyType() + { + $context = new NoopSpanContext(); + + $this->expectException(InvalidReferenceArgumentException::class); + $this->expectExceptionMessage('Reference type can not be an empty string'); + new Reference('', $context); + } + + public function testAReferenceCanBeCreatedAsACustomType() + { + $context = new NoopSpanContext(); + $reference = new Reference(self::REFERENCE_TYPE, $context); + + $this->assertSame($context, $reference->getSpanContext()); + $this->assertTrue($reference->isType(self::REFERENCE_TYPE)); + } +} diff --git a/vendor/opentracing/opentracing/tests/OpenTracing/StartSpanOptionsTest.php b/vendor/opentracing/opentracing/tests/OpenTracing/StartSpanOptionsTest.php new file mode 100644 index 000000000..d7e1504a8 --- /dev/null +++ b/vendor/opentracing/opentracing/tests/OpenTracing/StartSpanOptionsTest.php @@ -0,0 +1,129 @@ +<?php + +declare(strict_types=1); + +namespace OpenTracing\Tests; + +use DateTime; +use OpenTracing\InvalidSpanOptionException; +use OpenTracing\NoopSpanContext; +use OpenTracing\Reference; +use OpenTracing\StartSpanOptions; +use PHPUnit\Framework\TestCase; + +/** + * @covers StartSpanOptions + */ +final class StartSpanOptionsTest extends TestCase +{ + const REFERENCE_TYPE = 'a_reference_type'; + + public function testSpanOptionsCanNotBeCreatedDueToInvalidOption() + { + $this->expectException(InvalidSpanOptionException::class); + + StartSpanOptions::create([ + 'unknown_option' => 'value' + ]); + } + + public function testSpanOptionsWithInvalidCloseOnFinishOption() + { + $this->expectException(InvalidSpanOptionException::class); + + StartSpanOptions::create([ + 'finish_span_on_close' => 'value' + ]); + } + + public function testSpanOptionsCanNotBeCreatedBecauseInvalidStartTime() + { + $this->expectException(InvalidSpanOptionException::class); + + StartSpanOptions::create([ + 'start_time' => 'abc' + ]); + } + + /** @dataProvider validStartTime */ + public function testSpanOptionsCanBeCreatedBecauseWithValidStartTime($startTime) + { + $spanOptions = StartSpanOptions::create([ + 'start_time' => $startTime + ]); + + $this->assertEquals($spanOptions->getStartTime(), $startTime); + } + + public function validStartTime() + { + return [ + [new DateTime()], + ['1499355363'], + [1499355363], + [1499355363.123456] + ]; + } + + public function testSpanOptionsCanBeCreatedWithValidReference() + { + $context = new NoopSpanContext(); + + $options = [ + 'references' => new Reference(self::REFERENCE_TYPE, $context), + ]; + + $spanOptions = StartSpanOptions::create($options); + $references = $spanOptions->getReferences()[0]; + + $this->assertTrue($references->isType(self::REFERENCE_TYPE)); + $this->assertSame($context, $references->getSpanContext()); + } + + public function testSpanOptionsDefaultCloseOnFinishValue() + { + $options = StartSpanOptions::create([]); + + $this->assertTrue($options->shouldFinishSpanOnClose()); + } + + public function testSpanOptionsWithValidFinishSpanOnClose() + { + $options = StartSpanOptions::create([ + 'finish_span_on_close' => false, + ]); + + $this->assertFalse($options->shouldFinishSpanOnClose()); + } + + public function testSpanOptionsAddsANewReference() + { + $context1 = new NoopSpanContext(); + $spanOptions = StartSpanOptions::create([ + 'child_of' => $context1, + ]); + $this->assertCount(1, $spanOptions->getReferences()); + + $context2 = new NoopSpanContext(); + $spanOptions = $spanOptions->withParent($context2); + + $this->assertCount(1, $spanOptions->getReferences()); + $this->assertSame($context2, $spanOptions->getReferences()[0]->getSpanContext()); + } + + public function testDefaultIgnoreActiveSpan() + { + $options = StartSpanOptions::create([]); + + $this->assertFalse($options->shouldIgnoreActiveSpan()); + } + + public function testSpanOptionsWithValidIgnoreActiveSpan() + { + $options = StartSpanOptions::create([ + 'ignore_active_span' => true, + ]); + + $this->assertTrue($options->shouldIgnoreActiveSpan()); + } +} |