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

Call to undefined function Sentry\metrics() #885

Closed
jshwhitlow opened this issue Apr 16, 2024 · 8 comments · Fixed by #886
Closed

Call to undefined function Sentry\metrics() #885

jshwhitlow opened this issue Apr 16, 2024 · 8 comments · Fixed by #886
Assignees

Comments

@jshwhitlow
Copy link

How do you use Sentry?

Sentry SaaS (sentry.io)

SDK version

4.4.1

Steps to reproduce

Whenever we do php artisan or composer update/install with sentry-laravel 4.2 through 4.4.1 we get the error Call to undefined function Sentry\metrics()

Downgrading to 4.1.2 resolves this error for us. Attempted to use php artisan/composer update with both php 7.4 and 8.2 on CentOS 7, both produce the same error.

Those versions have this commit which is relevant:
7b19858

Expected result

php artisan / composer update does not produce this error

Actual result

[2024-04-16 13:10:05] production.ERROR: Call to undefined function Sentry\metrics() {"exception":"[object] (Error(code: 0): Call to undefined function Sentry\\metrics() at /vendor/sentry/sentry-laravel/src/Sentry/Laravel/Integration.php:128)
[stacktrace]
#0 /vendor/sentry/sentry-laravel/src/Sentry/Laravel/EventHandler.php(358): Sentry\\Laravel\\Integration::flushEvents()
#1 /vendor/sentry/sentry-laravel/src/Sentry/Laravel/EventHandler.php(190): Sentry\\Laravel\\EventHandler->commandFinishedHandler()
#2 /vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(404): Sentry\\Laravel\\EventHandler->__call()
#3 /vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(249): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}()
#4 /vendor/laravel/framework/src/Illuminate/Console/Application.php(96): Illuminate\\Events\\Dispatcher->dispatch()
#5 /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run()
#6 /artisan(35): Illuminate\\Foundation\\Console\\Kernel->handle()
#7 {main}
"}
@cleptric
Copy link
Member

Can you please run composer upgrade -W sentry/sentry-laravel, so all sub dependencies are updated as well?

@jshwhitlow
Copy link
Author

Sorry for late reply, I attempted to revert my composer change and ran command as you suggested. It updated to 4.5.1 and also updated numerous sub dependencies:

  - Upgrading symfony/console (v5.4.36 => v5.4.39)
  - Upgrading symfony/error-handler (v5.4.38 => v5.4.39)
  - Upgrading symfony/event-dispatcher (v5.4.35 => v5.4.39)
  - Upgrading symfony/finder (v5.4.35 => v5.4.39)
  - Upgrading symfony/http-foundation (v5.4.38 => v5.4.39)
  - Upgrading symfony/http-kernel (v5.4.38 => v5.4.39)
  - Upgrading symfony/mime (v5.4.38 => v5.4.39)
  - Upgrading symfony/options-resolver (v5.4.21 => v5.4.39)
  - Upgrading symfony/process (v5.4.36 => v5.4.39)
  - Upgrading symfony/routing (v5.4.38 => v5.4.39)
  - Upgrading symfony/string (v5.4.36 => v5.4.39)
  - Upgrading symfony/translation (v5.4.35 => v5.4.39)
  - Upgrading symfony/var-dumper (v5.4.38 => v5.4.39)

However, the error undefined function Sentry\metrics() is still present.

@cleptric
Copy link
Member

What version does composer show output for sentry/sentry?

@jshwhitlow
Copy link
Author

versions : * 4.7.0

@cleptric cleptric reopened this Apr 30, 2024
@cleptric
Copy link
Member

Can you tell us a bit more about how you setup the SDK? "By the book" https://docs.sentry.io/platforms/php/guides/laravel/ or something custom? Is this error happening on one machine or multiple? Did you dump the composer autoloader, etc. ?

@jshwhitlow
Copy link
Author

I wasn't the original developer who created the repo, but I explored to see how things are done and checked your guide. This install is on Laravel 8.83.27 at the moment. Its being composer required like normal. "sentry/sentry-laravel": "*",

So seems like a normal install for the most part.

Most of our laravel installs don't seem to have the config/sentry.php file, but the required .env entries are present. (and this plugin works on all of them so seems like the file must not be required)

I attempted to run php artisan sentry:publish command and stepped through the prompts, but the undefined metrics() issue will appear when you select 'no' to the javascript sdk step.

I did a composer dump-autoload and that did not fix it.

After checking the install instructions of different laravel versions and comparing them to what I see in the code, seems like we followed instructions for Laravel 5.x for original install back in 2018. I updated our app/Exceptions/Handler.php to match Laravel 8.x instructions, but that obviously doesn't have anything to do with the actual error.

The original composer lock versions prior to me attempting to update were (at present the production site runs fine with these versions):

sentry/sentry: 3.12.0
sentry/sentry-laravel: 3.1.2

I can reproduce this issue both on the live production server and our development server in multiple different repos. My next steps will probably be to load an empty Laravel 8.x project and just try to composer install this project and see if it still happens.

@cleptric
Copy link
Member

cleptric commented May 2, 2024

I would advice against "sentry/sentry-laravel": "*", it's better to at least lock it to the latest major.

Running a small Laravel 8 sample app hails no such errors for me, the metrics are emitted correctly.

laravel/framework                  v8.83.27 The Laravel Framework.
sentry/sentry                      4.7.0    PHP SDK for Sentry (http://sentry.io)
sentry/sentry-laravel              4.5.1    Laravel SDK for Sentry (https://sentry.io)

Something that is odd:

[2024-04-16 13:10:05] production.ERROR: Call to undefined function Sentry\metrics() {"exception":"[object] (Error(code: 0): Call to undefined function Sentry\\metrics() at /vendor/sentry/sentry-laravel/src/Sentry/Laravel/Integration.php:128)

Line 128, whereas it should be 125 instead. https://github.com/getsentry/sentry-laravel/blob/master/src/Sentry/Laravel/Integration.php#L125

@stayallive
Copy link
Collaborator

Hey @jshwhitlow, did you manage to get any further with investigating?

We have not had any other reports of this occurring for others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants