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

Fixed check for exclude #958

Merged
merged 1 commit into from
Jan 23, 2020
Merged

Conversation

tpdrs
Copy link
Contributor

@tpdrs tpdrs commented Jan 16, 2020

@Jean85 Jean85 added this to the 2.3 milestone Jan 16, 2020
Copy link
Collaborator

@Jean85 Jean85 left a comment

Choose a reason for hiding this comment

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

Thanks for this PR, but we're still internally discussing this and how to proceed.

This PR restores the behavior described in the unified APIs, and makes it easy to include the whole project, and exclude vendor, which should be the most common case; OTOH though it makes impossible to do the reverse, like including a dependency inside vendor (maybe an internal dependency?).

@ste93cry
Copy link
Collaborator

Thank you for the contribution, however this as-is cannot be merged because Unified API docs clearly says that in_app_include overrides in_app_exclude, so the behavior you're trying to fix is expected and is not a bug, although I think that we all agree that this depending on the needs of each user may or may not be a good thing

This option can be overridden using in-app-include.
https://docs.sentry.io/error-reporting/configuration/?platform=php#in-app-exclude

@ste93cry
Copy link
Collaborator

This PR restores the behavior described in the unified APIs

I would like to clarify this sentence because I feel that it's not: the behavior described in the Unified API is that the in_app_exclude option overrides the in_app_include, so what has been implemented in 2.3 is the correct behavior and thus there is technically nothing to change. You should not blindly migrate from project_root to in_app_include: instead you should make each of its entries more specific than the ones in in_app_exclude and it should work

@tpdrs
Copy link
Contributor Author

tpdrs commented Jan 17, 2020

So before I set project_root = /app and excluded /app/vendor, now I have to mention all folders to include (/app/src, /app/bin, /app/tests and don't use app_exclude)

@tpdrs
Copy link
Contributor Author

tpdrs commented Jan 20, 2020

Let's look to the code

    /**
     * Checks whether a certain frame should be marked as "in app" or not.
     *
     * @param string      $file         The file to check
     * @param string|null $functionName The name of the function
     */
    private function isFrameInApp(string $file, ?string $functionName): bool
    {
        if (self::INTERNAL_FRAME_FILENAME === $file) {
            return false;
        }

        if (null !== $functionName && 0 === strpos($functionName, 'Sentry\\')) {
            return false;
        }

        $projectRoot = $this->options->getProjectRoot();
        $excludedAppPaths = $this->options->getInAppExcludedPaths();
        $includedAppPaths = $this->options->getInAppIncludedPaths();
        $absoluteFilePath = @realpath($file) ?: $file;
        $isInApp = false;

        if (null !== $projectRoot) {
            $isInApp = 0 === mb_strpos($absoluteFilePath, $projectRoot);
        }

        foreach ($excludedAppPaths as $excludedAppPath) {
            if (0 === mb_strpos($absoluteFilePath, $excludedAppPath)) {
                $isInApp = false;

                break;
            }
        }

        foreach ($includedAppPaths as $includedAppPath) {
            if (0 === mb_strpos($absoluteFilePath, $includedAppPath)) {
                $isInApp = true;

                break;
            }
        }

        return $isInApp;
    }

If you say $projectRoot is deprecated then $excludedAppPaths is useless because $isInApp by default is false and you can remove foreach with check excluded.

@tpdrs
Copy link
Contributor Author

tpdrs commented Jan 21, 2020

@ste93cry any comments?

@ste93cry
Copy link
Collaborator

So, there is indeed one bug that should be addressed here: $isInApp should be true by default. This would make the things working as follow:

  • Everything is included by default (regardless of any option)
  • in_app_exclude sets $isInApp to false if any entry matches
  • in_app_include sets $isInApp to true if any entry matches

With this behavior it's possible to include everything by default, exclude some folders (e.g. app/vendor) and still include some paths like app/vendor/xxx if needed. Does it makes more sense to you? If so, it would be really cool if you could adjust this PR to fit with the above specs

@damnedest damnedest force-pushed the fix-check-exclude branch 2 times, most recently from 509b421 to 3387acf Compare January 22, 2020 09:58
@tpdrs
Copy link
Contributor Author

tpdrs commented Jan 22, 2020

@ste93cry I fixed default value for isInApp if in_app_include is not specified.

@ste93cry
Copy link
Collaborator

ste93cry commented Jan 22, 2020

As I said above, the default value of $isInApp must be true regardless of any option, otherwise we will report all files as not-in-app if you didn't configure project_root nor in_app_include nor in_app_exclude.

@damnedest damnedest force-pushed the fix-check-exclude branch 2 times, most recently from e6c474a to 4659550 Compare January 22, 2020 21:21
@tpdrs
Copy link
Contributor Author

tpdrs commented Jan 22, 2020

Fixed

Copy link
Collaborator

@ste93cry ste93cry left a comment

Choose a reason for hiding this comment

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

@Jean85 I've removed the Type: Breaking label because this PR became a fix for a regression and so even though we are going to change the behavior from 2.3.0 we're really just fixing it. I had a look at the code and it seems fine, if @tpdrs confirms that this solves their original issue LGTM

@tpdrs
Copy link
Contributor Author

tpdrs commented Jan 22, 2020

Yep. This one solves my issues.

Copy link
Collaborator

@stayallive stayallive left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to make this PR 👌

Copy link
Collaborator

@Jean85 Jean85 left a comment

Choose a reason for hiding this comment

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

We need a changelog entry!

@tpdrs
Copy link
Contributor Author

tpdrs commented Jan 23, 2020

Updated changelog

@stayallive stayallive changed the title Fixed check for exlude Fixed check for exclude Jan 23, 2020
@stayallive stayallive merged commit 15bfd0e into getsentry:master Jan 23, 2020
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.

4 participants