-
Notifications
You must be signed in to change notification settings - Fork 13
CRV-1021 implemented sharing correlation id between services #13
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
base: master
Are you sure you want to change the base?
Conversation
a215bee to
48ea581
Compare
|
@borilyordanov review it, please |
| $headerName = CorrelationIdListener::HEADER_NAME; | ||
| $request = $this->requestStack->getCurrentRequest(); | ||
|
|
||
| if ($request && $request->headers->has($headerName)) { | ||
| return $request->headers->get($headerName); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to move this logic out of the CorrelationIdProvider class? For example, we could create an event listener for the kernel.request event, which checks for the presence of the correlation ID in the HTTP headers and then explicitly sets the correlation ID in the CorrelationIdProvider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to implement your suggestion but realized that Symfony adds some logs even before kernel.request event. It means that it happens before the Request object creation. So not your suggested approach not mine was not working correctly.
The only way to solve this problem I see is by getting the header value directly from the $_SERVER variable. That's why the CorrelationIdFromHeaderExtractor was created.
I realize that using $_SERVER variable directly is something we would like to avoid, so if you have a better solution, let me know.
| } | ||
|
|
||
| public function incrementIdentifier() | ||
| public function incrementIdentifier(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid adding this return type hint, as it would technically be a BC break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void return type was introduced in PHP 7.1 https://www.php.net/releases/7_1_0.php
Since in composer.json we have "php": "^7.2 || ^8.0" it's not possible to break BC in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm referring more to cases where a client of the library decides to do something like this:
use Paysera\LoggingExtraBundle\Service\CorrelationIdProvider;
class CustomCorrelationIdProvider extends CorrelationIdProvider
{
public function incrementIdentifier()
{
parent::incrementIdentifier();
}
}Now, imagine we release a new version in which the incrementIdentifier() method signature has a void return type. This change will cause the client code to break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/Service/HttpClientDecorator.php
Outdated
| use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
| use Symfony\Contracts\HttpClient\ResponseInterface; | ||
|
|
||
| class HttpClientDecorator implements HttpClientInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about CorrelationIdHttpClientDecorator, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
src/Resources/config/services.xml
Outdated
| <argument type="service" id="request_stack"/> | ||
| </service> | ||
|
|
||
| <service id="Paysera\LoggingExtraBundle\Service\HttpClientDecorator" decorates="http_client"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better if we introduced the decorator class without configuring it? This way, we would allow the clients of the bundle to decide when they need the decorated HTTP client and when they do not. However, if we do that we should mention this in the README file, explaining how to use and configure the decorated HTTP client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
CHANGELOG.md
Outdated
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
|
||
| ## 2.2.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this appears to be a new feature, I think we should bump the MINOR version instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
| use Paysera\LoggingExtraBundle\Listener\CorrelationIdListener; | ||
| use Symfony\Component\HttpClient\DecoratorTrait; | ||
| use Symfony\Component\HttpClient\HttpClient; | ||
| use Symfony\Contracts\HttpClient\HttpClientInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to add symfony/http-client-contracts as dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
a4dda50 to
1bbab23
Compare
dfab6b8 to
6117455
Compare
mSprunskas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Correlation id is already not ideal term, apparently borrowed from https://www.rabbitmq.com/tutorials/tutorial-six-php which prevents passing it using same terminology as a header through rabbitmq
- Seeing logs from different apps for same identifier is not really backwards compatible and might cause confusion, especially in Sentry
Therefore it would be better to implement cross-app tracking with new identifier name, eg. "some id" (ray id in cloudflare). Also, consider identifier creation on server level (nginx, gateway, etc.) so that app responsibility would be only to pass the value.
No description provided.