Skip to content

feat(correlation): request_id from the host correlation provider, opt-in correlation_id / upstream_id (1.27.0) - #95

Merged
HecFranco merged 3 commits into
mainfrom
feat/1.27.0-correlation
Nov 28, 2026
Merged

HecFranco merged 3 commits into
mainfrom
feat/1.27.0-correlation

Conversation

@HecFranco

Copy link
Copy Markdown
Contributor

Summary

Beacon spec 235 T002 / FR-002 / FR-005: HttpLog adopts nowo-tech/correlation-contract ^0.1. Target 1.27.0 (minor, no BC break). Spec: specs/005-correlation-ids/spec.md.

Provider wiring (correlation.use_provider, default true)

  • New stateless Correlation\CorrelationIds reads the host's Nowo\CorrelationContract\CorrelationIdProviderInterface service through a NULL_ON_INVALID_REFERENCE reference. HttpLog registers no provider or alias itself, so a host without one keeps the 1.26 ids exactly.
  • HttpLogSubscriber sets the main request's ATTR_REQUEST_ID from provider->current() at kernel.request (1024) and again at kernel.response (-1024), so a provider that starts its unit of work after HttpLog's listener still wins, and a provider that clears its id before HttpLog's terminate listener (-1024) does not matter. No current id (or a throwing provider): generated as before. Sub-requests keep a generated id.
  • request_id stays the row's unique dedupe key (async retry guard). Outbound and mailer rows therefore cannot share it (several per request): they keep their own unique event id, and the shared id goes to correlation_id (below) and to the new HttpLogEntryRecordedEvent::$correlationId.
  • Outbound / mailer: HttpLogFrame gains correlationId, filled by HttpLogContext::current() at call time (provider id, else the main request's request_id, else null). The frame is taken when the call or the send starts, so the value matches the request / message that made it.

Trusted-proxy rule (upstream_id)

  • Read only with correlation.columns: true, only for the main request, only when Request::isFromTrustedProxy() (framework.trusted_proxies). Headers in order from correlation.upstream_headers (default X-Request-Id, X-Correlation-Id, traceparent; at most 4, validated names). traceparent → CorrelationId::tryFromTraceparent(), others → tryFromString(). First valid value wins; anything untrusted or invalid is dropped silently (raw values never logged). Kept on the request (ATTR_UPSTREAM_ID), never in a service (worker mode). Never replaces request_id.
  • Stored on web and named inbound channel rows.

Columns / migration (correlation.columns, default false, literal boolean)

  • Doctrine\CorrelationColumnsListener (registered only when on, like error_code) maps nullable correlation_id / upstream_id VARCHAR(64) (= CorrelationId::MAX_LENGTH) and indexes idx_http_log_corr_id (correlation_id, created_at) / idx_http_log_upstream (upstream_id, created_at) (24 chars max, within TablePrefixListener's fixed-name budget). Exact-match collation on MySQL / MariaDB (ExactColumnsCollationListener::COLUMNS), since ids are case-sensitive.
  • UPGRADING "To 1.27.0" has per-platform DDL blocks (correlation-ddl:*), verified by UsageSchemaTest::documentedCorrelationDdlLeavesNoSchemaDiff on SQLite / MySQL / PostgreSQL with the three prefix variants.
  • Admin: exact correlationId / upstreamId filters (independent of the usage columns), both ids on the entry page; export criteria keep them. CSV / JSON exports append correlationId, upstreamId last; CSV cells go through the existing formula neutralisation.

Response header (item 4)

Skipped: HttpLog owns no response header today (it never writes to the response), so echoing X-Request-Id stays with the provider's integration (documented).

Why a hard require

nowo-tech/correlation-contract has no dependency beyond PHP (interfaces, one value object, a null provider, header constants). The bundle type-hints CorrelationIdProviderInterface in a service constructor and uses CorrelationId for validation on every capture path; a soft dependency would need interface_exists guards and duplicate validation for no gain. The demo lock is updated (check-demo-lock.py).

Tests

  • Unit: CorrelationIdsTest, HttpLogSubscriberCorrelationTest, CorrelationExtensionTest, context / capture / guard / inbound recorder / filter form additions.
  • Integration: CorrelationColumnsTest (mapping, writes, case-sensitive filters, events, exports), documented DDL, exact collation, admin pages render.
  • database group: CorrelationColumnsDbTest on MySQL 8.4, MariaDB 11.4, PostgreSQL 16 (prefixed indexes, exact matching).
  • 100 % line coverage, PHPStan, CS, Igor locally.

Docs

CHANGELOG [Unreleased], UPGRADING "To 1.27.0", CONFIGURATION correlation section (+ full tree), README, spec 005, code inventory (also maps the 3 error_code files 1.26 left out: 145/145).

🤖 Generated with Claude Code

…-in correlation_id / upstream_id

Adopt nowo-tech/correlation-contract ^0.1 (Beacon spec 235 FR-002 / FR-005).
The main request's request_id comes from the host's
CorrelationIdProviderInterface service when one is registered (read at
kernel.request and kernel.response), else it is generated as before.
correlation.columns maps nullable correlation_id (shared by web, named
channel, outbound and mailer rows of a request) and upstream_id (X-Request-Id
/ X-Correlation-Id / traceparent trace-id, trusted proxies only, validated),
with indexes, exact collation, admin filters, entry fields and export
columns. Spec 005, UPGRADING To 1.27.0 with per-platform DDL.
@github-actions

Copy link
Copy Markdown

@coderabbitai review

… correlation_id

One indexed lookup on (correlation_id, created_at) returns a request's web row
(correlation_id = request_id), its named inbound channel rows and its outbound /
mailer rows; covered on MySQL 8.4, MariaDB 11.4 and PostgreSQL 16. UPGRADING and
CHANGELOG state it explicitly.
…HL-M1)

request_id stays HttpLog's own generated unique id for every row, as in 1.26:
a provider id that repeats can no longer collapse or drop rows. The provider's
id only becomes the correlation id (ATTR_CORRELATION_ID, correlation_id,
HttpLogEntryRecordedEvent::$correlationId), read on the main request at
kernel.request, kernel.response and kernel.terminate (I1).

L1: outbound calls and mails re-read the provider when recorded if it had no id
at their start (HttpLogContext::correlationIdAtCapture()).
I2: upstream_headers is replaced, not merged, by a later config file.
I3: tests for two main requests with the same provider id (sync and async, SQLite
and MySQL / MariaDB / PostgreSQL) and a provider throwing at kernel.response.
L2 / L3: docs state that a trusted proxy must overwrite the upstream headers, and
the CHANGELOG no longer claims a request_id change.
@HecFranco
HecFranco marked this pull request as ready for review November 28, 2026 08:53
@HecFranco
HecFranco merged commit a528945 into main Nov 28, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant