Skip to content

Conversation

@abparticular
Copy link
Contributor

No description provided.

@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
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
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.

/// </summary>
public Audit()
{
Prerequisite(context => context.Settings.GetOrDefault<bool>("Audit.Enabled"), $"Auditing was disabled via the `{IsEnabledEnvironmentVariableKey}` environment variable setting");
Copy link
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
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.

@ramonsmits
Copy link
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 on lines +33 to +40
var auditEnabledValue = Environment.GetEnvironmentVariable(Features.Audit.IsEnabledEnvironmentVariableKey);
Settings.SetDefault("Audit.Enabled", auditEnabledValue is null || !bool.TryParse(auditEnabledValue, out var isEnabled) || isEnabled);

var defaultAuditQueue = Environment.GetEnvironmentVariable(Features.Audit.AddressEnvironmentVariableKey);
if (defaultAuditQueue is not null)
{
Settings.Set("Audit.Address", defaultAuditQueue);
}
Copy link
Member

Choose a reason for hiding this comment

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

Conform to extensions.configuration behavior:

  1. Please ensure this is case-insensitive, so also support NSERVICEBUS__AUDIT__ISENABLED
  2. Please support both variations so with : and __ to behave similarly to extensions.configuration.

This isn't really following POSIX "standards":

  1. Usually just the existence of a key often is sufficient. Consider complying to the robustness principle and also accept 1 as valid value, support uppercase (POSIX convention) as envvar keys are case-sensitive.
  2. IsEnabled is not very common for envvars, likely better to just use Enable. This would result in NSERVICEBUS__AUDIT__ENABLE which IMHO is better.

Copy link
Member

Choose a reason for hiding this comment

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

Synced with @abparticular , preferring full uppercase as is common for envvars.

Not support 1 as that is not compatible with Extentions.Configuration

My comment on : was incorrect, that is invalid for envvar keys, but is valid for other configuration providers.

I asked why the Enable flag is needed and he mentioned that there is also a need to disable auditing where removing __ADDRESS isn't sufficient as it could be configured via the code api and specifying an empty address value does not feel right which I agree. If the intent it disabling, why not use that in the envvar key, as the default without it is that auditing is enabled.

public sealed class Audit : Feature
{
internal const string AddressEnvironmentVariableKey = "NServiceBus__Audit__Address";
internal const string IsEnabledEnvironmentVariableKey = "NServiceBus__Audit__IsEnabled";
Copy link
Member

Choose a reason for hiding this comment

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

If disabling the feature is the intent of the flag, why not name it NSERVICEBUS__AUDIT__DISABLED. Not against NSERVICEBUS_AUDIT_ENABLED, but it seems to better describe intent.

Suggested change
internal const string IsEnabledEnvironmentVariableKey = "NServiceBus__Audit__IsEnabled";
internal const string IsDisabledEnvironmentVariableKey = "NSERVICEBUS_AUDIT_DISABLE";

/// </summary>
public sealed class Audit : Feature
{
internal const string AddressEnvironmentVariableKey = "NServiceBus__Audit__Address";
Copy link
Member

@ramonsmits ramonsmits Jan 23, 2026

Choose a reason for hiding this comment

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

Suggested change
internal const string AddressEnvironmentVariableKey = "NServiceBus__Audit__Address";
internal const string AddressEnvironmentVariableKey = "NSERVICEBUS__AUDIT__ADDRESS";

@ramonsmits
Copy link
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.

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.

6 participants