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

Provide a chapter on adding a request ID #84

Merged
merged 4 commits into from
Jan 7, 2022

Conversation

weierophinney
Copy link
Contributor

Based on a question I answered in Slack, this provides a recipe for adding a unique request ID that can then be tracked in your logs.

@weierophinney weierophinney added this to the 4.0.1 milestone Jan 3, 2022
However, when using mezzio-swoole, the request handler runner we create is your web server.
It has listeners that take care of logging, which means that the request generated must _already_ have the identifier if you want to be able to log it.

This poses a problem: normally you will use middleware to propagate changes to the request.
Copy link
Member

Choose a reason for hiding this comment

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

Until here the problem is described, therefore the the headline "The solution" is wrong before these lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

This poses a problem: normally you will use middleware to propagate changes to the request.
How can you do it at the Swoole web server level?

The answer is deceptively simple: you can provide a [delegator factory](https://docs.mezzio.dev/mezzio/v3/features/container/delegator-factories/) for decorator on the service that converts the Swoole HTTP request instance into the equivalent [PSR-7](https://www.php-fig.org/psr/psr-7/) HTTP request instance that is then passed to your application.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it is simple for you but it does not mean that it applies to others as well. So do not use "simple" or "easy" in the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Based on a question I answered in Slack, this provides a recipe for adding a unique request ID that can then be tracked in your logs.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
- Move description of the problem... under the heading marked "The problem".
- Remove "simple" verbiage.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Performs one more editing pass, identifying several grammatical and/or spelling errors.

Also updates the example to use an arrow function.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
@weierophinney weierophinney changed the base branch from 4.0.x to 4.1.x January 6, 2022 14:40
@weierophinney weierophinney modified the milestones: 4.0.1, 4.1.1 Jan 6, 2022
@weierophinney weierophinney merged commit 336a149 into mezzio:4.1.x Jan 7, 2022
@weierophinney weierophinney deleted the docs/request-id-recipe branch January 7, 2022 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants