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

Cannot use object of type Illuminate\Support\Facades\Config as array When using MongoDB #88

Closed
aconital opened this issue Sep 23, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@aconital
Copy link

aconital commented Sep 23, 2022

We are using MongoDB with our laravel application and use the jenssegers/laravel-mongodb package. After we installed scout-apm-laravel our phpunit tests are failing with the following crash message. Is this a known issue?

Error: Cannot use object of type Illuminate\Support\Facades\Config as array
/var/www/api/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:469
/var/www/api/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:520
/var/www/api/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:112
/var/www/api/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:656
/var/www/api/vendor/scoutapp/scout-apm-php/src/Logger/FilteredLogLevelDecorator.php:83
/var/www/api/vendor/psr/log/Psr/Log/LoggerTrait.php:114
/var/www/api/vendor/scoutapp/scout-apm-php/src/Agent.php:342
/var/www/api/vendor/scoutapp/scout-apm-php/src/Agent.php:360
/var/www/api/vendor/scoutapp/scout-apm-php/src/MongoDB/QueryTimeCollector.php:48
/var/www/api/vendor/mongodb/mongodb/src/Operation/Find.php:341
/var/www/api/vendor/mongodb/mongodb/src/Collection.php:666
/var/www/api/vendor/jenssegers/mongodb/src/Collection.php:42
/var/www/api/vendor/jenssegers/mongodb/src/Query/Builder.php:399
/var/www/api/vendor/jenssegers/mongodb/src/Query/Builder.php:191
/var/www/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:625
/var/www/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:609
/var/www/api/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php:294
/var/www/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasOne.php:29
/var/www/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:553
/var/www/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:491
/var/www/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:440
/var/www/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2029

We even have SCOUT_MONITOR set to false but not sure why this package is still processing stuff.

@aconital aconital changed the title Illuminate\Support\Facades\Config as array When using MongoDB Cannot use object of type Illuminate\Support\Facades\Config as array When using MongoDB Sep 23, 2022
@asgrim
Copy link
Collaborator

asgrim commented Sep 23, 2022

@aconital Hey there, there's something definitely off here;

Firstly, you're completely right, SCOUT_MONITOR=false should disable collection completely; I've spotted a bug in our implementation and will fix that.

Secondly, the error from Laravel I can't quite pinpoint; I can see Scout is reaching its predefined span limit (which prevents us from consuming too much memory), but I'm not sure why Laravel's LogManager is throwing that error. I can look into this further, but could you let me know the output of composer show, and php -v so I know what combination of versions you're working with, so I can attempt to reproduce the issue please?

@asgrim asgrim added the bug Something isn't working label Sep 23, 2022
@asgrim asgrim self-assigned this Sep 23, 2022
@aconital
Copy link
Author

aconital commented Sep 23, 2022

Thanks for your quick response @asgrim. So this happens especially when we create a lot Models using Factory method for our unit tests. The models are using the MongoDB connection.

Here is the output of composer show:

algolia/algoliasearch-client-php      3.2.0               Algolia Search AP...
amphp/amp                             v2.6.2              A non-blocking co...
amphp/byte-stream                     v1.8.1              A stream abstract...
amphp/parallel                        v1.4.1              Parallel processi...
amphp/parallel-functions              v1.1.0              Parallel processi...
amphp/parser                          v1.0.0              A generator parse...
amphp/process                         v1.1.3              Asynchronous proc...
amphp/serialization                   v1.0.0              Serialization too...
amphp/sync                            v1.4.2              Mutex, Semaphore,...
amrnn/laravel-cursor-paginator        v2.0.0              Cursor pagination...
apache/thrift                         0.11.0              Apache Thrift RPC...
apix/cache                            1.3.5               A thin PSR-6 cach...
appstract/laravel-opcache             4.0.2               PHP OPcache Artis...
aws/aws-sdk-php                       3.173.19            AWS SDK for PHP -...
aws/aws-sdk-php-laravel               3.6.0               A simple Laravel ...
barryvdh/laravel-debugbar             v3.6.3              PHP Debugbar inte...
barryvdh/laravel-ide-helper           v2.8.2              Laravel IDE Helpe...
barryvdh/reflection-docblock          v2.0.6
berkayk/onesignal-laravel             v1.0.10             OneSignal Push Wr...
brainmaestro/composer-git-hooks       v2.8.5              Easily manage git...
brick/math                            0.9.3               Arbitrary-precisi...
bugsnag/bugsnag                       v3.28.0             Official Bugsnag ...
bugsnag/bugsnag-laravel               v2.24.0             Official Bugsnag ...
bugsnag/bugsnag-psr-logger            v1.4.5              Official Bugsnag ...
cboden/ratchet                        v0.4.4              PHP WebSocket lib...
clue/stdio-react                      v2.6.0              Async, event-driv...
clue/stream-filter                    v1.6.0              A simple and mode...
clue/term-react                       v1.3.0              Streaming termina...
clue/utf8-react                       v1.2.0              Streaming UTF-8 p...
composer/ca-bundle                    1.3.2               Lets you find a p...
composer/composer                     2.3.5               Composer helps yo...
composer/metadata-minifier            1.0.0               Small utility lib...
composer/pcre                         3.0.0               PCRE wrapping lib...
composer/semver                       3.3.2               Semver library th...
composer/spdx-licenses                1.5.7               SPDX licenses lis...
composer/xdebug-handler               3.0.3               Restarts a proces...
configcat/configcat-client            v6.0.0              ConfigCat is a fe...
dflydev/dot-access-data               v3.0.1              Given a deep data...
doctrine/cache                        2.2.0               PHP Doctrine Cach...
doctrine/collections                  1.6.8               PHP Doctrine Coll...
doctrine/dbal                         2.13.9              Powerful PHP data...
doctrine/deprecations                 v1.0.0              A small layer on ...
doctrine/event-manager                1.1.1               The Doctrine Even...
doctrine/inflector                    2.0.4               PHP Doctrine Infl...
doctrine/instantiator                 1.4.1               A small, lightwei...
doctrine/lexer                        1.2.3               PHP Doctrine Lexe...
dragonmantank/cron-expression         v3.3.1              CRON for PHP: Cal...
egulias/email-validator               2.1.25              A library for val...
evenement/evenement                   v3.0.1              Événement is a ...
facade/flare-client-php               1.9.1               Send PHP errors t...
facade/ignition                       2.17.5              A beautiful error...
facade/ignition-contracts             1.0.2               Solution contract...
fakerphp/faker                        v1.19.0             Faker is a PHP li...
fico7489/laravel-pivot                3.0.7               This package intr...
fideloper/proxy                       4.4.1               Set trusted proxi...
filp/whoops                           2.14.5              php error handlin...
firebase/php-jwt                      v6.2.0              A simple library ...
fruitcake/laravel-cors                v3.0.0              Adds CORS (Cross-...
fruitcake/php-cors                    v1.2.0              Cross-origin reso...
geo-io/interface                      v1.0.1              Geo I/O base inte...
geo-io/wkb-parser                     v1.0.2              Well-known binary...
geoip2/geoip2                         v2.12.2             MaxMind GeoIP2 PH...
gitonomy/gitlib                       v1.3.5              Library for acces...
google/apiclient                      v2.12.4             Client library fo...
google/apiclient-services             v0.251.0            Client library fo...
google/auth                           v1.21.0             Google Auth Libra...
googleads/googleads-php-lib           55.0.0              Google Ads APIs C...
graham-campbell/result-type           v1.0.4              An Implementation...
grimzy/laravel-mysql-spatial          5.0.0               MySQL spatial dat...
guzzlehttp/guzzle                     7.4.3               Guzzle is a PHP H...
guzzlehttp/promises                   1.5.1               Guzzle promises l...
guzzlehttp/psr7                       1.8.5               PSR-7 message imp...
hamcrest/hamcrest-php                 v2.0.1              This is the PHP p...
http-interop/http-factory-guzzle      1.2.0               An HTTP Factory u...
intervention/image                    2.7.2               Image handling an...
jean85/pretty-package-versions        2.0.5               A library to get ...
jenssegers/mongodb                    3.8.4               A MongoDB based E...
jmikola/geojson                       1.1.1               GeoJSON implement...
jolicode/jolinotif                    v2.4.0              Send desktop noti...
justinrainbow/json-schema             5.2.12              A library to vali...
kartik-v/bootstrap-fileinput          v5.2.8              An enhanced HTML ...
kickbox/kickbox                       2.2.7               Official kickbox ...
kitloong/laravel-migrations-generator v5.2.2              Generates Laravel...
kozz/laravel-guzzle-provider          7.1.0               Guzzle 5/6 Servic...
laravel/framework                     v8.83.14            The Laravel Frame...
laravel/legacy-factories              v1.3.0              The legacy versio...
laravel/scout                         v8.6.1              Laravel Scout pro...
laravel/serializable-closure          v1.2.0              Laravel Serializa...
laravel/slack-notification-channel    v2.4.0              Slack Notificatio...
laravel/tinker                        v2.7.2              Powerful REPL for...
laravel/ui                            v3.4.6              Laravel UI utilit...
laravelium/sitemap                    8.0.1               Laravelium Sitema...
lcobucci/clock                        2.2.0               Yet another clock...
lcobucci/jwt                          4.1.5               A simple library ...
league/commonmark                     2.3.1               Highly-extensible...
league/config                         v1.1.1              Define configurat...
league/csv                            9.8.0               CSV data manipula...
league/flysystem                      1.1.9               Filesystem abstra...
league/flysystem-aws-s3-v3            1.0.29              Flysystem adapter...
league/mime-type-detection            1.11.0              Mime-type detecti...
loilo/fuse                            6.6.2               Fuzzy search for ...
lorisleiva/cron-translator            v0.3.2              Makes CRON expres...
lvht/geohash                          v1.1.0              geohash like pyth...
maennchen/zipstream-php               2.2.1               ZipStream is a li...
maximebf/debugbar                     v1.16.5             Debug bar in the ...
maxmind-db/reader                     v1.11.0             MaxMind DB Reader...
maxmind/web-service-common            v0.9.0              Internal MaxMind ...
meilisearch/meilisearch-php           v0.23.2             PHP wrapper for t...
mikecbrant/php-rest-client            dev-master 98f2c25  PSR-4 PHP Package...
mockery/mockery                       1.3.5               Mockery is a simp...
mongodb/mongodb                       1.11.0              MongoDB driver li...
monolog/monolog                       2.6.0               Sends your logs t...
mtdowling/jmespath.php                2.5.0               Declaratively spe...
myclabs/deep-copy                     1.11.0              Create deep copie...
myclabs/php-enum                      1.8.3               PHP Enum implemen...
namshi/jose                           7.2.3               JSON Object Signi...
nesbot/carbon                         2.58.0              An API extension ...
nette/schema                          v1.2.2              📐 Nette Schema...
nette/utils                           v3.2.7              🛠  Nette Utils...
nikic/php-parser                      v4.13.2             A PHP parser writ...
nunomaduro/collision                  v5.11.0             Cli error handlin...
nunomaduro/larastan                   1.0.3               Larastan - Discov...
nunomaduro/laravel-console-task       v1.7.0              Laravel Console T...
ondram/ci-detector                    4.1.0               Detect continuous...
opis/closure                          3.6.3               A library that ca...
paragonie/constant_time_encoding      v2.5.0              Constant-time Imp...
paragonie/random_compat               v9.99.100           PHP 5.x polyfill ...
paragonie/sodium_compat               v1.17.1             Pure PHP implemen...
pda/pheanstalk                        v4.0.4              PHP client for be...
phar-io/manifest                      2.0.3               Component for rea...
phar-io/version                       3.2.1               Library for handl...
php-http/client-common                2.5.0               Common HTTP Clien...
php-http/discovery                    1.14.2              Finds installed H...
php-http/httplug                      2.3.0               HTTPlug, the HTTP...
php-http/message                      1.13.0              HTTP Message rela...
php-http/message-factory              v1.0.2              Factory interface...
php-http/promise                      1.1.0               Promise used for ...
php-open-source-saver/jwt-auth        1.4.2               JSON Web Token Au...
phpcompatibility/php-compatibility    9.3.5               A set of sniffs f...
phpdocumentor/reflection-common       2.2.0               Common reflection...
phpdocumentor/reflection-docblock     5.3.0               With this compone...
phpdocumentor/type-resolver           1.6.1               A PSR-5 based res...
phpoption/phpoption                   1.8.1               Option Type for PHP
phpro/grumphp                         v1.12.0             A composer plugin...
phpseclib/phpseclib                   3.0.14              PHP Secure Commun...
phpspec/prophecy                      v1.15.0             Highly opinionate...
phpstan/phpstan                       1.8.1               PHPStan - PHP Sta...
phpstan/phpstan-mockery               1.0.0               PHPStan Mockery e...
phpunit/php-code-coverage             9.2.15              Library that prov...
phpunit/php-file-iterator             3.0.6               FilterIterator im...
phpunit/php-invoker                   3.1.1               Invoke callables ...
phpunit/php-text-template             2.0.4               Simple template e...
phpunit/php-timer                     5.0.3               Utility class for...
phpunit/phpunit                       9.5.20              The PHP Unit Test...
predis/predis                         v1.1.10             Flexible and feat...
psr/cache                             1.0.1               Common interface ...
psr/container                         1.1.2               Common Container ...
psr/event-dispatcher                  1.0.0               Standard interfac...
psr/http-client                       1.0.1               Common interface ...
psr/http-factory                      1.0.1               Common interfaces...
psr/http-message                      1.0.1               Common interface ...
psr/http-server-handler               1.0.1               Common interface ...
psr/http-server-middleware            1.0.1               Common interface ...
psr/log                               1.1.4               Common interface ...
psr/simple-cache                      1.0.1               Common interfaces...
psy/psysh                             v0.11.5             An interactive sh...
pusher/pusher-php-server              7.0.2               Library for inter...
ralouphie/getallheaders               3.0.3               A polyfill for ge...
ramsey/collection                     1.2.2               A PHP library for...
ramsey/uuid                           4.3.1               A PHP library for...
rap2hpoutre/laravel-log-viewer        v2.2.0              A Laravel log reader
ratchet/rfc6455                       v0.3.1              RFC6455 WebSocket...
react/cache                           v1.1.1              Async, Promise-ba...
react/dns                             v1.9.0              Async DNS resolve...
react/event-loop                      v1.3.0              ReactPHP's core r...
react/promise                         v2.9.0              A lightweight imp...
react/promise-timer                   v1.8.0              A trivial impleme...
react/socket                          v1.11.0             Async, streaming ...
react/stream                          v1.2.0              Event-driven read...
rector/rector                         0.12.19             Instant Upgrade a...
scoutapp/scout-apm-laravel            v2.2.0              Scout Application...
scoutapp/scout-apm-php                8.6.0               Scout Application...
sebastian/cli-parser                  1.0.1               Library for parsi...
sebastian/code-unit                   1.0.8               Collection of val...
sebastian/code-unit-reverse-lookup    2.0.3               Looks up which fu...
sebastian/comparator                  4.0.6               Provides the func...
sebastian/complexity                  2.0.2               Library for calcu...
sebastian/diff                        4.0.4               Diff implementation
sebastian/environment                 5.1.4               Provides function...
sebastian/exporter                    4.0.4               Provides the func...
sebastian/global-state                5.0.5               Snapshotting of g...
sebastian/lines-of-code               1.0.3               Library for count...
sebastian/object-enumerator           4.0.4               Traverses array s...
sebastian/object-reflector            2.0.4               Allows reflection...
sebastian/recursion-context           4.0.4               Provides function...
sebastian/resource-operations         3.0.3               Provides a list o...
sebastian/type                        3.0.0               Collection of val...
sebastian/version                     3.0.2               Library that help...
seld/jsonlint                         1.9.0               JSON Linter
seld/phar-utils                       1.2.0               PHAR file format ...
sixlive/dotenv-editor                 v1.3.0              A tool to edit ph...
spatie/laravel-package-tools          1.12.1              Tools for creatin...
spatie/laravel-permission             5.5.4               Permission handli...
spatie/laravel-query-builder          4.0.3               Easily build Eloq...
spatie/pdf-to-image                   2.2.0               Convert a pdf to ...
spatie/phpunit-watcher                1.23.6              Automatically rer...
squizlabs/php_codesniffer             3.6.2               PHP_CodeSniffer t...
staudenmeir/belongs-to-through        v2.11.2             Laravel Eloquent ...
stella-maris/clock                    0.1.4               A pre-release of ...
storyblok/php-client                  v1.6.0              Storyblok Client ...
swiftmailer/swiftmailer               v6.3.0              Swiftmailer, free...
symfony/config                        v6.0.9              Helps you find, l...
symfony/console                       v5.4.9              Eases the creatio...
symfony/css-selector                  v6.0.3              Converts CSS sele...
symfony/debug                         v4.4.41             Provides tools to...
symfony/dependency-injection          v6.0.9              Allows you to sta...
symfony/deprecation-contracts         v3.0.1              A generic functio...
symfony/dotenv                        v6.0.5              Registers environ...
symfony/error-handler                 v5.4.9              Provides tools to...
symfony/event-dispatcher              v6.0.9              Provides tools th...
symfony/event-dispatcher-contracts    v3.0.1              Generic abstracti...
symfony/filesystem                    v6.0.9              Provides basic ut...
symfony/finder                        v5.4.8              Finds files and d...
symfony/http-foundation               v5.4.9              Defines an object...
symfony/http-kernel                   v5.4.9              Provides a struct...
symfony/mime                          v5.4.9              Allows manipulati...
symfony/options-resolver              v6.0.3              Provides an impro...
symfony/polyfill-ctype                v1.25.0             Symfony polyfill ...
symfony/polyfill-iconv                v1.25.0             Symfony polyfill ...
symfony/polyfill-intl-grapheme        v1.25.0             Symfony polyfill ...
symfony/polyfill-intl-idn             v1.25.0             Symfony polyfill ...
symfony/polyfill-intl-normalizer      v1.25.0             Symfony polyfill ...
symfony/polyfill-mbstring             v1.25.0             Symfony polyfill ...
symfony/polyfill-php56                v1.20.0             Symfony polyfill ...
symfony/polyfill-php72                v1.25.0             Symfony polyfill ...
symfony/polyfill-php73                v1.25.0             Symfony polyfill ...
symfony/polyfill-php80                v1.25.0             Symfony polyfill ...
symfony/polyfill-php81                v1.25.0             Symfony polyfill ...
symfony/process                       v5.4.8              Executes commands...
symfony/psr-http-message-bridge       v2.1.2              PSR HTTP message ...
symfony/routing                       v5.4.8              Maps an HTTP requ...
symfony/serializer                    v5.4.9              Handles serializi...
symfony/service-contracts             v2.5.1              Generic abstracti...
symfony/string                        v6.0.9              Provides an objec...
symfony/translation                   v6.0.9              Provides tools to...
symfony/translation-contracts         v3.0.1              Generic abstracti...
symfony/var-dumper                    v5.4.9              Provides mechanis...
symfony/yaml                          v6.0.3              Loads and dumps Y...
thedoctor0/laravel-factory-generator  1.2.3               Generate Laravel ...
thenpingme/laravel                    2.4.9               Zero config sched...
theseer/tokenizer                     1.2.1               A small library f...
tijsverkoyen/css-to-inline-styles     2.2.4               CssToInlineStyles...
troydavisson/phrets                   2.6.3               RETS library in PHP
tutorigo/laravel-ide-macros           1.6.0               Generating a help...
twilio/sdk                            6.1.0               A PHP wrapper for...
vlucas/phpdotenv                      v5.4.1              Loads environment...
voku/portable-ascii                   1.6.1               Portable ASCII li...
webmozart/assert                      1.10.0              Assertions to val...
wildbit/postmark-php                  4.0.4               The officially su...
wildbit/swiftmailer-postmark          3.3.0               A Swiftmailer Tra...
yosymfony/resource-watcher            v3.0.0              A simple resource...
z4kn4fein/php-semver                  v1.2.0              Semantic Versioni...

and out put of php -v:

PHP 8.0.19 (cli) (built: May 17 2022 18:48:59) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.19, Copyright (c) Zend Technologies
with Zend OPcache v8.0.19, Copyright (c), by Zend Technologies

@aconital
Copy link
Author

aconital commented Sep 23, 2022

Not sure if this is related but we experience the same scenario where memory usages keeps increasing laravel/framework#44214

@asgrim
Copy link
Collaborator

asgrim commented Sep 26, 2022

@aconital

First up, the issue with MongoDB monitoring occuring even when monitoring is disabled has now been fixed in scoutapp/scout-apm-php:8.6.1. Thanks for reporting that!

However, I can't seem to reproduce the issue you have with the framework version you have. In the default Laravel application setup, $this->app['config'] is an instance of \Illuminate\Config\Repository. Your error suggests that for your application, it is an instance of \Illuminate\Support\Facades\Config, which is incorrect; the facade is not an array-accessible object. I'm wondering if in your application you are replacing the config key with the facade instead of the actual config repository? This was the only way I could simulate that particular error.

@aconital
Copy link
Author

@asgrim thanks for the quick fix.

We'll keep and eye on the Config issue to see if we can pinpoint the problem. I'm hoping this is just an issue when we run PHPUnit tests and not in production. Thanks again

@asgrim
Copy link
Collaborator

asgrim commented Sep 26, 2022

Yep - please do let us know; not sure why the config facade would be assigned to $app['config'] :/ maybe something else is interacting funny in Laravel.

@asgrim asgrim closed this as completed Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants