diff --git a/MiniProfiler.WCF.nuspec b/MiniProfiler.WCF.nuspec index a499e5003..259cb052a 100644 --- a/MiniProfiler.WCF.nuspec +++ b/MiniProfiler.WCF.nuspec @@ -2,7 +2,7 @@ MiniProfiler.WCF - 3.0.12.1-wcffix-006 + 3.0.12.1-wcffix-009 Marc Gravell, Sam Saffron, Jarrod Dixon Marc Gravell, Sam Saffron, Jarrod Dixon MiniProfiler integration for WCF diff --git a/StackExchange.Profiling.Tests/StackExchange.Profiling.Tests.csproj b/StackExchange.Profiling.Tests/StackExchange.Profiling.Tests.csproj index d1f64d206..ce3ee816e 100644 --- a/StackExchange.Profiling.Tests/StackExchange.Profiling.Tests.csproj +++ b/StackExchange.Profiling.Tests/StackExchange.Profiling.Tests.csproj @@ -94,6 +94,7 @@ ..\packages\Microsoft.SqlServer.Compact.4.0.8876.1\lib\net40\System.Data.SqlServerCe.dll + @@ -122,6 +123,7 @@ + @@ -138,11 +140,16 @@ {7F18DC76-61A2-4E7D-BA5A-FE159E789362} StackExchange.Profiling.EntityFramework + + {c471b0e5-0ae4-48e0-a938-02aeda030c5e} + StackExchange.Profiling.Wcf + {386222BD-6B6E-480F-A342-8DE1AB516E2C} StackExchange.Profiling + diff --git a/StackExchange.Profiling.Tests/WCF/WcfMiniProfilerDispatchInspectorTest.cs b/StackExchange.Profiling.Tests/WCF/WcfMiniProfilerDispatchInspectorTest.cs new file mode 100644 index 000000000..f5989ac0c --- /dev/null +++ b/StackExchange.Profiling.Tests/WCF/WcfMiniProfilerDispatchInspectorTest.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.ServiceModel; +using System.ServiceModel.Channels; +using System.Text; +using NUnit.Framework; +using StackExchange.Profiling.Wcf; + +namespace StackExchange.Profiling.Tests.WCF +{ + [TestFixture] + public class WcfMiniProfilerDispatchInspectorTest + { + [Test] + public void WillSuppressSQlCommandTextInHeader() + { + MiniProfiler.Settings.ProfilerProvider = new SingletonProfilerProvider(); + var profiler = MiniProfiler.Start(nameof(this.WillSuppressSQlCommandTextInHeader)); + profiler.Root.AddCustomTiming("sql", + new CustomTiming(profiler, nameof(this.WillSuppressSQlCommandTextInHeader), 5)); + + var message = Message.CreateMessage(MessageVersion.Soap12, nameof(this.WillSuppressSQlCommandTextInHeader)); + + var wcfMiniProfilerDispatchInspector = new WcfMiniProfilerDispatchInspector(false); + wcfMiniProfilerDispatchInspector.BeforeSendReply(ref message, new MiniProfilerRequestHeader()); + + var resultHeader = message.Headers.GetHeader(MiniProfilerResultsHeader.HeaderName, + MiniProfilerResultsHeader.HeaderNamespace); + Assert.AreEqual(0, resultHeader.ProfilerResults.Root.CustomTimings.Count()); + } + + [Test] + public void WillSerializeProfilerWithoutSqlCommandText() + { + MiniProfiler.Settings.ProfilerProvider = new SingletonProfilerProvider(); + var profiler = MiniProfiler.Start(nameof(this.WillSuppressSQlCommandTextInHeader)); + + var message = Message.CreateMessage(MessageVersion.Soap12, nameof(this.WillSuppressSQlCommandTextInHeader)); + + var wcfMiniProfilerDispatchInspector = new WcfMiniProfilerDispatchInspector(false); + wcfMiniProfilerDispatchInspector.BeforeSendReply(ref message, new MiniProfilerRequestHeader()); + + var resultHeader = message.Headers.GetHeader(MiniProfilerResultsHeader.HeaderName, + MiniProfilerResultsHeader.HeaderNamespace); + Assert.IsNull(resultHeader.ProfilerResults.Root.CustomTimings); + } + } +} \ No newline at end of file diff --git a/StackExchange.Profiling.Wcf/Properties/AssemblyInfo.cs b/StackExchange.Profiling.Wcf/Properties/AssemblyInfo.cs index b1377943d..087d57420 100644 --- a/StackExchange.Profiling.Wcf/Properties/AssemblyInfo.cs +++ b/StackExchange.Profiling.Wcf/Properties/AssemblyInfo.cs @@ -12,4 +12,4 @@ [assembly: ComVisible(false)] [assembly: Guid("a95b0bf2-e9cf-4029-b77a-85b9e66fd3d5")] [assembly: AssemblyVersion("3.0.12.1")] -[assembly: AssemblyInformationalVersion("3.0.12.1-wcffix-006")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("3.0.12.1-wcffix-009")] \ No newline at end of file diff --git a/StackExchange.Profiling.Wcf/WcfMiniProfilerBehavior.cs b/StackExchange.Profiling.Wcf/WcfMiniProfilerBehavior.cs index e1e08bb72..815e99a7e 100644 --- a/StackExchange.Profiling.Wcf/WcfMiniProfilerBehavior.cs +++ b/StackExchange.Profiling.Wcf/WcfMiniProfilerBehavior.cs @@ -1,6 +1,7 @@ namespace StackExchange.Profiling.Wcf { using System; + using System.Configuration; using System.ServiceModel.Configuration; using System.ServiceModel.Description; @@ -9,6 +10,21 @@ /// public class WcfMiniProfilerBehavior : BehaviorExtensionElement, IEndpointBehavior { + [ConfigurationProperty("logSql")] + public bool LogSqlCommandText + { + get + { + if (bool.TryParse(this["logSql"]?.ToString(), out var val)) + { + return val; + } + return false; + } + + set => this["logSql"] = value; + } + /// /// Gets the behaviour type. /// @@ -44,7 +60,7 @@ public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Di /// The endpoint dispatcher. public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher) { - var inspector = new WcfMiniProfilerDispatchInspector(); + var inspector = new WcfMiniProfilerDispatchInspector(this.LogSqlCommandText); endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector); } @@ -65,4 +81,4 @@ protected override object CreateBehavior() return this; } } -} +} \ No newline at end of file diff --git a/StackExchange.Profiling.Wcf/WcfMiniProfilerDispatchInspector.cs b/StackExchange.Profiling.Wcf/WcfMiniProfilerDispatchInspector.cs index 3ccdf0ccc..ac6e1ce28 100644 --- a/StackExchange.Profiling.Wcf/WcfMiniProfilerDispatchInspector.cs +++ b/StackExchange.Profiling.Wcf/WcfMiniProfilerDispatchInspector.cs @@ -12,11 +12,18 @@ /// public class WcfMiniProfilerDispatchInspector : IDispatchMessageInspector { + protected readonly bool _logSqlCommandText; + /// /// true if the binding is using http. /// private bool _http; + public WcfMiniProfilerDispatchInspector(bool logSqlCommandText) + { + this._logSqlCommandText = logSqlCommandText; + } + /// /// after the request is received. /// @@ -86,6 +93,13 @@ public void BeforeSendReply(ref Message reply, object correlationState) miniProfiler.Root.RemoveTrivialTimings(); } + if ((false == this._logSqlCommandText) && (null != miniProfiler.Root.CustomTimings) + && (miniProfiler.Root.CustomTimings.ContainsKey("sql"))) + { + miniProfiler = miniProfiler.Clone(); + miniProfiler.Root.CustomTimings.Remove("sql"); + } + var header = new MiniProfilerResultsHeader { ProfilerResults = miniProfiler diff --git a/StackExchange.Profiling/Properties/AssemblyInfo.cs b/StackExchange.Profiling/Properties/AssemblyInfo.cs index 772fcf266..ae5844a8e 100644 --- a/StackExchange.Profiling/Properties/AssemblyInfo.cs +++ b/StackExchange.Profiling/Properties/AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: Guid("f41f8a8f-55ef-44ac-beaf-d6fa475939a7")] [assembly: AssemblyVersion("3.2.1.1")] -[assembly: AssemblyInformationalVersion("3.2.1.1-wcffix-004")] +[assembly: AssemblyInformationalVersion("3.2.1.1-wcffix-004-john")] [assembly: InternalsVisibleTo("StackExchange.Profiling.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001001172d8b313c5125b3503ab4656bc2c04305498b2c75560f2e4fdc70e22fd098b9fdce619c318b5fb92670406d2122c9912ee718cb24544f69b7a92a825bd6e439bf1b51cf8e32be536954881c067a81e3da26ca348f7a17de7dfc07ae6df14ce132a7cfcb6d5f53f939bc9f623ec0e5ff9edab439c04a9b8bf8c110ebe8908be")] \ No newline at end of file