php-sdk icon indicating copy to clipboard operation
php-sdk copied to clipboard

blackfire.yaml not taken into account profiling through custom code

Open thomasdiluccio opened this issue 4 years ago • 2 comments

I have to redefine the custom metrics specified within the .blackfire.yaml whenever I need to use custom code for that. But, I don't need to provide any authentification. I would expect some kind of "all or nothing" behaviour, requiring me to redefine everything, or nothing.

use Blackfire\Client;
use Blackfire\Probe;
use Blackfire\Profile;
use Blackfire\Profile\Configuration;
use Blackfire\Profile\Metric;

// ...

$this->blackfireClient = new Client();
$this->config = new Configuration();

$this->config->defineMetric((new Metric(
    'my_metric',
    ['=App\\FooBundle\\Entity\\Repository\\BarRepository::findStuff']
)));

thomasdiluccio avatar Mar 12 '21 10:03 thomasdiluccio

Hi @thomasdiluccio

Can you please provide more context? Does this happen only when you define a metric with Blackfire\Profile\Metric?

lolautruche avatar Mar 18 '21 10:03 lolautruche

OK I am able to reproduce it. When a metric is being defined programmatically, the .blackfire.yaml is ignored.

require __DIR__.'/vendor/autoload.php';

$blackfireClient = new \Blackfire\Client();
$config = new \Blackfire\Profile\Configuration();
$config->setTitle('Test SDK issue');
$config->setMetadata('issue', 'https://github.com/blackfireio/php-sdk/issues/53');
$config->setMetadata('skip_timeline', 'true');
$config->defineMetric((new \Blackfire\Profile\Metric(
    'my_metric',
    ['=foo']
)));
$probe = $blackfireClient->createProbe($config);

function foo()
{
    sleep(2);
    echo "Hello world!\n";
}

foo();

echo $blackfireClient->endProbe($probe)->getUrl()."\n";

@iamluc Is this an expected behavior?

lolautruche avatar Mar 18 '21 11:03 lolautruche