mantas-done / laravel-apm

Application monitoring for Laravel
MIT License
58 stars 9 forks source link

Log file isn't created #7

Open netdjw opened 8 months ago

netdjw commented 8 months ago

I made all steps from README, but log file isn't created so the package always show nothing on charts.

Isn't miss the documentation register a middleware or similar thing?

mantas-done commented 8 months ago

Hi @netdjw , middleware is registered automatically. I have updated the code, please do: composer update Now when you will visit /apm url, controller will show an error if it can't create /storage/app/apm folder. If that is the case, it means that file permissions are incorrect. Please report whether you will get an error after the composer update.

netdjw commented 8 months ago

Hi @mantas-done , I updated to v1.0.10, but still the same.

This is my config/apm.php:

<?php

return [
    /**
     * Enable or disable APM
     */
    'enabled' => env('MONITORING_APM', false),

    /**
     * How many results per page to show
     */
    'per_page' => 100,

    /**
     * Logs only part of requests. 1 - 100%, 0.1 - 10% of requests.
     */
    'sampling' => 1,

    /**
     * Log queries of pages that spent in SQL more than given seconds
     */
    'slow' => 3,
];

The storage/app/apm/ directory has 777 mod for testing.

I made a test exception in my code to verify the middleware is in the stacktrace and I see this:

Done \ LaravelAPM \ Middleware \ DelayedWriter: 12 handle

So the middleware is loaded just not write the log file.

mantas-done commented 8 months ago

Can you try setting 'enabled' to 'true' or adding to your .env file: MONITORING_APM=1

If that didn't work I will think of a better way to debug.

On Sat, Feb 10, 2024, 07:49 Balázs Winkler @.***> wrote:

Hi @mantas-done https://github.com/mantas-done , I updated to v1.0.10, but still the same.

This is my config/apm.php:

<?php return [ /* Enable or disable APM */ 'enabled' => env('MONITORING_APM', false),

/**     * How many results per page to show     */
'per_page' => 100,

/**     * Logs only part of requests. 1 - 100%, 0.1 - 10% of requests.     */
'sampling' => 1,

/**     * Log queries of pages that spent in SQL more than given seconds     */
'slow' => 3,

];

The storage/app/apm/ directory has 777 mod for testing.

I made a test exception in my code to verify the middleware is in the stacktrace and I see this:

Done \ LaravelAPM \ Middleware \ DelayedWriter: 12 handle

So the middleware is loaded just not write the log file.

— Reply to this email directly, view it on GitHub https://github.com/mantas-done/laravel-apm/issues/7#issuecomment-1936889212, or unsubscribe https://github.com/notifications/unsubscribe-auth/AECVOJQE7XJB5CHFNYR426DYS4C6JAVCNFSM6AAAAABC5H7BZKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZWHA4DSMRRGI . You are receiving this because you were mentioned.Message ID: @.***>

netdjw commented 8 months ago

Still not work. I tried with 'enabled', true and 1 values too.

I used dd to catch what methods are calling, but not called any method of any watcher. But DelayedWriter's handle method is called with this code:

    public function handle($request, Closure $next)
    {
        return $next($request);
    }

I think this isn't do anything.

LogWriter's methods also not called.

netdjw commented 8 months ago

Sorry about slow replies, I'm was busy a while.

mantas-done commented 8 months ago

image DelayedWriter writes to file only after the user's request is returned. (terminate method) Could you add Log::info('test'); into different places in code to check whether LogWriter::write(); is executed on your system?

netdjw commented 8 months ago

I added and not executing.

mantas-done commented 8 months ago

Just making sure, you have looked into your log files? (because terminate method executes when the response is already sent to the browser and doing dd() or echo won't show up in the browser).

kamilersz commented 2 months ago

Got the same issue. Added Log::info('test'); in DelayedResponse, log test shown on file but no request apm is logged

mantas-done commented 2 months ago

Got the same issue. Added Log::info('test'); in DelayedResponse, log test shown on file but no request apm is logged

if possible, can you also add Log::info('test') inside the ::write() method and see where it gets stuck. Whether it can't create a directory or file. That would help me to fix this issue. Because I don't know how to reproduce this problem on my end.

kamilersz commented 2 months ago

it seems that the listener got registered here $this->app['events']->listen(RequestHandled::class, [RequestWatcher::class, 'record']);

but RequestWatcher::class, 'record' method isn't called

kamilersz commented 2 months ago

It seems that I ran using laravel 5.3

by adding this, the requests are logged $this->app['events']->listen('kernel.handled', [RequestWatcher::class, 'record']);

mantas-done commented 2 months ago

In composer.json, it requires at least Laravel 5.5.

kamilersz commented 2 months ago

don't know why my composer can install this though. but now works on my side