arkaitzgarro / elastic-apm-laravel Goto Github PK
View Code? Open in Web Editor NEWLaravel APM agent for Elastic v2 intake API
License: MIT License
Laravel APM agent for Elastic v2 intake API
License: MIT License
hello i switched the logs level to info and i get the following recors in the logs:
[2021-12-13 19:44:01] production.NOTICE: [Elastic APM Agent] The "active" configuration option is deprecated, please use "enabled" instead.
[2021-12-13 19:44:01] production.NOTICE: [Elastic APM Agent] Both "appName" and "serviceName" were set, using the preferred option "serviceName".
[2021-12-13 19:44:01] production.NOTICE: [Elastic APM Agent] The "appVersion" configuration option is deprecated, please use "serviceVersion" instead.
is there any option to resolve this issue ?
regards
i
When installing, composer warns that:
Package jasny/dbquery-mysql is abandoned, you should avoid using it. Use jasny/persist-sql-query instead.
Original title: Using Log::getLogger() breaks compatibility with older versions
I'm still looking into when the change was made, but it used to be Log::getMonolog()
. At least in 5.x and possibly 6.x. I'll work on this.
Inconsistent send
method override in the Agent
class (child class, parent class):
PHP Fatal error: Declaration of AG\ElasticApmLaravel\Agent::send(): bool must be compatible with Nipwaayoni\Agent::send(): void in /home/vagrant/elastic-apm-laravel/src/Agent.php on line 30
Hi,
Maybe i'm confused by the way the APM Agent + this library is suppose to work but I have succesfully installed the APM agent as well as loaded this package in my repo. Currently running on our remote staging environment.
What i want to avoid really is to work with system-wide ENV / php.ini variables since our Elastic Search hosts vary. I would like to specify this on application level. So i defined the following in my .env:
ELASTIC_APM_SERVER_URL="https://....cloud.es.io:443"
ELASTIC_APM_SECRET_TOKEN="[token]"
ELASTIC_APM_SERVICE_NAME="My App"
It seems this is not being picked up by the agent. I get errors when i run any artisan commands:
2022-08-02 11:50:58.126310+02:00 [PID: 2905654] [TID: 2905655] [ERROR] [Backend-Comm] [backend_comm.c:251] [syncSendEventsToApmServer] Sending events to APM Server failed. URL: `http://localhost:8200/intake/v2/events'. Error message: `Couldn't connect to server'. Current process command line: `php artisan config:cache'
Because it tries to load the default ES values of localhost:8200
.
When i go the php.ini config route as suggested by the ES docs it seems to work and i get data ingested. For clarity, like this:
php.ini
elastic_apm.server_url="https:/....aws.cloud.es.io:443"
elastic_apm.secret_token="[token]"
However this seems odd to me to be only able to do this on a system wide level...
Any idea?
Tom
I work with @dstepe and as we were adding this to some existing code that had guzzle6-adapter v 1.1 but I was getting an error, so we discovered that the guzzle6-adapter needs to be > 2.0.
We have observed that artisan commands in the composer post-install scripts fail in our CI/CD pipeline with the error:
Nipwaayoni\Exception\MissingServiceNameException
No service name registered in agent config.
at projects/elastic-apm-php-agent/src/Config.php:105
101| {
102| $this->resolveLegacyOptions();
103|
104| if (empty($this->config['serviceName'])) {
> 105| throw new MissingServiceNameException();
106| }
107|
108| // TODO validate serviceName matches ^[a-zA-Z0-9 _-]+$
109| // TODO support list of server URLs
1 projects/elastic-apm-php-agent/src/Config.php:70
Nipwaayoni\Config::validateConfig()
2 projects/elastic-apm-laravel/src/ServiceProvider.php:109
Nipwaayoni\Config::__construct(["Laravel", "7.28.4", Object(Monolog\Logger), "error"])
This can be reproduced by removing the local .env
file and running:
php artisan package:discover
I believe we have identified the source of the problem and I'll be making a PR with a fix later today.
This issue is more of an enhancement-request.
Inside AG\ElasticApmLaravel\ServiceProvider::registerAgent()
,currently all Transactions are getting sent to an APM server. I understand that this dispatch to the APM server can be completely disabled or enabled on the basis of an environment variable.
Our requirement is to send only Transactions that result in Exceptions. Inside our Exceptions handler, we successfully capture the thrown Exceptions using the captureThrowable()
function. Is it possible to probably add a global identifier during the application execution which, if set properly, can determine whether or not to send the Transaction to the APM Server? We intend to modify this global identifier on-the-fly during the application's execution.
As a work around, we have placed this package in a separate folder and we have modified the registerAgent
function as follows:
$this->app->terminating(function (Request $request, Response $response) {
/** @var Agent $agent */
$agent = $this->app->make(Agent::class);
global $doesErrorExist;
if($doesErrorExist === true){
$agent->send();
}
});
Hi
I'm trying to use that apm agent for our php laravel project
php: "^7.3"
laravel/framework: 5.6.*
apm server: 7.6.0
I'm getting below errors in the application log:
test.ERROR: A transaction with the name POST /api/auth/login is already registered. {"exception":"[object] (PhilKra\\Exception\\Transaction\\DuplicateTransactionNameException(code: 0): A transaction with the name POST /api/auth/login is already registered. at /var/app/vendor/philkra/elastic-apm-php-agent/src/Stores/TransactionsStore.php:30)
[stacktrace]
#0 /var/app/vendor/philkra/elastic-apm-php-agent/src/Agent.php(161): PhilKra\\Stores\\TransactionsStore->register(Object(PhilKra\\Events\\Transaction))
#1 /var/app/vendor/arkaitzgarro/elastic-apm-laravel/src/Middleware/RecordTransaction.php(103): PhilKra\\Agent->startTransaction('POST /api/auth/...', Array, 1585063877.3042)
#2 /var/app/vendor/arkaitzgarro/elastic-apm-laravel/src/Middleware/RecordTransaction.php(45): AG\\ElasticApmLaravel\\Middleware\\RecordTransaction->startTransaction('POST /api/auth/...')
#3 /var/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): AG\\ElasticApmLaravel\\Middleware\\RecordTransaction->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#4 /var/app/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#5 /var/app/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#6 /var/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#7 /var/app/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#8 /var/app/vendor/swooletw/laravel-swoole/src/Server/Sandbox.php(257): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#9 /var/app/vendor/swooletw/laravel-swoole/src/Server/Sandbox.php(217): SwooleTW\\Http\\Server\\Sandbox->handleRequest(Object(Illuminate\\Http\\Request))
#10 /var/app/vendor/swooletw/laravel-swoole/src/Server/Sandbox.php(179): SwooleTW\\Http\\Server\\Sandbox->prepareObResponse(Object(Illuminate\\Http\\Request))
#11 /var/app/vendor/swooletw/laravel-swoole/src/Server/Manager.php(225): SwooleTW\\Http\\Server\\Sandbox->run(Object(Illuminate\\Http\\Request))
#12 {main}
Can you please advise?
Using the previous versions of nipwaayoni/elastic-apm-php-agent
, we noticed that Transactions were not getting correlated with Errors in Elastic Cloud APM. We alerted the package owners here: nipwaayoni/elastic-apm-php-agent#78
In the latest version of nipwaayoni/elastic-apm-php-agent
, this issue has been fixed. The problem is that your package relies on "nipwaayoni/elastic-apm-php-agent": "^7.5"
, which is not the latest version i.e. version 8.0.0
.
Is it possible for you to please include the latest version of nipwaayoni/elastic-apm-php-agent
in your composer.json
so that Transactions get associated with Errors accurately?
My environment
PHP 7.2 (docker php:7.2-fpm)
laravel/framework: 5.7.*
Passing along an error from our app. If it occurs frequently or causes a problem I can look closer, but I don't plan to prioritize it myself right now.
Symfony\Component\Debug\Exception\FatalThrowableError: Argument 2 passed to AG\ElasticApmLaravel\Collectors\ScheduledTaskCollector::stopTransaction() must be of the type int, null given, called in /var/www/vendor/arkaitzgarro/elastic-apm-laravel/src/Collectors/ScheduledTaskCollector.php on line 53
I don't know why in our case it is null, but I see in the source that null
is documented as a potential value.
// Illuminate\Console\Scheduling\Event
/**
* The exit status code of the command.
*
* @var int|null
*/
public $exitCode;
The ServiceProvider
resolves the Agent
class and calls Agent::registerInitCollectors()
during the Laravel register phase.
https://github.com/arkaitzgarro/elastic-apm-laravel/blob/master/src/ServiceProvider.php#L93
Because this happens during the register phase of the Laravel boot process, other service providers may not have completed registering services that may be required by the Agent
creation process.
The FrameworkCollector
needs to load before the boot phase, however.
I suggest the framework collector object be created outside of the Agent
class so it can register the necessary listeners, but that it then be given to the agent object after the agent is created. This should remove the need to create the Agent
in the service container during the register phase.
I should have PR for this shortly.
Add a new collector that listens to CommandStarting
and CommandFinished
events, so we can measure Laravel's artisan commands.
https://laravel.com/api/5.8/Illuminate/Console/Events/CommandStarting.html
https://laravel.com/api/5.8/Illuminate/Console/Events/CommandFinished.html
ArtisanStarting
event could be interesting to be included as well https://laravel.com/api/5.8/Illuminate/Console/Events/ArtisanStarting.html
If you notice the latest intake/v2/events Error schema on https://www.elastic.co/guide/en/apm/guide/current/api-error.html, along with the transaction_id
, a transaction
object should also be present in the incoming JSON.
Now in jsonSerialize
function of Nipwaayoni\Events\Error
, the transaction
key is not present. Therefore this key is never included during API calls made to Elastic Cloud APM Server.
I called the API with and without the transaction
key - the resulting Error (captured using captureThrowable
function) got associated with a Transaction only if this key is included in the request body. Without the inclusion of this key, the Transaction correctly displays the presence of an Error, but never really redirects to the Error upon trying to inspect the associated Error separately (when you click on "View related error" on the Transaction).
Is it possible for you to upgrade Nipwaayoni\Events\Error
to appropriately include this new Schema?
My core issue is that I want to hook into the agent to track jobs. My preferred solution is #18, but I'm also ok with #11.
But if not that, then there are a couple things I think should be done to allow better extensibility:
isHttpRequest
to not start the route_matching but I do think it's a bit awkward to have the boot stuff in http--may be just me$collectors
isn't public, I can't just add my own. Either a getCollectors
method or a public property would be fine.Even if one of my job PRs is merged, step 2 may still be useful.
Hello, I was wondering which would be the most appropiate way to extend the RecordTransaction middleware. The main concern I'm facing is that I want to record additional information from each request, for example body params, aswell as more information about the user and session.
Would happily work on a PR if we can agree on a solution!
Thank you!
Looks like all new functionality and necessary changes to accommodate the new agent are complete, and we can release the final 3.0 version. This is what I will include in the release notes, please let me know if I am missing something:
Features
Fixes
APM_MAXTRACEITEMS
value (#89)BREAKING CHANGES
philkra/elastic-apm-php-agent
with nipwaayoni/elastic-apm-php-agent
(#72). The previous agent is not under maintenance anymore, and the author agreed on transfering the ownership to an organization. This change should be transparent for most the users, unless you were extending the Agent
class. In this case, refer to the agent documentation and the new way to create an instance in this package.@countless-integers @dstepe is there anything else you would like to add?
Hey!
Now that the Oficial PHP APM Agent is released, there's any plans to implement it over the current dependency?
Great work on this btw.
As of now I haven't experienced any issues with this, but I noticed the conversation #95 (comment).
I'm curious, with the release of composer version 2, do you still have the issues with circleci?
We're interested in having APM only send events 10% of the time, and handling this via feature flags. https://github.com/checkr/flagr if you're curious.
I'm curious what you think about how to approach this. We could make our own custom service provider that extends yours, in order to make a flagr request prior to reading the provided configuration option. Do you see a clean way we could provide the ability to hook into the library instead of making a custom service provider?
While running the automatic build in the repository of my project after running composer install
, I encounter the following error:
[2022-06-20 15:19:24] production.ERROR: Trying to access array offset on value of type bool {"exception":"[object] (ErrorException(code: 0): Trying to access array offset on value of type bool at /frontend/vendor/arkaitzgarro/elastic-apm-laravel/src/Collectors/CommandCollector.php:103)
[stacktrace]
#0 /frontend/vendor/arkaitzgarro/elastic-apm-laravel/src/Collectors/CommandCollector.php(103): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Trying to acces...', '/frontend/vendo...', 103, Array)
#1 /frontend/vendor/arkaitzgarro/elastic-apm-laravel/src/Collectors/CommandCollector.php(32): AG\\ElasticApmLaravel\\Collectors\\CommandCollector->addMetadata(Object(Nipwaayoni\\Events\\Transaction))
#2 /frontend/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(381): AG\\ElasticApmLaravel\\Collectors\\CommandCollector->AG\\ElasticApmLaravel\\Collectors\\{closure}(Object(Illuminate\\Console\\Events\\CommandStarting))
#3 /frontend/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(226): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('Illuminate\\\\Cons...', Array)
#4 /frontend/vendor/laravel/framework/src/Illuminate/Console/Application.php(89): Illuminate\\Events\\Dispatcher->dispatch('Illuminate\\\\Cons...')
#5 /frontend/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#6 /frontend/artisan(35): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#7 {main}
"}
In CommandCollector.php line 103:
Trying to access array offset on value of type bool
Everything was working fine until last week (last successful release was on thursday) and today out of nowhere it crashes.
As been discussed in PR #101
Some of the classes imports class ( Illuminate\Foundation\Application
) from non existing package in composer.json
, we should require illuminate\contracts
and resolve the class using DI.
Hey,
after adding the package as describe I've tested it locally and it was working like a charm.
Now I did deploy it with Laravel Vapor onto AWS and we are getting the following errors:
@timestamp | 1621524169921
channel | development
context.exception.class | ErrorException
context.exception.code | 0
context.exception.file | /var/task/vendor/arkaitzgarro/elastic-apm-laravel/src/Collectors/FrameworkCollector.php:22
context.exception.message | Use of undefined constant LARAVEL_START - assumed 'LARAVEL_START' (this will throw an Error in a
future version of PHP)
datetime | 2021-05-20T17:22:49.808326+02:00
level | 400
level_name | ERROR
message | Use of undefined constant LARAVEL_START - assumed 'LARAVEL_START' (this will throw an Error in a future version of PHP)
and the following (but I would assume, they are related).
@timestamp | 1621524169979
channel | development
context.exception.class | Symfony\Component\ErrorHandler\Error\FatalError
context.exception.code | 0
context.exception.file | /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php:835
context.exception.message | Uncaught ReflectionException: Class translator does not exist in
/var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php:833Stack trace:#0 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(833): ReflectionClass->__construct('translator')#1 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\Container\Container->build('translator')#2 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve('translator', Array, true)#3 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\Foundation\Application->resolve('translator', Array)#4 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\Container\Container->make('translator', Array)#5 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(119): Illuminate\Foundation\Application->make('translator', Array)#6 /var/task/vendor/
datetime | 2021-05-20T17:22:49.979624+02:00
level | 400
level_name | ERROR
message | Uncaught ReflectionException: Class translator does not exist in /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php:833Stack trace:#0 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(833): ReflectionClass->__construct('translator')#1 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\Container\Container->build('translator')#2 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve('translator', Array, true)#3 /var/task/vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\Foundation\Application->resolve('translator', Array)#4 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\Container\Container->make('translator', Array)#5 /var/task/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(119): Illuminate\Foundation\Application->make('translator', Array)#6 /var/task/vendor/
In case anybody has experienced the same issue, I would be happy to hear your opinion on how we can solve that. My current assumption is, that due to the fact that the entry point is changing when using Laravel Vapor, the constant LARAVEL_START
is not set.
Regards,
Frederik
I'm not clear on the purpose of job middleware or when I may want to use it.
The README states it will "record an additional span around your job execution", but does not explain why that would be useful.
The JobCollector appears to do what I want without needing to add the middleware to my job classes.
The package config only looks at APM_ENVIRONMENT
. PR incoming shortly.
Hello, i am facing this issue when installing the plugin.
the problem seems to be here
at ***********\vendor\arkaitzgarro\elastic-apm-laravel\src\ServiceProvider.php:231
227▕ if ($this->app->bound(VersionResolver::class)) {
228▕ $config['appVersion'] = $this->app->make(VersionResolver::class)->getVersion();
229▕ }
230▕
➜ 231▕ return $config;
232▕ }
can you help me with this ?
Likely in TimelineDataCollector
. I think an exception might be extreme but a log could helpful. Potentially:
public function startMeasure(
string $name,
string $type = 'request',
string $action = null,
string $label = null,
float $start_time = null
): void {
if ($this->hasStartedMeasure($name) {
// Throw Exception?
// Log Warning?
return;
}
$start = $start_time ?? microtime(true);
$this->started_measures->put($name, [
'label' => $label ?: $name,
'start' => $start - $this->request_start_time,
'type' => $type,
'action' => $action,
]);
}
middleware does not get called when the app is running from console (unite tests/commands), so when the APM_ACTIVE=false
no transaction will be created which will make ApmAgent::getCurrentTransaction()
always throw an exception.
There is an issue when running with Octane
Here is the error
Undefined constant "AG\ElasticApmLaravel\Collectors\LARAVEL_START"
Hi,
I'm running APM + this package on one of our job servers. The server runs an install of our application with Laravel Horizon.
The only thing i'm seeing tracked in APM are the Artisan commands. I'm not seeing any Job execution.
Also, i'm not seeing any exceptions either.
Any idea what i'm missing?
Best,
Tom
Hi!, is there any method to check the coomunication between the agent and the apm server?, I'm trying to debug the installation. I did follow all the steps but's not working on Lumen 8.1, it does work on Laravel.
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
In SpanCollector.php line 28:
syntax error, unexpected ')'
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
The command '/bin/sh -c composer dump-autoload --optimize && composer run-script post-autoload-dump' returned a non-zero code: 1
My environment
PHP 7.2 (docker FROM php:7.2-fpm)
Composer version 1.10.8 2020-06-24 21:23:30
laravel/framework: 5.7.*
When I first read the Prerequisites I thought that I had to install nipwaayoni/elastic-apm-php-agent
but after re-reading I then understood that I just needed to install an HTTP client adapter.
I am also using a Gitlab PHP client and they have a similar requirement, where they don't provide a client either. How they describe their installation was more clear for me to understand.
Doesn't seem to be compatiable with Lumen
2020/04/03 17:06:59 [error] 11#11: *3 FastCGI sent in stderr: "PHP message: [2020-04-03 17:06:59] local.ERROR: ReflectionException: Class Illuminate\Foundation\Application does not exist in /vendor/illuminate/container/Container.php:871
Stack trace:
#0 /vendor/illuminate/container/Container.php(871): ReflectionParameter->getClass()
#1 /vendor/illuminate/container/Container.php(834): Illuminate\Container\Container->resolveDependencies(Array)
#2 /vendor/illuminate/container/Container.php(681): Illuminate\Container\Container->build('AG\\ElasticApmLa...')
#3 /vendor/illuminate/container/Container.php(629): Illuminate\Container\Container->resolve('AG\\ElasticApmLa...', Array)
#4 /vendor/laravel/lumen-framework/src/Application.php(267): Illuminate\Container\Container->make('AG\\ElasticApmLa...', Array)
#5 /vendor/laravel/lumen-framework/src/helpers.php(42): Laravel\Lumen\Application->make('AG\\ElasticApmLa...', Array)
#6 /vendor/arkaitzgarro/elastic-apm-laravel/src/Agent.php(46): app('AG\\ElasticApmLa...')
#7 /vendor/arkaitzgarro/elastic-apm-laravel/src/ServiceProvider.php(96): AG\ElasticApmLaravel\Agent->registerInitCollectors()
#8 /vendor/arkaitzgarro/elastic-apm-laravel/src/ServiceProvider.php(30): AG\ElasticApmLaravel\ServiceProvider->registerInitCollectors()
#9 /vendor/laravel/lumen-framework/src/Application.php(200): AG\ElasticApmLaravel\ServiceProvider->register()
#10 /bootstrap/app.php(115): Laravel\Lumen\Application->register(Object(AG\ElasticApmLaravel\ServiceProvider))
#11 /public/index.php(13): require('/bo...')
#12 {main} {"exception":"[object] (ReflectionException(code: 0): Class Illuminate\\Foundation\\Application does not exist at /vendor/illuminate/container/Container.php:871)
Any plan to upgrade to Laravel 9?
this is how this packege is on my composer.json "arkaitzgarro/elastic-apm-laravel": "^3.0",
php version PHP 7.4.13 (cli)
Composer version 2.0.8 2020-12-03 17:20:38
When running composer required or composer update this error is showing
@php artisan package:discover
TypeError
Return value of AG\ElasticApmLaravel\ServiceProvider::getAppConfig() must be of the type array, null returned
at ....\vendor\arkaitzgarro\elastic-apm-laravel\src\ServiceProvider.php:227
223| if ($this->app->bound(VersionResolver::class)) {
224| $config['appVersion'] = $this->app->make(VersionResolver::class)->getVersion();
225| }
226|
227| return $config;
228| }
229|
230| private function isAgentDisabled(): bool
231| {
1 ....\vendor\arkaitzgarro\elastic-apm-laravel\src\ServiceProvider.php:214
AG\ElasticApmLaravel\ServiceProvider::getAppConfig()
2 ....\vendor\arkaitzgarro\elastic-apm-laravel\src\ServiceProvider.php:105
AG\ElasticApmLaravel\ServiceProvider::getAgentConfig()
TypeError
Return value of AG\ElasticApmLaravel\ServiceProvider::getAppConfig() must be of the type array, null returned
at ....\vendor\arkaitzgarro\elastic-apm-laravel\src\ServiceProvider.php:227
223| if ($this->app->bound(VersionResolver::class)) {
224| $config['appVersion'] = $this->app->make(VersionResolver::class)->getVersion();
225| }
227| return $config;
229|
231| {
1 ....\vendor\arkaitzgarro\elastic-apm-laravel\src\ServiceProvider.php:214
AG\ElasticApmLaravel\ServiceProvider::getAppConfig()
2 ....\vendor\arkaitzgarro\elastic-apm-laravel\src\ServiceProvider.php:105
AG\ElasticApmLaravel\ServiceProvider::getAgentConfig()
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
Will you make an actual 2.0 release from the 2.x branch? Is there anything outstanding for that I could help with?
Enviroment: Laravel v8
This is my current config/elastic-apm-laravel.php
<?php
return [
'active' => true,
'log-level' => "DEBUG", //tried info,error
'cli' => [
'active' => env('APM_ACTIVE_CLI', true),
],
'app' => [
'serviceName' => preg_replace('/[^a-zA-Z0-9 _-]/', '-', "laravel"),
'serviceVersion' => 7.14
],
'env' => [
'env' => ['DOCUMENT_ROOT', 'REMOTE_ADDR'],
'environment' => "development"
],
'server' => [
'serverUrl' => "http://localhost:8200",
'hostname' => env('ELASTIC_APM_HOSTNAME', gethostname()),
],
'agent' => [
'transactionSampleRate' => env('ELASTIC_APM_TRANSACTION_SAMPLE_RATE', 1),
],
'transactions' => [
'useRouteUri' => env('APM_USEROUTEURI', true),
'ignorePatterns' => env('APM_IGNORE_PATTERNS', null),
],
'spans' => [
'maxTraceItems' => env('APM_MAXTRACEITEMS', 1000),
'backtraceDepth' => env('APM_BACKTRACEDEPTH', env('ELASTIC_APM_STACK_TRACE_LIMIT', 25)),
'querylog' => [
'enabled' => true,
'threshold' => env('APM_THRESHOLD', 200),
],
],
];
// I know I must to use env variables, but want to let you know values
My docker-compose.yml
version: '3'
networks:
laravel:
services:
kibana:
image: kibana:7.14.0
container_name: kibana
volumes:
- ./kibana/kibana.yml:/usr/share/kibana/config/kibana.yml
ports:
- "5601:5601"
depends_on:
- elastic
networks:
- laravel
elastic:
image: elasticsearch:7.14.0
hostname: elasticsearch
container_name: elastic
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./elastic/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./elastic/data:/usr/share/elasticsearch/data
ports:
- "9200:9200"
- "9300:9300"
networks:
- laravel
apm:
image: elastic/apm-server:7.14.0
cap_add: [ "CHOWN", "DAC_OVERRIDE", "SETGID", "SETUID" ]
cap_drop: [ "ALL" ]
container_name: apm
hostname: apm_agent
ports:
- "8200:8200"
depends_on:
- elastic
- kibana
networks:
- laravel
command: >
apm-server -e
-E apm-server.rum.enabled=true
-E setup.kibana.host=kibana:5601
-E setup.template.settings.index.number_of_replicas=0
-E apm-server.kibana.enabled=true
-E apm-server.kibana.host=kibana:5601
-E output.elasticsearch.hosts=["elasticsearch:9200"]
healthcheck:
interval: 10s
retries: 12
test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/
elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
discovery.type: "single-node"
node.name: "elastic_node"
xpack.security.enabled: false
bootstrap.memory_lock: true
I installed php-http/guzzle7-adapter
and arkaitzgarro/elastic-apm-laravel
tried some request (go to home page...) but no services listed (Kibana->Observability->APM/Services), and no errors on logs. Used elastic:create
command from jeroen-g/explorer
library, and one service is listed but only my command. Tried to throw a error from my application, but not listed on error. I added AG\ElasticApmLaravel\Middleware\RecordTransaction
to Http/Kernel.php
middleware. Did I miss something?
I want to trace request, DB queries, errors, cpu usage...
Greetings! I see that you use the philkra/elastic-apm-php-agent
package to provide the underlying APM service. That package has been seen much activity, and by mutual agreement with the author, I have created a replacement package to continue development (https://github.com/nipwaayoni/elastic-apm-php-agent). Philkra also published a Laravel APM package based on his Agent which I picked up as well (https://github.com/nipwaayoni/elastic-apm-laravel).
Would you consider switching to the new Agent package? There are some breaking changes to deal with, but I'm trying to keep improving it while watching the official Elastic APM Agent for PHP (https://github.com/elastic/apm-agent-php). I'd be happy to get feedback to benefit your Laravel package as well as the Agent.
I'd also like to consider how we might consolidate the Laravel APM packages. I like what I see in your implementation and I believe the community would benefit from collaboration.
I open to discussion.
While writing unit tests for the Agent
class, I found that the max trace items setting is used to take that number of items from each collector:
https://github.com/arkaitzgarro/elastic-apm-laravel/blob/master/src/Agent.php#L70
The README defines max trace items as "Max number of child items displayed when viewing trace details" which is not consistent with the implementation.
Should the implementation be fixed or should the documentation be updated to reflect this is per collector? I vote for fixing the implementation, but makes the behavior rather arbitrary since you make take all of one type and none of another based purely on which collector is processed first.
A better solution might be to create a global EventCollectionTracker
object which all collectors refer to and increment each time they collect an event. Each collector will then ask that object if it should collect an event and discard the event if not. Only that tracker object would need to be concerned with the max trace items, and the collectors would not consume memory collecting events which won't actually be pushed to APM.
Given that the default is 1000 items, it may be unlikely that anyone ever hits this problem, so maybe it's low priority.
Hello,
When logging laravel jobs, I have this kind of error :
production.ERROR: Client error: `POST /intake/v2/events` resulted in a `400 Bad Request` response:
"errors": [
{
"message": "did not recognize object type",
I'm using laravel 7.4
php 7.4
Kibana 7.6.2
Thank you !
I think as of Laravel 5.5 or so, there is no need to add the code to the ServiceProvider, since Laravel now utilizes the command @php artisan package:discover
as part of the "post-autoload-dump"
of the composer json file.
Hello there,
Is there a way to queue the transaction requests to elasticsearch? I've been digging into the source and haven't found a way to do so by myself. If I'm not mistaken, the request is sync and blocking, meaning that if there is a problem with that request and there is an error it would be an exception that would be catched, but what about the situations where there is no error because the server does not respond?
I think it would be quite interesting to configure if the transactions are sent async instead, for example in case that the connection with elasticsearch is unstable because the elastic is down or it timeouts. In this scenario the whole application would suffer that degradation on both http requests and cli jobs. Actually the jobs will get stuck and stop processing if job timeout option is not set. I can provide an example to reproduce this scenario.
Is there another way to handle those cases where the connection with elastic is down? Besides setting to false the APM_ACTIVE flag.
Maybe I'm missing something in my configuration that makes it very sensible to elasticsearch server being always accessible but if you find it interesting I could work on a PR to include queueing those requests so they can work on background and fail independently of the application flow.
Thank you!
When the Laravel application configuration is cached (artisan config:cache
) the .env
file is not parsed and no environment variables are set. As a consequence, the underlying Agent
does not have the expected ELASTIC_APM_
configuration variables and fails to start.
The Agent
is following the general practice of other APM agent implementations of configuration through environment variables. The configuration can also be provided as an array, as was previously done. While we wanted to avoid a one-to-one mapping of values through this package to the Agent
, that may be the only solution to this caching issue.
Hi @arkaitzgarro, thanks for the wonderful package!
It will be really great if we could use it safely with Laravel Octane.
I have attached a issue that seems to be with Octane:
Long Duration Time due to the Singleton Behavior
Also since most of the microservices will be going over Octane, so authenticity of the data is also required. Once again its great package for PHP devs looking to get APM. I am not so much experienced as you, else i would have surely raised a PR :)
Thanks
Hi
How enable collect data from Api routes ?
right now it's collect data from web.php routes and work fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.