Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/CLI/Commands/DemoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Appsignal\Appsignal;
use Appsignal\CLI\LogCatcher;
use Appsignal\CLI\Application;
use Appsignal\Severity;
use OpenTelemetry\API\LoggerHolder;
use OpenTelemetry\API\Trace\SpanKind;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressIndicator;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -58,6 +60,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::FAILURE;
}

$logProgress = new ProgressIndicator($output);
$logProgress->start('Sending a log ...');
Appsignal::log(
message: 'AppSignal test log.',
severity: Severity::INFO,
attributes: ['type' => 'appsignal_demo'],
);

if ($logCatcher->hasErrors()) {
$output->writeln(' <fg=red>Error:</> Failed to reach AppSignal. Check push_api_key and collector_endpoint configuration.');

return Command::FAILURE;
}
$logProgress->finish('Sent a log');


$traceProgress = new ProgressIndicator($output);
$traceProgress->start('Sending an example trace ...');
Appsignal::instrument(name: 'GET /demo', closure: function () {
Expand All @@ -79,22 +97,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);
});

// @phpstan-ignore if.alwaysFalse
if ($logCatcher->hasErrors()) {
$output->writeln(' <fg=red>Error:</> Failed to reach AppSignal. Check push_api_key and collector_endpoint configuration.');
return Command::FAILURE;
}
$traceProgress->finish('Sent a trace');

$errorProgress = new ProgressIndicator($output);
$errorProgress->start('Sending an exception');
Appsignal::instrument(name: 'GET /demo-with-error', closure: function () {
$errorProgress->start('Sending an exception ...');
Appsignal::instrument(name: 'GET /demo-with-error', attributes: ['http.response.status_code' => 500], spanKind: SpanKind::KIND_SERVER, closure: function () {
Appsignal::addTags(['demo-trace' => true]);
Appsignal::setAction('DemoController::showWithError');

Appsignal::instrument(name: 'span_with_error', closure: function () {
sleep(1);
Appsignal::setError(new DemoException('TestException: AppSignal demo exception'));
});
Appsignal::setError(new DemoException('TestException: AppSignal demo exception'));
});

// @phpstan-ignore if.alwaysFalse
Expand Down
2 changes: 1 addition & 1 deletion src/CLI/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
mkdir($configTargetDir, 0o755, true);
}
copy($configTemplate, $configTarget);
$output->writeln(" ✔ Created AppSignal config file <fg=gray>.env</>");
$output->writeln(" ✔ Created AppSignal config file <fg=gray>config/appsignal.php</>");
// reload config
$config = $appsignal->loadConfig(forceReload: true);
} else {
Expand Down
Loading