-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the tracecontext standard (#16)
Add support for the tracecontext standard - new traceMode config option to switch between traceid and tracecontext -- supporting both options at the same time is out of scope for this PR, might be possible in the future -- Need to think about what happens when X-TraceId header is in the request with a value that's not valid for traceContext standard, but app is doing ajax calls with traceparent headers. MessageBusSubscriber now passes the full TraceContext object to the TraceStamp - clones original TraceContext, fills parentTransactionId in cloned trace
- Loading branch information
Showing
57 changed files
with
1,549 additions
and
668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# TraceContext setup | ||
With the default traceContext setup, tracing will be configured according to the [W3C TraceContext](https://www.w3.org/TR/trace-context/) specification. | ||
Incoming request data will be taken from the traceparent/tracestate headers, this data will be updated and passed to messenger and httpclient requests. | ||
|
||
## Configuration | ||
|
||
```php | ||
# /config/packages/symfony-trace-bundle.php | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use DR\SymfonyTraceBundle\Generator\TraceId\RamseyUuid4Generator; | ||
use DR\SymfonyTraceBundle\TraceStorage; | ||
use Symfony\Config\SymfonyTraceConfig; | ||
|
||
return static function (SymfonyTraceConfig $config): void { | ||
// Whether to trust the incoming request header. This is turned on by default. | ||
// If true a value in the `traceparent` header in the request | ||
// will be used and parsed to get the trace ID for the rest of the request. If false | ||
// those values are ignored and new trace ID's are generated. | ||
$config->trustRequestHeader(true); | ||
|
||
// The service key of an object that implements | ||
// DR\SymfonyTraceBundle\TraceStorageInterface | ||
// Defaults to TraceStorage::class | ||
$config->storageService(TraceStorage::class); | ||
|
||
// Whether to add the monolog process, defaults to true | ||
$config->enableMonolog(true); | ||
|
||
// Whether to add the request id to console commands, defaults to true | ||
$config->enableConsole(true); | ||
|
||
// Whether to add the request id to message bus events, defaults to false | ||
$config->enableMessenger(false); | ||
|
||
// Whether to add the twig extension, defaults to true | ||
$config->enableTwig(true); | ||
|
||
// Whether to pass traceparent & tracestate to outgoing http requests, defaults to false | ||
$config->httpClient() | ||
->enabled(true) | ||
->tagDefaultClient(false); | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# TraceId setup | ||
With traceId mode it's possible to configure the request/response/httpclient headers, and configure custom ID generators. | ||
|
||
The bundle will try and use either Symfony Uid or Ramsey Uuid to generate the trace ids: | ||
```shell | ||
composer require ramsey/uuid | ||
# OR | ||
composer require symfony/uid | ||
``` | ||
Instead it's also possible to configure a custom ID generator using the `generatorService` option. | ||
|
||
## Configuration | ||
|
||
```php | ||
# /config/packages/symfony-trace-bundle.php | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use DR\SymfonyTraceBundle\Generator\TraceId\RamseyUuid4Generator; | ||
use DR\SymfonyTraceBundle\TraceStorage; | ||
use Symfony\Config\SymfonyTraceConfig; | ||
|
||
return static function (SymfonyTraceConfig $config): void { | ||
$config->traceMode('traceId'); | ||
|
||
// Whether to trust the incoming request header. This is turned | ||
// on by default. If true a value in the `X-Trace-Id` header in the request | ||
// will be used as the trace ID for the rest of the request. If false | ||
// those values are ignored. | ||
$config->trustRequestHeader(true); | ||
|
||
$config->traceid() | ||
// The header which the bundle inspects for the incoming trace ID | ||
// if this is not set an ID will be generated and set at this header | ||
->requestHeader('X-Trace-Id') | ||
// The header which the bundle will set the trace ID to on the response | ||
->responseHeader('X-Trace-Id') | ||
// The service key of an object that implements | ||
// DR\SymfonyTraceBundle\Generator\IdGeneratorInterface | ||
// Optional, will default to Symfony's Uuid or Ramsey's Uuid. | ||
->generatorService(RamseyUuid4Generator::class); | ||
|
||
// The service key of an object that implements | ||
// DR\SymfonyTraceBundle\TraceStorageInterface | ||
$config->storageService(TraceStorage::class); | ||
|
||
// Whether to add the monolog process, defaults to true | ||
$config->enableMonolog(true); | ||
|
||
// Whether to add the request id to console commands, defaults to true | ||
$config->enableConsole(true); | ||
|
||
// Whether to add the request id to message bus events, defaults to false | ||
$config->enableMessenger(false); | ||
|
||
// Whether to add the twig extension, defaults to true | ||
$config->enableTwig(true); | ||
|
||
// Whether to pass traceId to outgoing http requests, defaults to false | ||
$config->httpClient() | ||
->enabled(true) | ||
->tagDefaultClient(false) | ||
// The header which the bundle will set the trace ID to on the outgoing request | ||
->header('X-Trace-Id'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<phpmd-baseline> | ||
<violation rule="PHPMD\Rule\Design\CouplingBetweenObjects" file="src/DependencyInjection/SymfonyTraceExtension.php"/> | ||
<violation rule="PHPMD\Rule\CyclomaticComplexity" file="src/DependencyInjection/SymfonyTraceExtension.php" method="loadInternal"/> | ||
<violation rule="PHPMD\Rule\Design\NpathComplexity" file="src/DependencyInjection/SymfonyTraceExtension.php" method="loadInternal"/> | ||
<violation rule="PHPMD\Rule\Design\LongMethod" file="src/DependencyInjection/SymfonyTraceExtension.php" method="loadInternal"/> | ||
<violation rule="PHPMD\Rule\Controversial\Superglobals" file="tests/Functional/AbstractKernelTestCase.php" method="createKernel"/> | ||
<violation rule="PHPMD\Rule\Controversial\Superglobals" file="tests/Functional/AbstractWebTestCase.php" method="createKernel"/> | ||
</phpmd-baseline> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.