Skip to content

[Spring Data Cosmos] Add @EnableReactiveCosmosAuditing support (#42115)#48784

Draft
jeet1995 wants to merge 1 commit intoAzure:mainfrom
jeet1995:squad/42115-spring-reactive-auditor
Draft

[Spring Data Cosmos] Add @EnableReactiveCosmosAuditing support (#42115)#48784
jeet1995 wants to merge 1 commit intoAzure:mainfrom
jeet1995:squad/42115-spring-reactive-auditor

Conversation

@jeet1995
Copy link
Copy Markdown
Member

Issue

Fixes #42115

Problem

@EnableCosmosAuditing\ only supports blocking \AuditorAware\ which reads from thread-local. In Spring WebFlux apps, user identity lives in the Reactor context, making @CreatedBy/@LastModifiedBy\ fields stay empty.

Solution

Mirrored Spring Data MongoDB's @EnableReactiveMongoAuditing\ pattern:

  1. Created @EnableReactiveCosmosAuditing\ annotation
  2. Created \ReactiveCosmosAuditingRegistrar\ that registers \ReactiveIsNewAwareAuditingHandler\
  3. Updated \ReactiveCosmosTemplate\ to chain reactive auditing via \Mono\ — reactive handler takes precedence when present, blocking handler is fallback
  4. Both @EnableCosmosAuditing\ and @EnableReactiveCosmosAuditing\ can coexist via separate bean names

Dependencies

Uses \ReactiveIsNewAwareAuditingHandler\ and \ReactiveAuditingEntityCallback\ from Spring Data Commons 4.0.4+ (already satisfied).

Testing

  • 2 new unit tests (bean registration + type verification)
  • 118 existing tests remain green

…zure#42115)

Implement reactive auditing support for Spring Data Cosmos to enable
proper Reactor context propagation for @CreatedBy/@LastModifiedBy fields
in Spring WebFlux applications.

Changes:
- Create @EnableReactiveCosmosAuditing annotation
- Create ReactiveCosmosAuditingRegistrar (registers ReactiveIsNewAwareAuditingHandler)
- Update ReactiveCosmosTemplate to accept and use ReactiveIsNewAwareAuditingHandler
- Make markAuditedIfConfigured() reactive, returning Mono<T>
- Update insert/upsert/insertAll to chain auditing in the reactive pipeline
- Update AbstractCosmosConfiguration to wire reactive auditing handler
- Add REACTIVE_AUDITING_HANDLER_BEAN_NAME constant for bean coexistence
- Add unit tests for registrar bean registration
- Add integration test config and tests for reactive auditing

Both @EnableCosmosAuditing (blocking) and @EnableReactiveCosmosAuditing
(reactive) can coexist via separate bean names.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot added the azure-spring All azure-spring related issues label Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-spring All azure-spring related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE REQ] CosmosDB Spring Data Auditor ReactiveAuditorAware support

1 participant