diff --git a/src/TraceClient/TraceClient.cs b/src/TraceClient/TraceClient.cs index 991299d..6394132 100644 --- a/src/TraceClient/TraceClient.cs +++ b/src/TraceClient/TraceClient.cs @@ -229,7 +229,12 @@ public TraceClient(string baseUrl, string application, string version, string ke _thread.Start(); } - /// A client that reports nothing. Useful as a default before settings are read. + /// + /// A client that reports nothing. Useful as a default before settings are read. + /// Its is , or + /// when the environment turns reporting off, since + /// the environment is checked first. + /// public static TraceClient Disabled() { return new TraceClient("http://disabled.invalid", "disabled", "disabled", enabled: false); diff --git a/tests/TraceClient.Tests/TraceClientTest.cs b/tests/TraceClient.Tests/TraceClientTest.cs index a71dbf0..377cf06 100644 --- a/tests/TraceClient.Tests/TraceClientTest.cs +++ b/tests/TraceClient.Tests/TraceClientTest.cs @@ -376,6 +376,20 @@ public void DisabledReason_NamesTheConfigFlagOrTheMissingKey() Assert.Equal("config", TraceClient.Disabled().DisabledReason); } + [Fact] + public void Disabled_SaysEnvironmentRatherThanConfigWhenTheEnvironmentOptsOut() + { + // Disabled() goes through the same constructor, and the environment + // is checked before enabled: false, so its reason is not always "config". + _environment[TraceClient.EnvDoNotTrack] = "1"; + + TraceClient client = TraceClient.Disabled(); + + Assert.False(client.IsEnabled); + Assert.Equal(TraceClient.ReasonEnvironment, client.DisabledReason); + Assert.Null(client.InstallId); + } + [Theory] [InlineData("")] [InlineData(" ")]