Skip to content

Conversation

@maletskyi-paysera
Copy link

No description provided.

@maletskyi-paysera maletskyi-paysera marked this pull request as ready for review March 11, 2025 12:00
@maletskyi-paysera
Copy link
Author

@borilyordanov review it, please

@borilyordanov borilyordanov self-requested a review March 17, 2025 15:13
$headerName = CorrelationIdListener::HEADER_NAME;
$request = $this->requestStack->getCurrentRequest();

if ($request && $request->headers->has($headerName)) {
return $request->headers->get($headerName);
}
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

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.

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

class HttpClientDecorator implements HttpClientInterface
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

<argument type="service" id="request_stack"/>
</service>

<service id="Paysera\LoggingExtraBundle\Service\HttpClientDecorator" decorates="http_client">
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

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.

Copy link
Author

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;
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@haiduk-paysera haiduk-paysera force-pushed the CRV-1021 branch 7 times, most recently from dfab6b8 to 6117455 Compare May 7, 2025 11:24
Copy link
Contributor

@mSprunskas mSprunskas left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants