Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: update opentracing/opentracing to 1.0.1 #1

Merged
merged 38 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4d33273
todo list
jky-yy Aug 26, 2020
d21c078
Migrate from travis to GitHub Actions
nauxliu Dec 25, 2020
e0b75d8
Support opentracing v1.0
nauxliu Dec 25, 2020
c3bdb70
Change CI php version
nauxliu Dec 25, 2020
e30d6a4
Fix phpunit tests
nauxliu Dec 25, 2020
11db654
Update README
nauxliu Dec 25, 2020
b1dc43f
Bump PHPStan level 4
nauxliu Dec 25, 2020
19db2ac
Disable test on PHP 8
nauxliu Dec 25, 2020
f7d394a
Merge branch 'dev_v3' into next-major-version
nauxliu Dec 26, 2020
e0317a8
Merge pull request #98 from nauxliu/next-major-version
nauxliu Dec 26, 2020
8a67a8f
Add php-cs-fixer to format code
nauxliu Dec 26, 2020
9ee1ce5
PHP 7.1 syntax
nauxliu Dec 26, 2020
b92a7db
Add GitHub Action Lint job
nauxliu Dec 26, 2020
936d373
Improve PHPDoc
nauxliu Dec 26, 2020
34d6051
Add span property type doc
nauxliu Dec 26, 2020
e151e51
Update README.md
nauxliu Dec 26, 2020
4294caa
Fix call to undefined on Reference
nauxliu Dec 26, 2020
3e44d9a
Require ext-json
nauxliu Dec 26, 2020
7a9ddf8
Code style improvements
nauxliu Dec 26, 2020
c00b243
Refactor thrift
jky-yy Dec 29, 2020
28cec1a
unit test of JaegerThrift
jky-yy Dec 29, 2020
65e3611
unit test of transportUdp
jky-yy Dec 30, 2020
3c3a767
unit test of propagator
jky-yy Dec 30, 2020
6f56e26
unit test of config
jky-yy Dec 30, 2020
7843d62
PHPStan: ignore thrift functions not found errors
nauxliu Dec 31, 2020
349ea9d
Remove unmatch ignored error pattern
nauxliu Dec 31, 2020
ef00bc9
Improve TransportUdp type hint
nauxliu Jan 6, 2021
5c7e72b
Code format
nauxliu Jan 7, 2021
3a6cda7
Fix PHPStan errors
nauxliu Jan 7, 2021
641abfc
Fix opentracing/opentracing 1.0.1 return type
nauxliu Jan 14, 2021
41b0e3a
Fix always send data to localhost:6831
nauxliu Feb 2, 2021
f34d658
Fix int tag values always be 0
nauxliu Feb 2, 2021
81aa305
fix: cleanup tests and actions
cawolf Oct 4, 2021
ee2a5ef
chore: update phpunit and phpcs
cawolf Oct 4, 2021
6a780f0
fix: unit test
cawolf Oct 4, 2021
5a84343
chore: follow best practices
cawolf Nov 15, 2021
530c633
chore: update phpstan to level 5
cawolf Nov 15, 2021
8fe1034
doc: update documentation
cawolf Nov 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php:
- '7.3'
- '7.4'
- '8.0'
dependency-version: [prefer-stable]
name: ${{ matrix.php }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install dependencies
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Execute PHPStan
run: composer run-script phpstan

- name: PHP CS Fixer Check
run: composer run-script phpcs-check
39 changes: 39 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php:
- '7.3'
- '7.4'
- '8.0'
dependency-version: [prefer-stable]
name: ${{ matrix.php }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-laravel-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Install dependencies
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

- name: Execute tests
run: composer run-script test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.settings/
.buildpath
.php-version
.project
.idea
.php-cs-fixer.cache
composer.lock
vendor/*
build
16 changes: 16 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('src/Jaeger/Thrift')
->in(__DIR__);

$config = new PhpCsFixer\Config();
return $config
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
])
->setFinder($finder);
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

115 changes: 44 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,76 @@
[![Build Status](https://travis-ci.com/jukylin/jaeger-php.svg?branch=master)](https://travis-ci.com/jukylin/jaeger-php)
[![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/jukylin/jaeger-php.svg)](https://github.com/jukylin/jaeger-php/blob/master/LICENSE)
[![Coverage Status](https://coveralls.io/repos/github/jukylin/jaeger-php/badge.svg?branch=master)](https://coveralls.io/github/jukylin/jaeger-php?branch=master)

# jaeger-php

## Install

Install via composer.
[![Tests](https://github.com/auxmoney/jaeger-php/actions/workflows/test.yaml/badge.svg)](https://github.com/auxmoney/jaeger-php/actions/workflows/test.yaml)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg)](https://php.net/)
[![License](https://img.shields.io/github/license/auxmoney/jaeger-php.svg)](https://github.com/auxmoney/jaeger-php/blob/master/LICENSE)
[![Coverage Status](https://coveralls.io/repos/github/auxmoney/jaeger-php/badge.svg?branch=master)](https://coveralls.io/github/auxmoney/jaeger-php?branch=master)

```
composer config minimum-stability dev
composer require jukylin/jaeger-php
```
_ATTENTION: this is a fork and republication of [jukylin/jaeger-php](https://github.com/jukylin/jaeger-php)_

## Init Jaeger-php
_We opted into forking and publishing the original library in order to maintain our set of
[opentracing related symfony bundles](https://github.com/auxmoney?q=opentracingbundle). The original library seems to be unmaintained
currently._

```php
$config = Config::getInstance();
$tracer = $config->initTracer('example', '0.0.0.0:6831');
```
jaeger-php is a library implementing the [OpenTracing specification for PHP](https://github.com/opentracing/opentracing-php) to
connect with the [Jaeger Distributed Tracing Platform](https://github.com/jaegertracing/jaeger). It can be used to instrument PHP
code to generate tracing data and send it to Jaeger.

## 128bit
## Installation

```php
$config->gen128bit();
```

## Extract from Superglobals

```php
$spanContext = $tracer->extract(Formats\TEXT_MAP, $_SERVER);
composer require auxmoney/jaeger-php
```

## Start Span
## Usage

```php
$serverSpan = $tracer->startSpan('example HTTP', ['child_of' => $spanContext]);
```
First, you need to create a `Config` object, which serves as the factory to create your `Tracer`:

## Distributed context propagation
```php
$serverSpan->addBaggageItem("version", "2.0.0");
// create a config instance
$config = \Jaeger\Config::getInstance();
// create a tracer
$tracer = $config->initTracer('example service name', '0.0.0.0:6831');
```

## Inject into Superglobals

To make the distributed tracing work, you need to extract your `SpanContext` from somewhere, e.g. `$_SERVER`:
```php
$clientTrace->inject($clientSpan1->spanContext, Formats\TEXT_MAP, $_SERVER);
$spanContext = $tracer->extract(\Opentracing\Formats\TEXT_MAP, $_SERVER);
```

## Tags and Log

You can then start tracing by using the common Opentracing interface:
```php
// tags are searchable in Jaeger UI
$span->setTag('http.status', '200');

// log record
$span->log(['error' => 'HTTP request timeout']);
$tracer->startActiveSpan("example operation name", ['child_of' => $spanContext]);
```

## Close Tracer

To add metadata to your span, you need to retrieve it first (be sure to check the [semantic conventions](https://opentracing.io/specification/conventions/) first):
```php
$config->setDisabled(true);
$span = $tracer->getActiveSpan();
$span->addBaggageItem("user_id", "12345");
$span->setTag("http.url", "http://localhost");
$span->log(["message" => "responded successfully"]);
$span->finish();
```

## Zipkin B3 Propagation

*no support for* `Distributed context propagation`

Finally, at the end of your script, you should flush the original `Config`. This will flush all created `Tracer`s and all created `Span`s:
```php
$config::$propagator = \Jaeger\Constants\PROPAGATOR_ZIPKIN;
$config->flush();
```

## Finish span and flush Tracer
### optional configuration

```php
$span->finish();
$config->flush();
// optional: generate 128 bit trace ids (default: false)
$config->gen128bit();
// optional: disable tracing (default: false)
$config->setDisabled(true);
// optional: inject custom transport (default: TransportUdp)
$config->setTransport($transport);
// optional: inject custom reporter (default: RemoteReporter)
$config->setReporter($reporter);
// optional: inject custom sampler (default: ConstSampler)
$config->setSampler($sampler);
```

## More example

- [HTTP](https://github.com/jukylin/jaeger-php/blob/master/example/HTTP.php)
- [Hprose](https://github.com/jukylin/blog/blob/master/Uber%E5%88%86%E5%B8%83%E5%BC%8F%E8%BF%BD%E8%B8%AA%E7%B3%BB%E7%BB%9FJaeger%E4%BD%BF%E7%94%A8%E4%BB%8B%E7%BB%8D%E5%92%8C%E6%A1%88%E4%BE%8B%E3%80%90PHP%20%20%20Hprose%20%20%20Go%E3%80%91.md#跨语言调用案例)
- [Istio](https://github.com/jukylin/jaeger-php/blob/master/example/README.md)

## Features

- Transports
- via Thrift over UDP

- Sampling
- ConstSampler
- ProbabilisticSampler

## Reference

[OpenTracing](https://opentracing.io/)
## Special thanks

[Jaeger](https://uber.github.io/jaeger/)
Thank you @jukylin for creating this library!
44 changes: 32 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
{
"name": "jukylin/jaeger-php",
"description": "php client for jaeger",
"keywords": ["jaeger","trace","opentracing"],
"license": "Apache-2.0",
"name": "auxmoney/jaeger-php",
"description": "php client for jaeger",
"keywords": [
"jaeger",
"trace",
"opentracing"
],
"license": "Apache-2.0",
"minimum-stability": "stable",
"require": {
"php": ">=5.6.0",
"packaged/thrift" : "0.10.0",
"opentracing/opentracing" : "1.0.0-beta5"
"require": {
"php": ">=7.1",
"ext-json": "*",
"packaged/thrift": "~0.13.0",
"opentracing/opentracing": "^1.0.1"
},
"authors": [
{
"name": "jukylin",
"email": "[email protected]"
},
{
"name": "auxmoney GmbH",
"email": "[email protected]"
}
],
"autoload": {
"autoload": {
"psr-4": {
"Jaeger\\": "src\\Jaeger"
},
"files": [
"src/Jaeger/Constants.php"
]
},
"autoload-dev": {
"psr-4": {
"tests\\": "tests\\"
}
},
"scripts": {
"test": "./vendor/bin/phpunit"
"test": "phpdbg -qrr vendor/bin/phpunit",
"phpcs": "vendor/bin/php-cs-fixer fix --ansi",
"phpcs-check": "vendor/bin/php-cs-fixer fix --dry-run --diff 1>&2",
"phpstan": "vendor/bin/phpstan analyse src tests"
},
"require-dev": {
"phpunit/phpunit": "^5",
"php-coveralls/php-coveralls": "^1.0"
"roave/security-advisories": "dev-latest",
"phpunit/phpunit": "^8.5",
"php-coveralls/php-coveralls": "^v2.4",
"phpstan/phpstan": "^0.12",
"friendsofphp/php-cs-fixer": "^v3.1"
}
}
Loading