Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lazy factory and threadsafe
  • Loading branch information
sourabh1007 committed Mar 27, 2023
commit 5c65c5602562fa8d316f4e3d579dd8ad57bb255a
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ internal static class OpenTelemetryRecorderFactory
/// <summary>
/// Singleton to make sure we only have one instance of the DiagnosticScopeFactory and pattern matching of listener happens only once
/// </summary>
private static DiagnosticScopeFactory ScopeFactory { get; set; }
private static Lazy<DiagnosticScopeFactory> ScopeFactory = new Lazy<DiagnosticScopeFactory>(() => new DiagnosticScopeFactory(clientNamespace: OpenTelemetryAttributeKeys.DiagnosticNamespace,
resourceProviderNamespace: OpenTelemetryAttributeKeys.ResourceProviderNamespace,
isActivityEnabled: true),
isThreadSafe: true);

public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
string containerName,
Expand All @@ -26,13 +29,9 @@ public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
{
if (clientContext is { ClientOptions.IsDistributedTracingEnabled: true })
{
OpenTelemetryRecorderFactory.ScopeFactory ??= new DiagnosticScopeFactory(clientNamespace: OpenTelemetryAttributeKeys.DiagnosticNamespace,
resourceProviderNamespace: OpenTelemetryAttributeKeys.ResourceProviderNamespace,
isActivityEnabled: true);

// If there is no source then it will return default otherwise a valid diagnostic scope
DiagnosticScope scope = OpenTelemetryRecorderFactory
.ScopeFactory
.ScopeFactory.Value
.CreateScope(name: $"{OpenTelemetryAttributeKeys.OperationPrefix}.{operationName}",
kind: clientContext.ClientOptions.ConnectionMode == ConnectionMode.Gateway ? DiagnosticScope.ActivityKind.Internal : DiagnosticScope.ActivityKind.Client);

Expand Down