Skip to content

Allow auditing to be configured and enabled via environment variables#7535

Merged
abparticular merged 5 commits intomasterfrom
configurable-auditing
Jan 29, 2026
Merged

Allow auditing to be configured and enabled via environment variables#7535
abparticular merged 5 commits intomasterfrom
configurable-auditing

Conversation

@abparticular
Copy link
Copy Markdown
Contributor

@abparticular abparticular commented Dec 4, 2025

This PR allows auditing to be configured via environment variables to facilitate better control of the audit capability enabled/disabled state, without requiring compiling and redeploying of endpoint instances.

Refer to the Configuring auditing documentation for details.

A follow-up PR is at #7610

@abparticular abparticular force-pushed the configurable-auditing branch from 4d31291 to b4c146b Compare January 6, 2026 04:44
@abparticular abparticular marked this pull request as ready for review January 7, 2026 00:42
@SzymonPobiega
Copy link
Copy Markdown
Member

Looks good but I am wondering (I haven't been working on the core recently) if using environment for config is a new concept in core or something established? If it is a brand new concept then maybe we should explore the .NET configuration APIs to be able to bind the config values from any source, not just environment?

@abparticular
Copy link
Copy Markdown
Contributor Author

abparticular commented Jan 8, 2026

Using environment for config is a new concept in core. The configuration APIs were explored but there didn't seem to be a way to meaningfully use them without a larger integration effort into core.

Comment thread src/NServiceBus.Core/Audit/Audit.cs Outdated
/// </summary>
public Audit()
{
Prerequisite(context => context.Settings.GetOrDefault<bool>("Audit.Enabled"), $"Auditing was disabled via the `{IsEnabledEnvironmentVariableKey}` environment variable setting");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ideally, there would be no changes required to the feature to implement this. I'd prefer to see the changes just in EndpointConfiguration, such that the environment variables just act as if the APIs were called to configure auditing.

If this is related to precedence of API vs. environment variables, it seems like you should be able to move where you're reading the environment variables to allow them to take precedence if that's what you want.

Copy link
Copy Markdown
Contributor Author

@abparticular abparticular Jan 23, 2026

Choose a reason for hiding this comment

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

If the feature remains untouched, then when auditing was disabled via env var, the start up diagnostics would report that auditing was disabled because no configured audit queue was found, which would be inaccurate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I still want to take a deeper look at this, but I'll open a follow-up PR with any changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ramonsmits
Copy link
Copy Markdown
Member

Why does this PR exist? Can this be linked to a TF.

Second, why only audit and why not only put this support in NServiceBus.Extensions.Hosting and properly use Exceptions.Configuration?

Comment thread src/NServiceBus.Core/EndpointConfiguration.cs Outdated
Comment thread src/NServiceBus.Core/Audit/Audit.cs Outdated
Comment thread src/NServiceBus.Core/Audit/Audit.cs Outdated
@ramonsmits
Copy link
Copy Markdown
Member

Why only audit and why not only put this support in NServiceBus.Extensions.Hosting and properly use Exceptions.Configuration?

I didn't mean to use the word ONLY, but ALSO.

There was a comment that this would take an additional dependency which is not the case. NServiceBus.Extensions.Hosting has a dependency to Microsoft.Extentions.Hosting, the package has dependencies on pretty much ALL extension packages as it contains the host builder API that use all these.

Here a 5 minute spike of what I meant for reference:

If the envvar provider is enabled (which it is for both host and web builders) that should work but not only for envvar or appsettings.json but any configured provider like Azure KeyVault.

@abparticular abparticular force-pushed the configurable-auditing branch from 6ad7544 to f39f9ec Compare January 29, 2026 02:37
@abparticular abparticular merged commit 8c7e371 into master Jan 29, 2026
5 of 6 checks passed
@abparticular abparticular deleted the configurable-auditing branch January 29, 2026 03:01
danielmarbach added a commit that referenced this pull request Jan 30, 2026
@danielmarbach
Copy link
Copy Markdown
Contributor

I have raised #7610 as a follow up

danielmarbach added a commit that referenced this pull request Feb 2, 2026
…#7610)

* Revert "Merge pull request #7535 from Particular/configurable-auditing"

This reverts commit 8c7e371, reversing
changes made to 09bae00.

* Allow auditing to be configured and enabled via environment variable

* Better tests

* Comment

---------

Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
@abparticular abparticular added this to the 10.1.0 milestone Feb 4, 2026
@abparticular
Copy link
Copy Markdown
Contributor Author

Released in NServiceBus 10.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants