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

Add the request hostname to error & exception logs #18996

Merged
merged 7 commits into from Apr 11, 2022

Conversation

samjf
Copy link
Contributor

@samjf samjf commented Mar 24, 2022

Ref: DEV-2584

Description:

When viewing the logs of a multi-tenant install it is difficult to determine which Matomo instance was requested when the error (log entry) occurs.

A simple solution is to print the host from the incoming headers. Whilst this is not safe against tampering, it is only printed in logs and will be effective for normal traffic.

Notes

I preferred injecting the error message prefix when providing the prefix in core/testMinimumPhpVersion.php due to the fact that the code seems to be early in the bootstrap and must be compatible with early versions of PHP. The filter_var validation function of the hostname/domain has a minimum php requirement of 5.2.

Review

@samjf samjf marked this pull request as ready for review March 25, 2022 00:57
@samjf samjf added the Needs Review PRs that need a code review label Mar 25, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2022

This issue is in "needs review" but there has been no activity for 7 days. ping @matomo-org/core-reviewers

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Apr 2, 2022
core/Common.php Outdated Show resolved Hide resolved
@sgiehl
Copy link
Member

sgiehl commented Apr 7, 2022

@samjf This looks good so far. Is it on purpose that only exceptions / errors that might get logged outside of matomo's logging will be prefixed with the host? Messages logged to the matomo log files won't include the hostname. For that guess it would need to be added somewhere in https://github.com/matomo-org/matomo/blob/115527353a9e75e01aa4d263408956ae45403bea/plugins/Monolog/Formatter/LineMessageFormatter.php

@github-actions github-actions bot removed the Stale The label used by the Close Stale Issues action label Apr 8, 2022
@samjf
Copy link
Contributor Author

samjf commented Apr 10, 2022

@sgiehl I don't think I've really had a problem with the matomo file log. Correct me if i'm wrong but It seems that the hostnames are being logged for me (checking locally). Perhaps archiving/commands already adds them on a multitenant?
image

The main problem was trying to distinguish between a large amount of errors on the PHP/FPM error/exception logging.

@sgiehl
Copy link
Member

sgiehl commented Apr 11, 2022

@samjf Guess our cloud plugin has a special log processor, that adds the instanceid. We could consider having that in core and only log it for multitenant maybe.
But as that won't affect many people at all, guess we can save the effort for now.

@sgiehl sgiehl added this to the 4.10.0 milestone Apr 11, 2022
@sgiehl sgiehl merged commit e618209 into 4.x-dev Apr 11, 2022
@sgiehl sgiehl deleted the D2584-add-hostname-to-error-logs branch April 11, 2022 09:32
@sgiehl sgiehl added Easier debugging For issues that make troubleshooting issues for developers easier. and removed Needs Review PRs that need a code review labels Apr 11, 2022
@samjf
Copy link
Contributor Author

samjf commented Apr 11, 2022

Many thanks @sgiehl
That might be a good contribution from cloud in the future. Hard tracking down exactly where it was added haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easier debugging For issues that make troubleshooting issues for developers easier.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants