mirror of
https://github.com/temporalio/skill-temporal-developer.git
synced 2026-09-14 13:52:58 +08:00
2401665931
- Renamed sections to match Python reference style (6 section name fixes) - observability.md: replaced full Search Attributes content with ref to data-handling.md - gotchas.md: removed extra subsection already covered in php.md - versioning.md: expanded Worker Versioning to match Python verbosity Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2.5 KiB
2.5 KiB
PHP SDK Observability
Overview
The PHP SDK provides observability through PSR-3 logging (with replay-aware Workflow logger), and visibility via Search Attributes.
Logging
Workflow Logging
Use Workflow::getLogger() for replay-safe logging inside Workflows:
use Temporal\Workflow;
class OrderWorkflow implements OrderWorkflowInterface
{
public function run(array $order): \Generator
{
Workflow::getLogger()->info('Workflow started', ['orderId' => $order['id']]);
$result = yield $this->activity->processPayment($order);
Workflow::getLogger()->info('Payment processed', ['result' => $result]);
return $result;
}
}
The Workflow logger automatically suppresses duplicate log messages during replay by default.
Activity Logging
Activities are not replayed, so use any standard PSR-3 logger (injected via constructor or DI):
use Psr\Log\LoggerInterface;
class OrderActivity implements OrderActivityInterface
{
public function __construct(private LoggerInterface $logger) {}
public function processPayment(array $order): string
{
$this->logger->info('Processing payment', ['orderId' => $order['id']]);
// Perform work...
$this->logger->info('Payment complete');
return 'completed';
}
}
Enabling Logging During Replay
By default, Workflow::getLogger() suppresses logs during replay. To enable logging during replay (useful for debugging):
use Temporal\Worker\WorkerOptions;
$worker = $factory->newWorker(
taskQueue: 'orders',
options: WorkerOptions::new()->withEnableLoggingInReplay(true)
);
Customizing the Logger
Pass a custom PSR-3 logger when creating the Worker:
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Temporal\WorkerFactory;
$logger = new Logger('temporal');
$logger->pushHandler(new StreamHandler('php://stdout'));
$factory = WorkerFactory::create();
$worker = $factory->newWorker(
taskQueue: 'my-task-queue',
logger: $logger
);
Any PSR-3 compatible logger (Monolog, etc.) can be used.
Search Attributes (Visibility)
See the Search Attributes section of references/php/data-handling.md
Best Practices
- Use
Workflow::getLogger()inside Workflow code for replay-safe logging - Do not use
echoorprint()in Workflows — output appears on every replay - Use standard PSR-3 loggers in Activities (no replay concern)
- Use Search Attributes for business-level visibility and querying across Workflow executions