diff --git a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs
index 836ea91b6d..6c88b3d5db 100644
--- a/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs
+++ b/Microsoft.Azure.Cosmos/src/Telemetry/OpenTelemetry/OpenTelemetryRecorderFactory.cs
@@ -15,11 +15,8 @@ internal static class OpenTelemetryRecorderFactory
///
/// Singleton to make sure we only have one instance of the DiagnosticScopeFactory and pattern matching of listener happens only once
///
- private static Lazy ScopeFactory = new Lazy(() => new DiagnosticScopeFactory(clientNamespace: OpenTelemetryAttributeKeys.DiagnosticNamespace,
- resourceProviderNamespace: OpenTelemetryAttributeKeys.ResourceProviderNamespace,
- isActivityEnabled: true),
- isThreadSafe: true);
-
+ private static DiagnosticScopeFactory ScopeFactory { get; set; }
+
public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
string containerName,
string databaseName,
@@ -29,11 +26,13 @@ public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
{
if (clientContext is { ClientOptions.IsDistributedTracingEnabled: true })
{
- ActivityExtensions.ResetFeatureSwitch();
+ 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.Value
+ .ScopeFactory
.CreateScope(name: $"{OpenTelemetryAttributeKeys.OperationPrefix}.{operationName}",
kind: clientContext.ClientOptions.ConnectionMode == ConnectionMode.Gateway ? DiagnosticScope.ActivityKind.Internal : DiagnosticScope.ActivityKind.Client);
diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs
index 9f18c78028..e17a01d29c 100644
--- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs
+++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Tracing/EndToEndTraceWriterBaselineTests.cs
@@ -24,7 +24,8 @@ namespace Microsoft.Azure.Cosmos.EmulatorTests.Tracing
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using static Microsoft.Azure.Cosmos.SDK.EmulatorTests.TransportClientHelper;
-
+ using AzureCore = global::Azure.Core.Pipeline;
+
[VisualStudio.TestTools.UnitTesting.TestClass]
[TestCategory("UpdateContract")]
public sealed class EndToEndTraceWriterBaselineTests : BaselineTests
@@ -41,10 +42,14 @@ public sealed class EndToEndTraceWriterBaselineTests : BaselineTests