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

Exception thrown using the Symfony profiler for Messenger workers #24

Open
dev-cld opened this issue Feb 17, 2025 · 0 comments · May be fixed by #25
Open

Exception thrown using the Symfony profiler for Messenger workers #24

dev-cld opened this issue Feb 17, 2025 · 0 comments · May be fixed by #25

Comments

@dev-cld
Copy link

dev-cld commented Feb 17, 2025

Hello,

Listening to Symfony Messenger workers raises a BadRequestException from Symfony\Component\HttpFoundation\Request.

It seems to be due to the introduction of a rejection of some characters in the URIs, including backslashes, by the Request class of the HTTPFoundation component:
symfony/http-foundation@32310ff#diff-de5d8eb3f1d6537c947f70e0a4673779312a902c083739f472c709c037bcbc30R370

if (false !== ($i = strpos($uri, '\\')) && $i < strcspn($uri, '?#')) {
    throw new BadRequestException('Invalid URI: A URI cannot contain a backslash.');
}

Backslashes are used by the bundle in the transaction name, which is composed from the class name of the message, and the class name uses backslashes for the namespace:

$transactionName = \get_class($event->getEnvelope()->getMessage());

$transactionName = \get_class($envelope->getMessage());

Then the SymfonyProfiler uses the transaction name in the URI:

$uri = sprintf('http://%s/%s', $kind, $name);

And creates the Request:

$this->request = Request::create($uri, $kind);

I suggest fixing it by replacing the backslashes in the class name with regular slashes:

$transactionName = str_replace('\\', '/', \get_class($event->getEnvelope()->getMessage()));
$transactionName = str_replace('\\', '/', \get_class($envelope->getMessage()));
adrienbrault added a commit that referenced this issue Feb 18, 2025
…24

Fixes #24

Fix exception thrown using the Symfony profiler for Messenger workers

* Replace backslashes with regular slashes in the transaction name in `src/EventListener/MessengerProfilerListener.php`
  * Use `str_replace('\\', '/', \get_class($event->getEnvelope()->getMessage()))`
* Replace backslashes with regular slashes in the transaction name in `src/Messenger/ProfilerMiddleware.php`
  * Use `str_replace('\\', '/', \get_class($envelope->getMessage()))`
* Ensure the transaction name is used in the URI with regular slashes in `src/Profiler/SymfonyProfiler.php`
  * Replace backslashes with regular slashes in the URI

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/sourceability/instrumentation/issues/24?shareId=XXXX-XXXX-XXXX-XXXX).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant