Skip to content

Commit

Permalink
try1
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabh1007 committed Mar 13, 2023
1 parent cfc3415 commit ae6b51b
Showing 1 changed file with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ internal static class OpenTelemetryRecorderFactory
/// </summary>
private static DiagnosticScopeFactory ScopeFactory { get; set; }

private static readonly object lockObject = new object();

public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
string containerName,
string databaseName,
Expand All @@ -26,28 +28,32 @@ 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
.CreateScope(name: $"{OpenTelemetryAttributeKeys.OperationPrefix}.{operationName}",
kind: clientContext.ClientOptions.ConnectionMode == ConnectionMode.Gateway ? DiagnosticScope.ActivityKind.Internal : DiagnosticScope.ActivityKind.Client);

// Record values only when we have a valid Diagnostic Scope
if (scope.IsEnabled)
lock (lockObject)
{
return new OpenTelemetryCoreRecorder(
scope: scope,
operationName: operationName,
containerName: containerName,
databaseName: databaseName,
operationType: operationType,
clientContext: clientContext,
config: requestOptions?.DistributedTracingOptions ?? clientContext.ClientOptions?.DistributedTracingOptions);
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
.CreateScope(name: $"{OpenTelemetryAttributeKeys.OperationPrefix}.{operationName}",
kind: clientContext.ClientOptions.ConnectionMode == ConnectionMode.Gateway ? DiagnosticScope.ActivityKind.Internal : DiagnosticScope.ActivityKind.Client);

// Record values only when we have a valid Diagnostic Scope
if (scope.IsEnabled)
{
return new OpenTelemetryCoreRecorder(
scope: scope,
operationName: operationName,
containerName: containerName,
databaseName: databaseName,
operationType: operationType,
clientContext: clientContext,
config: requestOptions?.DistributedTracingOptions ?? clientContext.ClientOptions?.DistributedTracingOptions);
}
}

}

return default;
Expand Down

0 comments on commit ae6b51b

Please sign in to comment.