-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BREAKING CHANGE] DefaultTracing: Removes DefaultTraceListener to dis…
…able tracing by default (#2926) This PR is removing the DefaultTraceListener from the TraceSource by default unless there is a debugger attached. It is enabled by default for debugging scenario because performance is not an issue in those scenarios, and it can be helpful to root cause the issue being debugged. The DefaultTraceListener adds a significant amount of overhead and will cause lock contention. There have been several live site incidents caused by this. This issue is more problematic for .NET Core because the app config file is not supported which make it difficult to disable it. For example, the performance project had to use reflection to get the trace source to remove it programmatically.
- Loading branch information
Showing
4 changed files
with
116 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DefaultTracingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
namespace Microsoft.Azure.Cosmos.Tests | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Net.Http; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Cosmos.Core.Trace; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
[TestClass] | ||
public class DefaultTracingTests | ||
{ | ||
[TestMethod] | ||
public void DefaultTracingEnableTest() | ||
{ | ||
// Access cosmos client to cause the static consturctor to get called | ||
Assert.IsTrue(CosmosClient.numberOfClientsCreated >= 0); | ||
|
||
if (!Debugger.IsAttached) | ||
{ | ||
Assert.IsFalse(this.DefaultTraceHasDefaultTraceListener()); | ||
DefaultTrace.TraceSource.Listeners.Add(new DefaultTraceListener()); | ||
} | ||
|
||
Assert.IsTrue(this.DefaultTraceHasDefaultTraceListener()); | ||
typeof(CosmosClient).GetMethod("RemoveDefaultTraceListener", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null); | ||
//CosmosClient.RemoveDefaultTraceListener(); | ||
Assert.IsFalse(this.DefaultTraceHasDefaultTraceListener()); | ||
} | ||
|
||
private bool DefaultTraceHasDefaultTraceListener() | ||
{ | ||
if (DefaultTrace.TraceSource.Listeners.Count == 0) | ||
{ | ||
return false; | ||
} | ||
|
||
foreach (TraceListener listener in DefaultTrace.TraceSource.Listeners) | ||
{ | ||
if (listener is DefaultTraceListener) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
DefaultTrace.TraceSource.Listeners.Clear(); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters