Skip to content

Feature/issue 1971 correlation id logging#1981

Open
kayjoosten wants to merge 11 commits intomainfrom
feature/issue-1971-correlation-id-logging
Open

Feature/issue 1971 correlation id logging#1981
kayjoosten wants to merge 11 commits intomainfrom
feature/issue-1971-correlation-id-logging

Conversation

@kayjoosten
Copy link
Copy Markdown
Contributor

No description provided.

@kayjoosten kayjoosten force-pushed the feature/issue-1971-correlation-id-logging branch from 8ee83d0 to bf1e8e1 Compare April 16, 2026 14:50
@kayjoosten kayjoosten requested a review from johanib April 17, 2026 09:24
Copy link
Copy Markdown
Contributor

@johanib johanib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general approach is good! Still, I think some rework to cleanup the architecture & improve the behat tests will add a lot of value.

Comment thread src/OpenConext/EngineBlock/Request/CorrelationId.php Outdated
Comment thread src/OpenConext/EngineBlock/Request/CorrelationIdRepository.php Outdated
Comment thread src/OpenConext/EngineBlock/Request/CorrelationIdRepository.php Outdated
Comment thread src/OpenConext/EngineBlock/Request/CorrelationIdRepository.php Outdated
Comment thread library/EngineBlock/Application/DiContainer.php Outdated
Comment thread src/OpenConext/EngineBlock/Request/CorrelationIdRepository.php Outdated
Comment thread src/OpenConext/EngineBlock/Request/CorrelationIdRepository.php Outdated
Comment thread library/EngineBlock/Corto/Module/Service/AssertionConsumer.php Outdated
@kayjoosten kayjoosten force-pushed the feature/issue-1971-correlation-id-logging branch 2 times, most recently from 73b3503 to 7e17a65 Compare April 21, 2026 16:08
@kayjoosten kayjoosten requested a review from johanib April 23, 2026 08:04
@kayjoosten kayjoosten force-pushed the feature/issue-1971-correlation-id-logging branch from e84276d to e5e4d1f Compare April 23, 2026 11:21
Comment thread library/EngineBlock/Corto/Module/Service/AssertionConsumer.php Outdated
@johanib johanib linked an issue May 6, 2026 that may be closed by this pull request
kayjoosten and others added 10 commits May 7, 2026 08:31
Introduces components to address issue #1971:

- CorrelationId: immutable value object wrapping a hex correlation ID
- CurrentCorrelationId: mutable DI singleton holding the active correlation
  ID for the current HTTP request; read by the Monolog processor
- CorrelationIdRepository: session-backed store with store/find/link methods;
  no-ops safely when no session is available (CLI, unit tests)
- CorrelationIdService: orchestrator with mint/link/resolve used by Corto:
    mint(requestId)    — generate a new ID if none exists (back-button safe)
    link(target, src)  — copy an ID to a second SAML request ID
    resolve(requestId) — look up and push into CurrentCorrelationId
- CorrelationIdProcessor: Monolog processor stamping correlation_id on every
  log record via CurrentCorrelationId
- TestLogHandler: in-memory Monolog handler for Behat log assertions,
  registered in ci and test monolog config

DI wiring: services.yml registers all services; logging.yml registers the
processor. DiContainer exposes getCorrelationIdService() as the bridge from
legacy Corto code into Symfony.
Migrates AuthnRequestSessionRepository from \$_SESSION to the Symfony
session (via RequestStack) and registers it as a DI service, so all
call sites use DiContainer instead of constructing it with a logger.

Each HTTP leg resolves the correlation ID at the top of its handler:

  Leg 1 SSO           — mint() + resolve() in SingleSignOn (WAYF path);
                        mint() + link() + resolve() in ProxyServer (direct path)
  Leg 2 ContinueToIdp — resolve() so log lines in this leg carry the ID;
                        ProxyServer also calls link() to tie the IdP request ID
                        to the SP request ID (idempotent second resolve)
  Leg 3 ACS           — resolve() via InResponseTo (IdP request ID)
  Leg 4 Consent       — resolve() via SP request ID in ProvideConsent
                        and ProcessConsent
Unit tests:
- CorrelationIdRepositoryTest: store/find/link + SessionNotFoundException safety
- CorrelationIdServiceTest: mint idempotency, link, resolve, null safety
- CorrelationIdFlowTest: end-to-end simulation of all four SAML legs (WAYF,
  direct, concurrent flows, back-button replay guard)
- CorrelationIdProcessorTest: stamps correlation_id; null when not set
- AuthnRequestSessionRepositoryTest: updated to inject RequestStack +
  MockArraySessionStorage (logger constructor removed)
- ProcessConsentTest / ProvideConsentTest: inject RequestStack-backed
  repository; stub getReceivedRequestFromResponse for isolation

Behat:
- CorrelationId.feature: WAYF and direct path scenarios assert every log
  record carries a non-null correlation_id field
- LoggingContext: @BeforeScenario reset + "each log record should contain
  a :field field" step
- TestLogHandler wired into behat.yml default suite contexts
@johanib johanib force-pushed the feature/issue-1971-correlation-id-logging branch from 3557fe0 to 464f9e4 Compare May 7, 2026 06:31
And I give my consent
And I pass through EngineBlock
Then the url should match "functional-testing/CorrId-SP/acs"
# And I dump the log records
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be removed? Or do you want to let it stay so we know later on thats a option?

use Monolog\Level;
use Monolog\LogRecord;

final class TestLogHandler extends AbstractProcessingHandler
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this class still needed now we write to files?

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.

No way to track requests through the logs

2 participants