From acc
Generates Correlation ID propagation for PHP 8.4: PSR-15 middleware, Monolog processor, Symfony Messenger stamps, value objects, and unit tests. For tracing requests across distributed services and observability.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-correlation-contextThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Creates Correlation ID propagation infrastructure for distributed PHP applications.
Creates Correlation ID propagation infrastructure for distributed PHP applications.
| Component | Layer | Path | Purpose |
|---|---|---|---|
CorrelationId | Domain/Shared | src/Domain/Shared/Correlation/CorrelationId.php | UUID-based Value Object |
CorrelationContext | Domain/Shared | src/Domain/Shared/Correlation/CorrelationContext.php | Immutable context holder |
CorrelationContextMiddleware | Presentation | src/Presentation/Middleware/CorrelationContextMiddleware.php | PSR-15 middleware |
CorrelationLogProcessor | Infrastructure | src/Infrastructure/Logging/CorrelationLogProcessor.php | Monolog processor |
CorrelationMessageStamp | Infrastructure | src/Infrastructure/Messaging/CorrelationMessageStamp.php | Message bus stamp |
| Unit tests | Tests | tests/Unit/... | Tests for all components |
final readonly class in Domain layergenerate()Stringable and JsonSerializableequals() methodcorrelationId, causationId, optional userIdcreate() generates new correlation IDfromRequest() extracts from PSR-7 request headerswithCausationId(), withUserId()X-Correlation-ID header from incoming request (or generates new UUID)X-Causation-ID if presentCorrelationContext as request attributeX-Correlation-ID to response headersProcessorInterfacecorrelation_id, causation_id to every log record extra fieldCorrelationContextHolder (request-scoped)StampInterface (or custom stamp interface)correlationId and causationId through message busPath: src/Domain/Shared/Correlation/
CorrelationId.php -- UUID-based Value ObjectCorrelationContext.php -- Immutable context holderUse templates from references/templates.md (Domain section).
Path: src/Presentation/Middleware/
CorrelationContextMiddleware.php -- PSR-15 middlewareUse templates from references/templates.md (Presentation section).
Path: src/Infrastructure/Logging/ and src/Infrastructure/Messaging/
CorrelationLogProcessor.php -- Monolog processorCorrelationMessageStamp.php -- Message bus stampUse templates from references/templates.md (Infrastructure section).
Path: tests/Unit/Domain/Shared/Correlation/ and tests/Unit/Presentation/Middleware/ and tests/Unit/Infrastructure/
CorrelationIdTest.phpCorrelationContextTest.phpCorrelationContextMiddlewareTest.phpCorrelationLogProcessorTest.phpUse templates from references/templates.md (Tests section).
| Component | Default Path |
|---|---|
| CorrelationId | src/Domain/Shared/Correlation/CorrelationId.php |
| CorrelationContext | src/Domain/Shared/Correlation/CorrelationContext.php |
| Middleware | src/Presentation/Middleware/CorrelationContextMiddleware.php |
| Log Processor | src/Infrastructure/Logging/CorrelationLogProcessor.php |
| Message Stamp | src/Infrastructure/Messaging/CorrelationMessageStamp.php |
| Tests | tests/Unit/{layer}/...Test.php |
Adapt paths to match existing project structure detected via:
Glob: src/Domain/**/*.php
Glob: src/Presentation/**/*.php
Glob: src/Infrastructure/**/*.php
final readonly class CorrelationId implements \Stringable, \JsonSerializable
{
public function __construct(public string $value) {}
public static function generate(): self { /* UUID v4 */ }
public function equals(self $other): bool { /* comparison */ }
}
final readonly class CorrelationContext
{
public function __construct(
public CorrelationId $correlationId,
public ?string $causationId = null,
public ?string $userId = null,
) {}
public static function create(): self { /* new with generated ID */ }
public static function fromRequest(ServerRequestInterface $request): self { /* extract headers */ }
}
final readonly class CorrelationContextMiddleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$context = CorrelationContext::fromRequest($request);
$request = $request->withAttribute(CorrelationContext::class, $context);
$response = $handler->handle($request);
return $response->withHeader('X-Correlation-ID', $context->correlationId->value);
}
}
See references/templates.md for complete implementations and references/examples.md for integration examples.
$app->add(new CorrelationContextMiddleware());
return [
CorrelationContextMiddleware::class => autowire(),
CorrelationLogProcessor::class => autowire(),
];
$context = $request->getAttribute(CorrelationContext::class);
$this->logger->info('Processing order', ['orderId' => $orderId]);
// Log automatically includes correlation_id via processor
See references/examples.md for Symfony, Laravel, and message bus integration.
npx claudepluginhub dykyi-roman/awesome-claude-code --plugin accGenerates PSR-3 structured logger for PHP 8.4 with Monolog processors for correlation IDs and request context, PSR-15 middleware, and unit tests. For distributed tracing and observability.
Implements structured API request logging with correlation IDs, performance metrics, PII redaction, and security audit trails for debugging, analysis, and compliance.
Instruments Python apps with structured logging via structlog, Prometheus metrics, distributed tracing, and correlation IDs for production observability and debugging.