-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OpenTelemetry.Instrumentation.AWS] Fix Memory Leak by Reusing Activi…
…tySources, Meters, and Instruments (#2039)
- Loading branch information
1 parent
f0a5a6e
commit ce8c21e
Showing
9 changed files
with
92 additions
and
23 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
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
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
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
15 changes: 14 additions & 1 deletion
15
src/OpenTelemetry.Instrumentation.AWS/Implementation/Tracing/AWSTracerProvider.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 |
---|---|---|
@@ -1,14 +1,27 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Collections.Concurrent; | ||
using System.Diagnostics; | ||
using Amazon.Runtime.Telemetry.Tracing; | ||
|
||
namespace OpenTelemetry.Instrumentation.AWS.Implementation.Tracing; | ||
|
||
internal sealed class AWSTracerProvider : TracerProvider | ||
{ | ||
private static readonly ConcurrentDictionary<string, AWSTracer> TracersDictionary = new ConcurrentDictionary<string, AWSTracer>(); | ||
|
||
public override Tracer GetTracer(string scope) | ||
{ | ||
return new AWSTracer(scope); | ||
if (TracersDictionary.TryGetValue(scope, out AWSTracer? awsTracer)) | ||
{ | ||
return awsTracer; | ||
} | ||
|
||
awsTracer = TracersDictionary.GetOrAdd( | ||
scope, | ||
new AWSTracer(new ActivitySource(scope))); | ||
|
||
return awsTracer; | ||
} | ||
} |
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