Skip to content

Commit

Permalink
fix(executiontime): fixed concurrent issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zhifenglee-aelf committed Oct 25, 2024
1 parent 2ca709a commit 402cf77
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions AElf.OpenTelemetry/ExecutionTime/ExecutionTimeRecorder.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.Metrics;
using Volo.Abp.DependencyInjection;
Expand All @@ -7,7 +8,7 @@ namespace AElf.OpenTelemetry.ExecutionTime;
public class ExecutionTimeRecorder : ISingletonDependency, IInterceptor
{
private readonly Meter _meter;
private readonly Dictionary<string, Histogram<long>> _histogramMapCache = new Dictionary<string, Histogram<long>>();
private readonly ConcurrentDictionary<string, Histogram<long>> _histogramMapCache = new ConcurrentDictionary<string, Histogram<long>>();

public ExecutionTimeRecorder(IInstrumentationProvider instrumentationProvider)
{
Expand Down Expand Up @@ -41,7 +42,7 @@ private Histogram<long> GetHistogram(string className, string methodName)
description: "Histogram for method execution time",
unit: "ms"
);
_histogramMapCache.Add(key, histogram);
_histogramMapCache.TryAdd(key, histogram);
return histogram;
}
}

0 comments on commit 402cf77

Please sign in to comment.