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

handle host detector with custom error handler and open_basedir #1454

Merged
merged 5 commits into from
Dec 20, 2024

Conversation

brettmc
Copy link
Collaborator

@brettmc brettmc commented Dec 13, 2024

if open_basedir is configured such that files that the host detector tries to open are denied with a php warning, and a custom error handler is installed which converts warnings to exceptions, an unhandled exception occurs.
add a test for this, and some try/catch/ignore blocks around the code that can trigger this.

Closes: #1450
Replace: #1451

if open_basedir is configured such that files that it tries to open are denied with a php warning, and
a custom error handler is installed which converts warnings to exceptions, an unhandled exception occurs.
add a test for this, and some try/catch/ignore blocks around the code that can trigger this.
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.25%. Comparing base (4a021fb) to head (a52aa40).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1454      +/-   ##
============================================
- Coverage     73.26%   73.25%   -0.01%     
+ Complexity     2685     2683       -2     
============================================
  Files           387      387              
  Lines          8009     8014       +5     
============================================
+ Hits           5868     5871       +3     
- Misses         2141     2143       +2     
Flag Coverage Δ
8.1 72.98% <100.00%> (-0.01%) ⬇️
8.2 73.22% <100.00%> (+0.04%) ⬆️
8.3 73.22% <100.00%> (+0.02%) ⬆️
8.4 ?
8.5 73.15% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/SDK/Resource/Detectors/Host.php 73.46% <100.00%> (+3.01%) ⬆️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a021fb...a52aa40. Read the comment docs.

Copy link
Contributor

@Nevay Nevay left a comment

Choose a reason for hiding this comment

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

IMO we should disable the error handler instead.

set_error_handler(static fn() => true);
try {
    if (($content = file_get_contents($file)) !== false) {
        return trim($content);
    }
} finally {
    restore_error_handler();
}

src/SDK/Resource/Detectors/Host.php Outdated Show resolved Hide resolved
set_error_handler(static fn () => true);

try {
if (is_file($file) && is_readable($file)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These checks are no longer needed.

src/SDK/Resource/Detectors/Host.php Outdated Show resolved Hide resolved
src/SDK/Resource/Detectors/Host.php Show resolved Hide resolved
@brettmc brettmc force-pushed the host-detector-vs-error-handler branch from 8cd59c1 to 86deb4e Compare December 19, 2024 09:44
@brettmc brettmc merged commit b515b6b into open-telemetry:main Dec 20, 2024
8 of 9 checks passed
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.

File(/etc/machine-id) is not within the allowed path(s)
3 participants