From e615d8246f3d97636d28f5cd7229ee55f90a5ad2 Mon Sep 17 00:00:00 2001 From: zhifenglee-aelf Date: Fri, 25 Oct 2024 21:32:43 +0800 Subject: [PATCH] fix(executiontime): fixed concurrent issue --- AElf.OpenTelemetry/ExecutionTime/ExecutionTimeRecorder.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AElf.OpenTelemetry/ExecutionTime/ExecutionTimeRecorder.cs b/AElf.OpenTelemetry/ExecutionTime/ExecutionTimeRecorder.cs index d218ae8..b61abc7 100644 --- a/AElf.OpenTelemetry/ExecutionTime/ExecutionTimeRecorder.cs +++ b/AElf.OpenTelemetry/ExecutionTime/ExecutionTimeRecorder.cs @@ -1,3 +1,4 @@ +using System.Collections.Concurrent; using System.Diagnostics; using System.Diagnostics.Metrics; using Volo.Abp.DependencyInjection; @@ -7,7 +8,7 @@ namespace AElf.OpenTelemetry.ExecutionTime; public class ExecutionTimeRecorder : ISingletonDependency, IInterceptor { private readonly Meter _meter; - private readonly Dictionary> _histogramMapCache = new Dictionary>(); + private readonly ConcurrentDictionary> _histogramMapCache = new ConcurrentDictionary>(); public ExecutionTimeRecorder(IInstrumentationProvider instrumentationProvider) { @@ -41,7 +42,7 @@ private Histogram GetHistogram(string className, string methodName) description: "Histogram for method execution time", unit: "ms" ); - _histogramMapCache.Add(key, histogram); + _histogramMapCache.TryAdd(key, histogram); return histogram; } } \ No newline at end of file