diff --git a/Microsoft.Azure.Cosmos/src/Tracing/Trace.cs b/Microsoft.Azure.Cosmos/src/Tracing/Trace.cs index 53fc03e23f..dfddd7131e 100644 --- a/Microsoft.Azure.Cosmos/src/Tracing/Trace.cs +++ b/Microsoft.Azure.Cosmos/src/Tracing/Trace.cs @@ -12,6 +12,7 @@ namespace Microsoft.Azure.Cosmos.Tracing internal sealed class Trace : ITrace { private static readonly IReadOnlyDictionary EmptyDictionary = new Dictionary(); + private readonly object lockObject; private volatile List children; private volatile Dictionary data; private ValueStopwatch stopwatch; @@ -25,6 +26,7 @@ private Trace( TraceSummary summary) { this.Name = name ?? throw new ArgumentNullException(nameof(name)); + this.lockObject = new object(); this.Id = Guid.NewGuid(); this.StartTime = DateTime.UtcNow; this.stopwatch = ValueStopwatch.StartNew(); @@ -122,7 +124,7 @@ public ITrace StartChild( public void AddChild(ITrace child) { - lock (this.Name) + lock (this.lockObject) { if (!this.isBeingWalked) { @@ -172,7 +174,7 @@ public void AddDatum(string key, TraceDatum traceDatum) public void AddDatum(string key, object value) { - lock (this.Name) + lock (this.lockObject) { this.data ??= new Dictionary(); @@ -192,7 +194,7 @@ public void AddDatum(string key, object value) public void AddOrUpdateDatum(string key, object value) { - lock (this.Name) + lock (this.lockObject) { this.data ??= new Dictionary(); @@ -217,7 +219,7 @@ internal void SetWalkingStateRecursively() return; // Already set, return early } - lock (this.Name) + lock (this.lockObject) { if (this.isBeingWalked) { @@ -239,7 +241,7 @@ internal void SetWalkingStateRecursively() bool ITrace.TryGetDatum(string key, out object datum) { - lock (this.Name) + lock (this.lockObject) { if (this.data == null) {