Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
Implement cross service trace contexts
Browse files Browse the repository at this point in the history
Adds middleware for Laravel and GuzzleHttp to automatically extract and
inject trace contexts for cross service tracing.
  • Loading branch information
taisph committed Apr 21, 2019
1 parent 8ed7c95 commit 5de6500
Show file tree
Hide file tree
Showing 9 changed files with 601 additions and 343 deletions.
39 changes: 39 additions & 0 deletions README.md
Expand Up @@ -134,6 +134,45 @@ app(\Illuminate\Bus\Dispatcher::class)->pipeThrough([
]);
```

### Tracing Across Service Boundaries

Trace contexts can easily be used across services. If your application starts a tracing context, that context can be
carried over HTTP to another service with an OpenTracing compatible implementation.

To automatically accept trace contexts from other services, add the tracing middleware to your application by adding it
to your `app/Http/Kernel.php` file like below:

```php
<?php

class Kernel extends HttpKernel
{
protected $middleware = [
\LaravelOpenTracing\Http\Middleware\Tracing::class,
];
}
```

Assuming your application uses GuzzleHttp for sending requests to external services, you can use the provided tracing
handler when creating the client like below. This will automatically send the necessary trace context headers with the
HTTP request to the external service.

```php
<?php

new \GuzzleHttp\Client(
[
'handler' => new \LaravelOpenTracing\TracingHandlerStack(),
'headers' => [
'cache-control' => 'no-cache',
'content-type' => 'application/json',
],
'base_uri' => 'http://localhost/api/myservice',
'http_errors' => false
]
);
```

## Testing

docker run --rm -it -v $(pwd):/app php:5.6-cli-alpine /bin/sh -c 'apk add --no-cache $PHPIZE_DEPS && pecl install xdebug-2.5.5 && cd app && php -dzend_extension=xdebug.so vendor/bin/phpunit'
Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -15,6 +15,7 @@
],
"require": {
"php": ">=5.6",
"guzzlehttp/guzzle": "^6.2",
"illuminate/support": "^5.4.36",
"jonahgeorge/jaeger-client-php": "dev-feature/php56",
"opentracing/opentracing": "^1.0.0-beta5",
Expand Down

0 comments on commit 5de6500

Please sign in to comment.