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

PSR-4 autoloading doesn't work #19

Closed
ghost opened this issue Mar 30, 2020 · 15 comments
Closed

PSR-4 autoloading doesn't work #19

ghost opened this issue Mar 30, 2020 · 15 comments
Labels
bug Something isn't working P1

Comments

@ghost
Copy link

ghost commented Mar 30, 2020

Description

I've tried using this package with our Symfony 5 installation and could not integrate it cleanly because the autoloading is broken due to the fix for PHP5.

Steps to Reproduce

Take any Symfony installation, composer-require this and try to use it inside a service. It basically doesn't work because the Formatter and Handler classes never end up in the classmap.

Theoretically, this should also fail to work with composer dump-autoload generated files (i.e. the standard autoloading method).

Expected Behaviour

This works with normal PSR-4 autoloading.

Your Environment

PHP 7.2.29 (cli) (built: Mar 20 2020 01:33:13) ( NTS )

monolog/monolog                        1.25.3   Sends your logs to files, sockets, inboxes, databases and various web services
newrelic/monolog-enricher              1.0.0    Monolog components to enable New Relic Logs
symfony/monolog-bridge                 v4.4.5   Symfony Monolog Bridge
symfony/monolog-bundle                 v3.5.0   Symfony MonologBundle

Linux 693af06c9eb9 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 x86_64 GNU/Linux
@ghost ghost added the bug Something isn't working label Mar 30, 2020
@kneitinger
Copy link
Contributor

Thank you for this detailed bug report @armin-crosslend! I appreciate the information, and will look at this in the coming days!

@awons
Copy link

awons commented Aug 13, 2020

As a temporary solution I added a fixed class map to composer:

"autoload": {
    "classmap": [
        "vendor/newrelic/monolog-enricher/src"
    ]
}

And later in our bootstrap.php we have this (for Monolog v2):

require __DIR__ . '/vendor/autoload.php';

require __DIR__ .'/vendor/newrelic/monolog-enricher/src/api2/Formatter.php';
require __DIR__ .'/vendor/newrelic/monolog-enricher/src/api2/Handler.php';

For Monolog v1 just change the folder to api1.

This makes composer with --classmap-authoritative happy and properly loads necessary classes.

@cjunge-work
Copy link

cjunge-work commented Aug 17, 2020

    "autoload": {
        "exclude-from-classmap": ["/src/api1/", "/src/api2"],
        "psr-4": {
            "NewRelic\\Monolog\\Enricher\\": "src"
        }
    },

The exclude-from-classmap is resulting in the generated classmap not including the formatter. I can understand why (each folder contains the same classes which are meant to load based on the api version), but it means using composer dump-autoload -a will not work.

This appears to be a deliberate choice based on the comment in the AbstractFormatter

/*
 * This extension to the Monolog framework supports the same PHP versions
 * as the New Relic PHP Agent (>=5.3).  Older versions of PHP are only
 * compatible with Monolog v1, therefore, To accomodate Monolog v2's explicit
 * and required type annotations, some overridden methods must be implemented
 * both with compatible annotations for v2 and without for v1
 */
if (Logger::API == 2) {
    require_once dirname(__FILE__) . '/api2/Formatter.php';
} else {
    require_once dirname(__FILE__) . '/api1/Formatter.php';
}

@vinyvicente
Copy link

Some updates about this issue, folks?

@junowilderness
Copy link

The latest version of Composer v1 complains similarly:

Deprecation Notice: Class NewRelic\Monolog\Enricher\AbstractHandler located in ./vendor/newrelic/monolog-enricher/src/Handler.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201
Deprecation Notice: Class NewRelic\Monolog\Enricher\AbstractFormatter located in ./vendor/newrelic/monolog-enricher/src/Formatter.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201

@hver
Copy link

hver commented Oct 1, 2020

Having the same issue. The best solution would be to create two versions of the library, one which explicitly needs Monolog 1.* and another for 2.*

@pyohannes
Copy link

Thanks for all your feedback on this. We will work on creating two versions of the library, one for Monolog 1, another for Monolog 2 versions.

@Miriam-R Miriam-R reopened this Oct 21, 2020
@ghost
Copy link
Author

ghost commented Oct 27, 2020

With the release of Composer 2 this is now again an issue. Do you have a guesstimate on the split library ETA?

@junowilderness
Copy link

The idea is to maintain two release branches of this library, correct?

@pyohannes
Copy link

The idea is to maintain two release branches of this library, correct?

Yes @cilefen, that's what we plan to do.

@Miriam-R Miriam-R added the P1 label Jan 20, 2021
@dragoonis
Copy link

dragoonis commented Feb 3, 2021

@pyohannes please can you speak to your managers at NewRelic on getting this change prioritized? It is a massive blocker for me, and many other people. I have customers who are paying loads of money to NewRelic platform already, and we're relying on this library to use your platform for logging, instead of Google Cloud. Thanks.

UPDATE: I see @pyohannes you're at Microsoft, not NewRelic. Who is the point of contact for this?

@benrowe-chuffed
Copy link

This issue has been logged for almost a year now. Any chance we can get a proper fix for this?

@dlucian
Copy link

dlucian commented Feb 20, 2021

That's it for me, moving to Logflare. The NewRelic platform is an actual bottleneck instead of an Observability Platform, like they advertise. Any bug takes years to solve, interface is very slow. Not worth spending life time with it.

@whobutsb
Copy link

whobutsb commented Feb 20, 2021 via email

@zsistla
Copy link
Contributor

zsistla commented Mar 16, 2021

We'd like to thank the community for your patience and engagement in this issue. We understand your frustrations with the delay and lack of transparency on the timeline for this for which we sincerely apologize.

The fix is now in with release 2.0.0!

:) We hope you'll give it a try.

@zsistla zsistla closed this as completed Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1
Projects
None yet
Development

No branches or pull requests