ScoutAPM PHP Agent for the Laravel Framework

Overview

Scout Laravel APM Agent

Monitor the performance of PHP Laravel applications with Scout's PHP APM Agent. Detailed performance metrics and transaction traces are collected once the scout-apm package is installed and configured.

Requirements

  • PHP Version: PHP 7.1+
  • Laravel Version: 5.5+

Quick Start

A Scout account is required. Signup for Scout.

composer require scoutapp/scout-apm-laravel

Then use Laravel's artisan vendor:publish to ensure configuration can be cached:

php artisan vendor:publish --provider="Scoutapm\Laravel\Providers\ScoutApmServiceProvider"

Composer 2 and PHP 7.1-7.3 support

If you are using PHP 7.1, 7.2, or 7.3, and you have started using Composer v2, please read this. scoutapp/scout-apm-php depends on a package called ocramius/package-versions. However, this package only provides support for the new Composer 2 series in version 1.8 or above, which requires PHP 7.4 as a minimum. If you are using PHP 7.1-7.3, and you would like to use Composer 2, you have the following options:

  • Upgrade to PHP 7.4 (this is the recommended approach!)
  • Don't use Composer 2 (stick to Composer 1)
  • Require the polyfill composer/package-versions-deprecated (provides support for Composer 2 in PHP 7.1-7.3)

If you opt to use the polyfill, you would install both packages, for example:

composer require scoutapp/scout-apm-laravel composer/package-versions-deprecated

Configuration

In your .env file, make sure you set a few configuration variables:

SCOUT_KEY=ABC0ZABCDEFGHIJKLMNOP
SCOUT_NAME="My Laravel App"
SCOUT_MONITOR=true

Your key can be found in the Scout organization settings page.

Logging Verbosity

Once you have set up Scout and are happy everything is working, you can reduce the verbosity of the library's logging system. The library is intentionally very noisy by default, which gives us more information to support our customers if something is broken. However, if everything is working as expected, these logs can be reduced by setting the log_level configuration key to a higher Psr\Log\LogLevel. For example, if you are using .env configuration:

SCOUT_LOG_LEVEL=error

Or if you are using config/scout_apm.php:

$config[\Scoutapm\Config\ConfigKey::LOG_LEVEL] = \Psr\Log\LogLevel::ERROR;

Any of the constants defined in \Psr\Log\LogLevel are acceptable values for this configuration option.

Documentation

For full installation and troubleshooting documentation, visit our help site.

Support

Please contact us at [email protected] or create an issue in this repo.

Capabilities

The Laravel library:

  • Registers a service \Scoutapm\ScoutApmAgent::class into the container (useful for dependency injection)
  • Provides a Facade \Scoutapm\Laravel\Facades\ScoutApm
  • Wraps view engines to monitor view rendering times
  • Injects several middleware for monitoring controllers and sending statistics to the Scout Core Agent
  • Adds a listener to the database connection to instrument SQL queries

Custom Instrumentation

In order to perform custom instrumentation, you can wrap your code in a call to the instrument method. For example, given some code to be monitored:

$request = new ServiceRequest();
$request->setApiVersion($version);

Using the provided Facade for Laravel, you can wrap the call and it will be monitored.

// At top, with other imports
use Scoutapm\Events\Span\Span;
use Scoutapm\Laravel\Facades\ScoutApm;

// Replacing the above code
$request = ScoutApm::instrument(
    'Custom',
    'Building Service Request',
    static function (Span $span) use ($version) {
        $request = new ServiceRequest();
        $request->setApiVersion($version);
        return $request;
    }
);
Comments
  • Memory issues remaining in Laravel queue monitoring

    Memory issues remaining in Laravel queue monitoring

    Sorry to post on an already closed issue, but I installed Scout yesterday on one of my Laravel app, and I get the exact same issue as @lchachurski .

    The memory issue stops when I disable the Laravel queue monitoring.

    I'm on Laravel v7.12.0 using scoutapp/scout-apm-laravel v1.5.0 with scoutapp/scout-apm-php v4.4.0.

    Do you need any more details? Thanks!

    Originally posted by @philippe-tellier in https://github.com/scoutapp/scout-apm-php/issues/168#issuecomment-653156016

    bug 
    opened by asgrim 10
  • Add Laravel Lumen support

    Add Laravel Lumen support

    scoutAPM doesn't seem to support Laravel Lumen, I opened this issue to request adding support to it.

    Argument 1 passed to Scoutapm\Laravel\Providers\ScoutApmServiceProvider::Scoutapm\Laravel\Providers\{closure}() must
     implement interface Illuminate\Contracts\Foundation\Application, instance of Laravel\Lumen\Application 
    given, called in /****/vendor/illuminate/container/Container.php on line 799
    
    enhancement 
    opened by imhmdb 10
  • Cannot use object of type Illuminate\Support\Facades\Config as array When using MongoDB

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

    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.

    bug 
    opened by aconital 6
  • Site is throwing a 500 error - Laravel Scout Agent is starting

    Site is throwing a 500 error - Laravel Scout Agent is starting

    Description: I installed Scout APM on my site last night and everything was fine. This morning the site is throwing a 500 error.

    Error: Laravel Scout Agent is starting

    Environment: Laravel Version: 5.8.*

    invalid question 
    opened by RTSchriner 5
  • Span limit of 1500 has been reached trying to start span for

    Span limit of 1500 has been reached trying to start span for "SQL/Query"

    Hi;

    I get Span limit of 1500 has been reached trying to start span for "SQL/Query" error on some queries. What is the reason and how can I solve this?

    Thanks.

    question 
    opened by ysb 5
  • Test against custom blade directives

    Test against custom blade directives

    We had a report of an issue with a custom blade directive.

    I did notice that installing your Laravel package broke a custom Blade directive
    that we use from the spatie/laravel-permission package.
    What’s the best way to troubleshoot this?
    For now, I was able to refactor usage of that `@role` directive,
    but I’d like to get that fixed and understand why it broke.
    

    I'm asking for any exception or backtrace, but this is worth looking into.

    bug 
    opened by cschneid 5
  • ERROR: Log level WARN was not a valid PSR-3 compatible log level. Should be one of: debug, info, notice, warning, error, critical, alert, emergency

    ERROR: Log level WARN was not a valid PSR-3 compatible log level. Should be one of: debug, info, notice, warning, error, critical, alert, emergency

    Laravel: v8.55.0 PHP: 7.4

    Issue: 1: Generating optimized autoload files Class Scoutapm\ScoutApmBundle\Twig\TwigMethods located in ./vendor/scoutapp/scout-apm-php/src/ScoutApmBundle/Twig/TwigMethods-Twig2.php does not comply with psr-4 autoloading standard. Skipping. Class Scoutapm\ScoutApmBundle\Twig\TwigMethods located in ./vendor/scoutapp/scout-apm-php/src/ScoutApmBundle/Twig/TwigMethods-Twig3.php does not comply with psr-4 autoloading standard. Skipping.

    Issue: 2: [2021-08-21 11:43:56] staging.ERROR: Log level WARN was not a valid PSR-3 compatible log level. Should be one of: debug, info, notice, warning, error, critical, alert, emergency {"exception":"[object] (Webmozart\Assert\InvalidArgumentException(code: 0): Log level WARN was not a valid PSR-3 compatible log level. Should be one of: debug, info, notice, warning, error, critical, alert, emergency at /tmp/build_9de6b4cc/vendor/webmozart/assert/src/Assert.php:2060)

    question 
    opened by hasnat-we 4
  • composer changes in the latest version

    composer changes in the latest version

    Does the latest version work in Laravel 7?

    I cannot install the package using the latest version:

     Conclusion: don't install ramsey/uuid 4.0.1|install ramsey/uuid 3.3.0|install ramsey/uuid 3.4.0 all the way to version 3.7.3
    

    I think the issue comes from v4.0.1 of ramsey/uuid which does not work well with "paragonie/random_compat v9.99.99", and symfony/polyfill-uuid uses the paragonie package.

    bug duplicate dependencies 
    opened by pixelplant 4
  • Add an option to disable instrumenting Laravel queues

    Add an option to disable instrumenting Laravel queues

    We use scout APM in a production environment of high usage, when we updated to v1.2 that adds support to instrument Laravel queues we noticed that the workers became drastically slower than the usual, we downgraded back to v1.1 and the performance issue disappeared.

    I couldn't figure out exactly why it makes the jobs slower, but my request is to add an option so we can disable instrumenting Laravel queues and that would solve our issue.

    bug 
    opened by imhmdb 4
  • Configuration conflict with Laravel's Scout

    Configuration conflict with Laravel's Scout

    As per comment:

    scout apm using the name scout.php for configs conflicts with the config file of the first party package Laravel/scout https://github.com/laravel/scout

    We can rename the config (and thus, the key used) to scoutapm but I'm not sure we can do this in a BC way. Need to check.

    bug 
    opened by asgrim 4
  • Laravel 9.x Compatibility

    Laravel 9.x Compatibility

    This is an automated pull request from Shift to update your package code and dependencies to be compatible with Laravel 9.x.

    Before merging, you need to:

    • Checkout the l9-compatibility branch
    • Review all comments for additional changes
    • Thoroughly test your package

    If you do find an issue, please report it by commenting on this PR to help improve future automation.

    invalid 
    opened by laravel-shift 3
  • Feature request: support Laravel 5.1+ (currently 5.5+)

    Feature request: support Laravel 5.1+ (currently 5.5+)

    A friend of mine @liam-wiltshire was asking around for Laravel-focused APMs. I suggested they try out Scout, but they are on an older version of Laravel than we support out the box.

    He did a bit of work to get some of the Laravel agent working on Laravel 5.1 and up. See diff - I pulled Liam's changes into a branch in case the fork is deleted: https://github.com/scoutapp/scout-apm-laravel/compare/experimental-laravel-51-support

    Investigate bringing these changes into this library and see if we can support earlier Laravel versions.

    enhancement nice to have 
    opened by asgrim 2
Releases(v2.2.0)
  • v2.2.0(Mar 8, 2022)

  • v2.1.0(Jan 19, 2022)

  • v2.0.0(Feb 23, 2021)

    Added

    • Nothing.

    Changed

    • #74 Updated to scout-apm-php ^6.0
      • scout-apm-laravel is now a meta package only, which defines which versions of Laravel we support. You should still use this package directly if you use Laravel to ensure you are running a compatible Laravel version.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • v1.8.0(Dec 16, 2020)

  • v1.7.0(Nov 10, 2020)

    1.7.0 - 2020-11-10

    Added

    • #68 Documentation on Composer v2 + PHP 7.1-7.3 support
    • #67 Documentation for log level in README.md

    Changed

    • Nothing.

    Deprecated

    • #68 Require scoutapp/scout-apm-php:^5.1.
      • Note, if you use any of the Span::INSTRUMENT_* constants, these are deprecated, you should now use the new SpanReference::INSTRUMENT_* constants. We plan to remove the Span::INSTRUMENT_* constants with the release of scout-apm-php:6.0.0.

    Removed

    • Nothing.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Sep 11, 2020)

  • v1.5.0(May 28, 2020)

  • v1.4.0(May 27, 2020)

  • v1.3.0(Mar 17, 2020)

    Added

    • #51 Added support for Laravel 7.x series

    Changed

    • #52 Require minimum ^4.2 for scout-apm-php to upgrade to core-agent 1.2.8

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • v1.2.3(Jan 9, 2020)

  • v1.2.2(Jan 9, 2020)

  • v1.2.1(Dec 31, 2019)

  • v1.2.0(Dec 19, 2019)

    Added

    • Added support for Laravel Queues (#36, #40)
    • Uncaught exceptions now cause the error tag to be added to the request (#39)

    Changed

    • [BC] Renamed Scout APM's config file to scout_apm.php - if you use this, you will need to rename yours too (#38)
      • This was done to avoid a conflict with Laravel Scout configuration.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Dec 9, 2019)

  • v1.0.0(Dec 4, 2019)

    Changed

    • Required scoutapp/scout-apm-php at ^2.0
    • Use Laravel's Cache, if configured, for the agent to cache metadata
    • Removed duplicate [Scout] text from log messages
    Source code(tar.gz)
    Source code(zip)
Owner
Scout APM
Scout APM
MeiliSearch PHP is the MeiliSearch API client for PHP developers.

MeiliSearch PHP is the MeiliSearch API client for PHP developers. ⚡ The MeiliSearch API client written for PHP ??

MeiliSearch 362 Jan 4, 2023
[Deprecated] We now recommend using Laravel Scout, see =>

[DEPRECATED] Algolia Search API Client for Laravel Algolia Search is a hosted full-text, numerical, and faceted search engine capable of delivering re

Algolia 240 Nov 25, 2022
Maps Laravel Eloquent models to Elasticsearch types

Elasticquent Elasticsearch for Eloquent Laravel Models Elasticquent makes working with Elasticsearch and Eloquent models easier by mapping them to Ela

Elasticquent 1.3k Jan 4, 2023
Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch, by providing a fluent syntax for mapping, querying, and storing eloquent models.

Plastic is an Elasticsearch ODM and mapper for Laravel. It renders the developer experience more enjoyable while using Elasticsearch, by providing a f

Sleiman Sleiman 511 Dec 31, 2022
A search package for Laravel 5.

Search Package for Laravel 5 This package provides a unified API across a variety of different full text search services. It currently supports driver

Mark Manos 354 Nov 16, 2022
Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

TNTSearch Driver for Laravel Scout - Laravel 5.3 - 8.0 This package makes it easy to add full text search support to your models with Laravel 5.3 to 8

TNT Studio 1k Dec 27, 2022
Laravel Scout provides a driver based solution to searching your Eloquent models.

Introduction Laravel Scout provides a simple, driver-based solution for adding full-text search to your Eloquent models. Once Scout is installed and c

The Laravel Framework 1.3k Dec 31, 2022
Unmaintained: Laravel Searchy makes user driven searching easy with fuzzy search, basic string matching and more to come!

!! UNMAINTAINED !! This package is no longer maintained Please see Issue #117 Here are some links to alternatives that you may be able to use (I do no

Tom Lingham 533 Nov 25, 2022
Elasticsearch driver for Laravel Scout

Elasticsearch driver for Laravel Scout. Contents Compatibility Installation Configuration Basic Usage Advanced Search Migrations Pitfalls Compatibilit

Ivan Babenko 197 Dec 19, 2022
Elasticsearch migrations for Laravel

Elastic Migrations Elasticsearch migrations for Laravel allow you to easily modify and share indices schema across the application's environments. Con

Ivan Babenko 151 Dec 20, 2022
Fulltext indexing and searching for Laravel

Laravel fulltext index and search This package creates a MySQL fulltext index for models and enables you to search through those. Install Install with

SWIS 171 Jan 4, 2023
Search among multiple models with ElasticSearch and Laravel Scout

For PHP8 support use php8 branch For Laravel Framework < 6.0.0 use 3.x branch The package provides the perfect starting point to integrate ElasticSear

Sergey Shlyakhov 592 Dec 25, 2022
This is an open source demo of smart search feature implemented with Laravel and Selectize plugin

Laravel smart search implementation See demo at: http://demos.maxoffsky.com/shop-search/ Tutorial at: http://maxoffsky.com/code-blog/laravel-shop-tuto

Maksim Surguy 215 Sep 8, 2022
Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.

Laravel Cross Eloquent Search This Laravel package allows you to search through multiple Eloquent models. It supports sorting, pagination, scoped quer

Protone Media 844 Dec 25, 2022
Think-scout - A driver based solution to searching your models. Inspired By Laravel Scout

前言 whereof/think-scout根据thinkphp设计思想参考laravel/scout进行扩展 whereof/think-scout 为模型的全文搜索提供了一个简单的、基于驱动程序的解决方案。 目前,Scout 自带了一个 Elasticsearch 驱动;而编写自定义驱动程序很简

wangzhiqiang 6 Mar 18, 2022
Laravel 8.* Elasticsearch Eloquent

Elasticsearch Installation composer require etsetra/elasticsearch Create config file $ php artisan vendor:publish --tag="etsetra-elasticsearch-config

Etsetra 2 Jan 14, 2022
Laravel Searchable - This package makes it easy to get structured search from a variety of sources

This package makes it easy to get structured search from a variety of sources. Here's an example where we search through some model

Spatie 1.1k Dec 31, 2022
The official SingleStore Laravel driver.

SingleStore Driver for Laravel This repository contains a SingleStore Driver for Laravel. Install You can install the package via composer: composer r

SingleStore Labs 197 Jan 1, 2023
Laravel search is package you can use it to make search query easy.

Laravel Search Installation First, install the package through Composer. composer require theamasoud/laravel-search or add this in your project's comp

Abdulrahman Masoud 6 Nov 2, 2022