Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
8a3883e
[Internal] Client Telemetry: Fixes tests leaking environment variable…
ealsur Oct 27, 2022
543294c
Updated change log and bumped up the version. (#3526)
kundadebdatta Oct 29, 2022
abf3d93
Query: Fixes performance regression on target partition on some ORDER…
neildsh Oct 31, 2022
84ef545
[Internal] AI Integration: Adds SubStatusCode Information in attribut…
sourabh1007 Nov 2, 2022
68b9805
Diagnostics: Removes unused properties and reduces size (#3519)
aavasthy Nov 2, 2022
a9bcaf5
[Internal] docs: Add address caches conceptual flow (#3534)
kirankumarkolli Nov 2, 2022
6762e07
Release: Adds SDK version and changelog for 3.31.2 (#3546)
neildsh Nov 3, 2022
ef7339e
[Internal] Documentation: Removes invalid comment from ReadThroughput…
ealsur Nov 4, 2022
825595a
[Internal] nugetconfig: Removes specific overrides (#3551)
kirankumarkolli Nov 7, 2022
4746a6f
Query: Fixes partition range evaluation for spatial queries (#3495)
adityasa Nov 9, 2022
acd899e
[Internal] Documentation: Refactors cache content on its own document…
ealsur Nov 9, 2022
01c1cd4
[Internal] Emulator unit tests: Adds IdEncoding unit tests for Comput…
FabianMeiswinkel Nov 10, 2022
ab1f249
Change Feed Processor: Adds support for Resource Tokens (#3566)
ealsur Nov 15, 2022
9fb3a12
[Internal] AI integration: Refactor code how container and database n…
sourabh1007 Nov 15, 2022
9c2015b
[Internal] AI Integration: Adds a new flag in DistributedTracingOptio…
sourabh1007 Nov 16, 2022
c38346d
Query: Fixes default to BadRequestException in case of internal error…
neildsh Nov 17, 2022
9cafaa8
[Internal] Query: Adds unit tests for Merge/Split implementation with…
akotalwar Nov 17, 2022
2681be8
Client Retry Policy: Adds HTTP timeouts with request-level cross-regi…
NaluTripician Nov 18, 2022
010e4ba
Documentation: Fixes EUAP in Comments (#3579)
PramodValavala-MSFT Nov 21, 2022
b24eeb9
Query: Fixes incorrect FeedResponse.Count when result contains undefi…
neildsh Nov 23, 2022
9734ec5
removed allr eference (#3581)
sourabh1007 Nov 24, 2022
6632168
Trace: Fixes Tracing/diagnostics hour-times to 24Hours (#3577)
kirankumarkolli Nov 24, 2022
8e82a1a
AI Integration: Adds cosmetic fixes (#3576)
sourabh1007 Nov 26, 2022
2f047e1
Query: Adds ALL Scalar Expression (#3509)
ezrahaleva-msft Nov 28, 2022
07b34e6
Release: Adds API contracts for 3.31.2-preview (#3586)
neildsh Nov 28, 2022
5318646
[Internal] sccignore: Adds a .sccignore file to apply an exception fo…
vivekr20 Nov 29, 2022
28318b0
[Internal] PermissionTests: Adds CosmosPermissionTests Coverage (#3593)
prasadu-microsoft Dec 1, 2022
a34bac7
[Internal] AI Integration: Refactors to Operation prefix and add test…
sourabh1007 Dec 5, 2022
6b1fa03
[Internal] HttpTimeoutPolicy: Removes Data Plane Writes from being ab…
NaluTripician Dec 15, 2022
814e72e
[Internal] Performance Testing: Adds Distributed Tracing option in be…
sourabh1007 Dec 20, 2022
5c05fbb
[Internal] Benchmark: Refactors code to make Memory Stream capacity c…
sourabh1007 Jan 4, 2023
73c9e08
add new LatestVersion changefeed mode that has same behavior as Incre…
philipthomas-MSFT Jan 4, 2023
77e3aa4
Query: Fixes handling of CosmosUndefined, CosmosGuid and CosmosBinary…
neildsh Jan 7, 2023
3c875c7
[Internal] Subpartitioning: Adds updates to test coverage for subpart…
NaluTripician Jan 9, 2023
416b154
[Internal] ContainerProperties: Fixes version reset when setting Part…
ealsur Jan 9, 2023
59b70a6
[Internal] AI Integration: Adds CorrelationId and Activity Id Attribu…
sourabh1007 Jan 10, 2023
612337c
Documentation: Fixes CosmosClientBuilder.WithConnectionModeGateway pa…
arthuraugsten Jan 11, 2023
55f9ce8
Upgrade Resiliency: Refactors Implementation for Opening Rntbd Connec…
kundadebdatta Jan 11, 2023
9dde99e
[Preview] AI integration: Adds IsDistributedTracingEnabled flag as pu…
sourabh1007 Jan 12, 2023
36d0e0f
Change Feed Processor: Fixes behavior with StartTime on Local (#3645)
ealsur Jan 13, 2023
bdd059d
[Internal] Client Telemetry: Refactors code to use base useragent str…
sourabh1007 Jan 17, 2023
b3cf7df
[Internal] AI Integration: Refactors code to rename event name (#3648)
sourabh1007 Jan 17, 2023
4b77519
Region Availability: Adds Poland Central Region For Public Usage (#3656)
kundadebdatta Jan 17, 2023
1710115
Client Encryption: Adds validation code to check if the Key Vault URI…
kr-santosh Jan 19, 2023
e383d83
[Internal] Query: Adds Split Support for Ode (#3572)
akotalwar Jan 20, 2023
ccaf8fb
[Internal] AI Integration : Fixes operation type for batch (#3660)
sourabh1007 Jan 23, 2023
c29abfe
CosmosClientOptions: Adds ServerCertificateCustomValidationCallback f…
aavasthy Jan 24, 2023
2608d4a
Query: Adds EnableOptimisticDirectExecution flag to QueryRequestOptio…
akotalwar Jan 26, 2023
d6a439f
[Internal] Tests: Removes Direct/HTTPS emulator tests (#3679)
ealsur Feb 2, 2023
393ae23
[Internal] Benchmark : Fixes issue with dependency on Cosmos Project …
sourabh1007 Feb 2, 2023
122bc56
LocalQuorum: Adds Quorum reads on Consistent Prefix Accounts (#3680)
pravengithub Feb 3, 2023
8a537ce
3.32.0: Adds new SDK version and contract files (#3687)
aavasthy Feb 6, 2023
bf9a6d4
[Internal] Samples: Adds change feed pull model samples (#3646)
jcocchi Feb 9, 2023
16caa1b
[Internal] Tests: Refactors emulator CI (#3688)
ealsur Feb 13, 2023
6434c10
[Internal] GitHub Template: Adds needs-investigation label (#3708)
ealsur Feb 14, 2023
4e923da
Adding fabric bot action (#3709)
ealsur Feb 14, 2023
38d1bcc
CosmosNullReferenceException: Refactors CosmosNullReferenceException …
jeet1995 Feb 17, 2023
209e473
[Internal] PriorityRequests: Fixes header value (#3714)
Achint-Agrawal Feb 17, 2023
67e1a90
[Internal] Query: Adds single physical partition check for Optimistic…
akotalwar Feb 17, 2023
b257f8e
[Internal] CTL: Fixes Reservoir Sampling Logic (#3712)
kundadebdatta Feb 17, 2023
94c83f5
Diagnostics: Adds startDate in Summary (#3707)
NimitS1 Feb 27, 2023
462a2c4
[Internal] Client Telemetry: Adds network information in the payload …
sourabh1007 Feb 27, 2023
0088c2f
Documentation: Fixes Database.ReadAsync description (#3457)
SaurabhSharma-MSFT Mar 1, 2023
fd687f5
Upgrade Resiliency: Adds Implementation for Validating the Unhealthy …
kundadebdatta Mar 1, 2023
93bb10b
ReadMany: Fixes BadRequest when using Ids with single quotes (#3732)
ealsur Mar 1, 2023
45c0d14
Release: Adds SDK version and changelog for 3.32.1 (#3733)
ealsur Mar 1, 2023
0018c4a
[Internal] Build: Fixes static tool analysis versions (#3736)
ealsur Mar 2, 2023
d6e04a9
Query: Fixes System.ArgumentException when using PartitionKey.None on…
neildsh Mar 2, 2023
f262f89
Query: Adds FIRST and LAST Scalar Expressions (#3629)
ezrahaleva-msft Mar 6, 2023
dc3d037
Subpartitioning: Adds support for Prefix Partition Key searches for s…
philipthomas-MSFT Mar 7, 2023
6ebb8d4
[Internal] ClientTelemetry: Adds logic to limit payload size to 2 MB …
sourabh1007 Mar 9, 2023
682b001
Query: Fixes regression from LINQ custom serializer fix (#3749)
leminh98 Mar 10, 2023
f2a3078
[Internal] LocalQuorum: Refactors override (i.e. strong) to allow fro…
kirankumarkolli Mar 10, 2023
d41f099
Release: Adds SDK version and change log for 3.32.2 (#3752)
ealsur Mar 11, 2023
1acfaa2
Subpartitioning: Adds APIs for public release and increase REST API v…
NaluTripician Mar 21, 2023
d0c0578
Change Feed Processor: Fixes LeaseLostException leaks on notification…
ealsur Mar 23, 2023
4ab6293
Upgrade Resiliency: Refactors GatewayAddressCache to Mark TransportAd…
kundadebdatta Mar 23, 2023
d822239
[Preview] PriorityBasedExecution: Adds PriorityLevel as a RequestOpti…
Achint-Agrawal Mar 27, 2023
1c544bf
[Internal] Client Telemetry: Adds sampling logic for network level te…
sourabh1007 Mar 29, 2023
6553a70
[Internal] Emulator Test : Fixes test when running with distributed t…
sourabh1007 Mar 29, 2023
67dc262
Release: Adds SDK version and changelog for 3.32.3 (#3788)
ealsur Mar 30, 2023
a697242
SummaryDiagnostics: Refactors Code to Remove Dependency of HttpRespon…
kundadebdatta Apr 3, 2023
e41eea5
[Internal] Documentation: Fixes API name to NoSQL (#3795)
jcocchi Apr 4, 2023
ba078c9
[Internal] CTL: Fixes docker image pipeline (#3794)
ealsur Apr 4, 2023
ae6bcf3
[Internal] AI Integration : Refactors useragent attribute name as per…
sourabh1007 Apr 4, 2023
2b69394
HttpClient: Adds Properties to the Http messages if available (#3803)
ealsur Apr 6, 2023
4222cef
Documentation: Refactors SQL API reference to NoSQL API (#3793)
scottaddie Apr 6, 2023
fce9702
[Internal] Perf test: Refactors code to re-enable performance tests (…
sourabh1007 Apr 7, 2023
2f2e8fb
HttpClient: Adds detection of DNS changes through use of SocketsHttpH…
NaluTripician Apr 7, 2023
789f701
[Internal] Tests: Fixes Open Telemetry attributes for ReadMany test (…
ealsur Apr 8, 2023
2b6fdb7
[Internal] Client Telemetry: Refactors code to run client telemetry d…
sourabh1007 Apr 10, 2023
33dea8a
Patch: Adds Move Operation (#3389)
Amaan-Haque Apr 11, 2023
31b1ff3
[Internal] Pipelines: Adds nightly build to produce packages (#3802)
ealsur Apr 11, 2023
bfbb43e
[Internal] OpenTelemetry: Direct Package update and replacing diagnos…
aavasthy Apr 18, 2023
f94869a
[Internal] MerlinBot: Adds auto-merge and cleanup automation (#3813)
ealsur Apr 18, 2023
afd5904
Update fabricbot.json (#3824)
ealsur Apr 24, 2023
fb80ba8
[Internal] Upgrade Resiliency: Adds Logic to Validate `Unknown` Repli…
kundadebdatta Apr 24, 2023
5d4f7c1
Serialization: Fixes call to CosmosSerializer.FromStream on Gateway m…
Apr 25, 2023
0d0ffe0
[Internal] Documentation: Adds documentation covering build pipelines…
ealsur Apr 27, 2023
e872f93
Client Encryption: Adds release version of Microsoft.Azure.Cosmos to …
vipulvishal-ms Apr 27, 2023
e5972ac
SDK 3.33.0 : Adds version bump and changelog (#3823)
NaluTripician Apr 27, 2023
7465da2
[Internal] Documentation: Adds msdata/direct Sync-up Guide. (#3828)
kundadebdatta May 1, 2023
20121c8
Query: Adds TRIM string system function support in LINQ (#3833)
leminh98 May 2, 2023
15616d3
Query: Fixes Parsing Error in SQL DOM when CultureInfo is available (…
leminh98 May 2, 2023
1dcba53
Client Encryption: Adds api FetchDataEncryptionKeyWithoutRawKeyAsync …
vipulvishal-ms May 3, 2023
9ba3f75
Initial commit (#3826)
adityasa May 3, 2023
17203a5
Query: Adds Computed Property SDK Support (#3761)
adityasa May 4, 2023
033e883
[Internal] Samples: Adds OpenTelemetry and Application Insights sampl…
jcocchi May 5, 2023
0c15865
[Internal] Query: Added custom serializer coverage tests to Expressio…
onionhammer May 9, 2023
ade7e34
Query: Added remaining Cosmos Type checking functions to CosmosLinqEx…
onionhammer May 9, 2023
aff7349
update sdk version and section tags (#3841)
jcocchi May 10, 2023
1a8b7f0
PackageLicense: Removes PackageLicenseUrl and Adds PackageLicenseFile…
philipthomas-MSFT May 16, 2023
b06d6c3
making ChangeFeedMode.LatestVersion accessible to the public (#3854)
philipthomas-MSFT May 17, 2023
37a80b3
Merge branch 'master' into msdata/direct
kundadebdatta May 17, 2023
0c10434
Code changes to update msdata/direct repo.
kundadebdatta May 17, 2023
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
[Preview] AI integration: Adds IsDistributedTracingEnabled flag as pu…
…blic API to enable/disable this feature (#3598)

* make api public for preview

* add null check

* fix tests

* singleton listener initialization

* assign null to listeners

* fix test

* concurrent bag in listener

* renamed to LatencyThresholdForDiagnosticEvent

* renamed to IsDistributedTracingEnabled

* updated xml

* update contract

* made latency threshold flag internal

* fix test

* regeneratebaselines

* update documentation

* rename builder api

* add docs

* updated contracts and all

* doc update

* import cleanup

Co-authored-by: Sourabh Jain <sourabhjain@microsoft.com>
  • Loading branch information
sourabh1007 and sourabh1007 authored Jan 12, 2023
commit 9dde99e697eacc9c61b6272fb0ea3b761ca041d6
20 changes: 16 additions & 4 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -988,17 +988,29 @@ public override bool CanConvert(Type objectType)
return objectType == typeof(DateTime);
}
}

/// <summary>
/// Distributed Tracing Options. <see cref="Microsoft.Azure.Cosmos.DistributedTracingOptions"/>
/// </summary>
/// <remarks> Applicable only when Operation level distributed tracing is enabled through <see cref="Microsoft.Azure.Cosmos.CosmosClientOptions.IsDistributedTracingEnabled"/></remarks>
internal DistributedTracingOptions DistributedTracingOptions { get; set; }

/// <summary>
/// Gets or sets value indicating whether distributed tracing activities (<see cref="System.Diagnostics.Activity"/>) are going to be created for the SDK methods calls and HTTP calls.
/// By default true for Preview package
/// Gets or sets the flag to generate operation level <see cref="System.Diagnostics.Activity"/> for methods calls using the Source Name "Azure.Cosmos.Operation".
/// </summary>
internal bool EnableDistributedTracing { get; set; }
/// <value>
/// The default value is true (for preview package).
/// </value>
/// <remarks>This flag is there to disable it from source. Please Refer https://opentelemetry.io/docs/instrumentation/net/exporters/ to know more about open telemetry exporters</remarks>
#if PREVIEW
public
#else
internal
#endif
bool IsDistributedTracingEnabled { get; set; }
#if PREVIEW
= true;
#endif

}
}
24 changes: 21 additions & 3 deletions Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,30 @@ public CosmosClientBuilder WithConsistencyLevel(Cosmos.ConsistencyLevel consiste
}

/// <summary>
/// If Open Telemetry listener is subscribed for Azure.Cosmos namespace, There are <see cref="Microsoft.Azure.Cosmos.DistributedTracingOptions"/> you can leverage to control it.<br></br>
/// Sets whether Distributed Tracing for "Azure.Cosmos.Operation" source is enabled.
/// </summary>
/// <param name="options">Tracing Options <see cref="Microsoft.Azure.Cosmos.DistributedTracingOptions"/></param>
/// <param name="isEnabled">Whether <see cref="CosmosClientOptions.IsDistributedTracingEnabled"/> is enabled.</param>
/// <returns>The current <see cref="CosmosClientBuilder"/>.</returns>
internal CosmosClientBuilder WithDistributingTracing(DistributedTracingOptions options)
#if PREVIEW
public
#else
internal
#endif
CosmosClientBuilder WithDistributedTracing(bool isEnabled = true)
{
this.clientOptions.IsDistributedTracingEnabled = isEnabled;
return this;
}

/// <summary>
/// Enables Distributed Tracing with a Configuration ref. <see cref="DistributedTracingOptions"/>
/// </summary>
/// <param name="options"><see cref="DistributedTracingOptions"/>.</param>
/// <returns>The current <see cref="CosmosClientBuilder"/>.</returns>]
/// <remarks>Refer https://opentelemetry.io/docs/instrumentation/net/exporters/ to know more about open telemetry exporters</remarks>
internal CosmosClientBuilder WithDistributedTracingOptions(DistributedTracingOptions options)
{
this.clientOptions.IsDistributedTracingEnabled = true;
this.clientOptions.DistributedTracingOptions = options;

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace Microsoft.Azure.Cosmos
using System;

/// <summary>
/// Open Telemetry Configuration
/// It needs to be public once AppInsight is ready
/// Options for configuring the distributed tracing and event tracing
/// </summary>
internal sealed class DistributedTracingOptions
{
Expand All @@ -23,9 +22,9 @@ internal sealed class DistributedTracingOptions
internal static readonly TimeSpan DefaultQueryTimeoutThreshold = TimeSpan.FromMilliseconds(500);

/// <summary>
/// Latency Threshold to generate (<see cref="System.Diagnostics.Tracing.EventSource"/>) with Request diagnostics in distributing Tracing.<br></br>
/// If it is not set then by default it will generate (<see cref="System.Diagnostics.Tracing.EventSource"/>) for query operation which are taking more than 500 ms and non-query operations taking more than 100 ms.
/// SDK generates <see cref="System.Diagnostics.Tracing.EventSource"/> (Event Source Name is "Azure-Cosmos-Operation-Request-Diagnostics") with Request Diagnostics String, If Operation level distributed tracing is not disabled i.e. <see cref="Microsoft.Azure.Cosmos.CosmosClientOptions.IsDistributedTracingEnabled"/>
/// </summary>
public TimeSpan? DiagnosticsLatencyThreshold { get; set; }
/// <remarks>If it is not set then, by default, it will generate <see cref="System.Diagnostics.Tracing.EventSource"/> for query operation which are taking more than 500 ms and non-query operations taking more than 100 ms.</remarks>
public TimeSpan? LatencyThresholdForDiagnosticEvent { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public static bool IsTracingNeeded(
{
TimeSpan latencyThreshold;

if (config?.DiagnosticsLatencyThreshold != null)
if (config?.LatencyThresholdForDiagnosticEvent != null)
{
latencyThreshold = config.DiagnosticsLatencyThreshold.Value;
latencyThreshold = config.LatencyThresholdForDiagnosticEvent.Value;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Microsoft.Azure.Cosmos.Telemetry
{
using System;
using global::Azure.Core.Pipeline;

/// <summary>
Expand All @@ -15,19 +16,19 @@ internal static class OpenTelemetryRecorderFactory
/// 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; }

public static OpenTelemetryCoreRecorder CreateRecorder(string operationName,
string containerName,
string databaseName,
Documents.OperationType operationType,
RequestOptions requestOptions,
CosmosClientContext clientContext)
{
if (clientContext is { ClientOptions.EnableDistributedTracing: true })
if (clientContext is { ClientOptions.IsDistributedTracingEnabled: true })
{
ScopeFactory = new DiagnosticScopeFactory(clientNamespace: OpenTelemetryAttributeKeys.DiagnosticNamespace,
resourceProviderNamespace: OpenTelemetryAttributeKeys.ResourceProviderNamespace,
isActivityEnabled: 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,10 @@
maxRetryWaitTimeOnThrottledRequests: TimeSpan.FromSeconds(1),
maxRetryAttemptsOnThrottledRequests: 3)
.WithBulkExecution(true)
.WithDistributedTracingOptions(new DistributedTracingOptions()
{
LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(0)
})
.WithTransportClientHandlerFactory(transportClient => new TransportClientWrapper(
transportClient,
(uri, resourceOperation, request) => TransportClientHelper.ReturnThrottledStoreResponseOnItemOperation(
Expand All @@ -1599,12 +1603,6 @@
exceptionActivityId,
errorMessage))));

throttleClient.ClientOptions.EnableDistributedTracing = true;
throttleClient.ClientOptions.DistributedTracingOptions = new DistributedTracingOptions()
{
DiagnosticsLatencyThreshold = TimeSpan.FromMilliseconds(0)
};

ItemRequestOptions requestOptions = new ItemRequestOptions();
Container containerWithThrottleException = throttleClient.GetContainer(
database.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@
string errorMessage = "Mock throttle exception" + Guid.NewGuid().ToString();
Guid exceptionActivityId = Guid.NewGuid();
using CosmosClient throttleClient = TestCommon.CreateCosmosClient(builder =>
builder.WithThrottlingRetryOptions(
builder
.WithDistributedTracingOptions(new DistributedTracingOptions()
{
LatencyThresholdForDiagnosticEvent = TimeSpan.FromMilliseconds(0)
})
.WithThrottlingRetryOptions(
maxRetryWaitTimeOnThrottledRequests: TimeSpan.FromSeconds(1),
maxRetryAttemptsOnThrottledRequests: 3)
.WithTransportClientHandlerFactory(transportClient => new TransportClientWrapper(
Expand All @@ -171,13 +176,7 @@
request,
exceptionActivityId,
errorMessage))));

throttleClient.ClientOptions.EnableDistributedTracing = true;
throttleClient.ClientOptions.DistributedTracingOptions = new DistributedTracingOptions()
{
DiagnosticsLatencyThreshold = TimeSpan.FromMilliseconds(0)
};


ItemRequestOptions requestOptions = new ItemRequestOptions();
Container containerWithThrottleException = throttleClient.GetContainer(
database.Id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace Microsoft.Azure.Cosmos.Tracing
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Tracing
{
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -13,14 +17,16 @@ internal static class AssertActivity
public static void IsValid(Activity activity)
{
Assert.IsTrue(activity.OperationName == activity.DisplayName);
Assert.IsNotNull(activity.GetTagItem("db.cosmosdb.connection_mode"));

Assert.IsFalse(string.IsNullOrEmpty(activity.GetTagItem("db.cosmosdb.connection_mode").ToString()), $"connection mode is emtpy for {activity.OperationName}");

if (activity.GetTagItem("db.cosmosdb.connection_mode").ToString() == ConnectionMode.Gateway.ToString())
{
Assert.AreEqual(ActivityKind.Internal, activity.Kind);
Assert.AreEqual(ActivityKind.Internal, activity.Kind, $" Actual Kind is {activity.Kind} but expected is {ActivityKind.Internal} for {activity.OperationName}");
}
else
else if (activity.GetTagItem("db.cosmosdb.connection_mode").ToString() == ConnectionMode.Direct.ToString())
{
Assert.AreEqual(ActivityKind.Client, activity.Kind);
Assert.AreEqual(ActivityKind.Client, activity.Kind, $" Actual Kind is {activity.Kind} but expected is {ActivityKind.Client} for {activity.OperationName}");
}

IList<string> expectedTags = new List<string>
Expand Down Expand Up @@ -73,8 +79,10 @@ private static void AssertDatabaseAndContainerName(string name, KeyValuePair<str
IList<string> exceptionsForContainerAttribute = new List<string>
{
"Operation.CreateDatabaseAsync",
"Operation.CreateDatabaseIfNotExistsAsync",
"Operation.ReadAsync",
"Operation.DeleteAsync"
"Operation.DeleteAsync",
"Operation.DeleteStreamAsync"
};

if ((tag.Key == OpenTelemetryAttributeKeys.ContainerName && !exceptionsForContainerAttribute.Contains(name)) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.Azure.Cosmos.Tests
/// <summary>
/// It is a custom listener for Activities and Event. It is used to validate the Activities generated by cosmosDb SDK.
/// </summary>
public class CustomListener :
internal class CustomListener :
EventListener, // Override Event Listener to capture Event source events
IObserver<KeyValuePair<string, object>>, // Override IObserver to capture Activity events
IObserver<DiagnosticListener>,
Expand All @@ -27,8 +27,8 @@ public class CustomListener :
private readonly Func<string, bool> sourceNameFilter;
private readonly string eventName;

private List<IDisposable> subscriptions = new();
private List<ProducedDiagnosticScope> Scopes { get; } = new();
private ConcurrentBag<IDisposable> subscriptions = new();
private ConcurrentBag<ProducedDiagnosticScope> Scopes { get; } = new();

public static ConcurrentBag<Activity> CollectedActivities { private set; get; } = new();
private static ConcurrentBag<string> CollectedEvents { set; get; } = new();
Expand Down Expand Up @@ -75,7 +75,7 @@ public void OnNext(KeyValuePair<string, object> value)
string startSuffix = ".Start";
string stopSuffix = ".Stop";
string exceptionSuffix = ".Exception";

if (value.Key.EndsWith(startSuffix))
{
string name = value.Key[..^startSuffix.Length];
Expand Down Expand Up @@ -181,7 +181,7 @@ public override void Dispose()
return;
}

List<IDisposable> subscriptions;
ConcurrentBag<IDisposable> subscriptions;
lock (this.Scopes)
{
subscriptions = this.subscriptions;
Expand Down
Loading