diff --git a/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs b/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs index 464ca09ddf..6512ce8dd4 100644 --- a/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs +++ b/Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs @@ -111,7 +111,7 @@ public virtual Stream Content /// /// Gets the cosmos diagnostic information for the current request to Azure Cosmos DB service /// - public CosmosDiagnostics Diagnostics { get; set; } + public virtual CosmosDiagnostics Diagnostics { get; internal set; } /// /// Gets the internal error object. diff --git a/Microsoft.Azure.Cosmos/src/Query/CosmosDiagnosticsAggregate.cs b/Microsoft.Azure.Cosmos/src/Query/CosmosDiagnosticsAggregate.cs index 5b57660580..e4d04c1ce5 100644 --- a/Microsoft.Azure.Cosmos/src/Query/CosmosDiagnosticsAggregate.cs +++ b/Microsoft.Azure.Cosmos/src/Query/CosmosDiagnosticsAggregate.cs @@ -5,6 +5,7 @@ namespace Microsoft.Azure.Cosmos.Query { using System.Collections.Generic; + using System.Text; using Newtonsoft.Json; internal class CosmosDiagnosticsAggregate : CosmosDiagnostics @@ -13,7 +14,18 @@ internal class CosmosDiagnosticsAggregate : CosmosDiagnostics public override string ToString() { - return JsonConvert.SerializeObject(this); + if (this.Diagnostics.Count == 0) + { + return string.Empty; + } + + StringBuilder stringBuilder = new StringBuilder(); + foreach (CosmosDiagnostics diagnostics in this.Diagnostics) + { + stringBuilder.Append(diagnostics.ToString()); + } + + return stringBuilder.ToString(); } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerResponse.cs index 496d8189d9..7c6f034beb 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ContainerResponse.cs @@ -28,12 +28,14 @@ internal ContainerResponse( HttpStatusCode httpStatusCode, Headers headers, ContainerProperties containerProperties, - Container container) + Container container, + CosmosDiagnostics diagnostics) { this.StatusCode = httpStatusCode; this.Headers = headers; this.Resource = containerProperties; this.Container = container; + this.Diagnostics = diagnostics; } /// @@ -51,6 +53,9 @@ internal ContainerResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Resource/Container/ItemResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/Container/ItemResponse.cs index 8884de44ec..324a635562 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Container/ItemResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Container/ItemResponse.cs @@ -45,6 +45,9 @@ internal ItemResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Resource/CosmosException.cs b/Microsoft.Azure.Cosmos/src/Resource/CosmosException.cs index 804d5a84fe..6a642575b6 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/CosmosException.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/CosmosException.cs @@ -44,6 +44,7 @@ internal CosmosException( this.RequestCharge = this.Headers.RequestCharge; this.RetryAfter = this.Headers.RetryAfter; this.SubStatusCode = (int)this.Headers.SubStatusCode; + this.Diagnostics = cosmosResponseMessage.Diagnostics; if (this.Headers.ContentLengthAsLong > 0) { using (StreamReader responseReader = new StreamReader(cosmosResponseMessage.Content)) @@ -122,6 +123,11 @@ public CosmosException( /// public virtual Headers Headers { get; } + /// + /// Gets the diagnostics for the request + /// + public virtual CosmosDiagnostics Diagnostics { get; } + /// /// Gets the internal error object /// @@ -150,7 +156,8 @@ public virtual bool TryGetHeader(string headerName, out string value) /// A string representation of the exception. public override string ToString() { - return $"{nameof(CosmosException)};StatusCode={this.StatusCode};SubStatusCode={this.SubStatusCode};ActivityId={this.ActivityId ?? string.Empty};RequestCharge={this.RequestCharge};Message={this.Message};"; + string diagnostics = this.Diagnostics != null ? this.Diagnostics.ToString() : string.Empty; + return $"{nameof(CosmosException)};StatusCode={this.StatusCode};SubStatusCode={this.SubStatusCode};ActivityId={this.ActivityId ?? string.Empty};RequestCharge={this.RequestCharge};Message={this.Message};Diagnostics{diagnostics}"; } internal ResponseMessage ToCosmosResponseMessage(RequestMessage request) diff --git a/Microsoft.Azure.Cosmos/src/Resource/CosmosResponseFactory.cs b/Microsoft.Azure.Cosmos/src/Resource/CosmosResponseFactory.cs index bfeeda43a9..34a565bb76 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/CosmosResponseFactory.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/CosmosResponseFactory.cs @@ -93,7 +93,8 @@ internal Task CreateContainerResponseAsync( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, containerProperties, - container); + container, + cosmosResponseMessage.Diagnostics); }); } @@ -108,7 +109,8 @@ internal Task CreateUserResponseAsync( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, userProperties, - user); + user, + cosmosResponseMessage.Diagnostics); }); } @@ -123,7 +125,8 @@ internal Task CreatePermissionResponseAsync( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, permissionProperties, - permission); + permission, + cosmosResponseMessage.Diagnostics); }); } @@ -141,7 +144,8 @@ internal Task CreateDatabaseResponseAsync( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, databaseProperties, - database); + database, + cosmosResponseMessage.Diagnostics); }); } @@ -154,7 +158,8 @@ internal Task CreateThroughputResponseAsync( return new ThroughputResponse( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, - throughputProperties); + throughputProperties, + cosmosResponseMessage.Diagnostics); }); } @@ -166,7 +171,8 @@ internal Task> CreateStoredProcedureExecuteRes return new StoredProcedureExecuteResponse( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, - item); + item, + cosmosResponseMessage.Diagnostics); }); } @@ -178,7 +184,8 @@ internal Task CreateStoredProcedureResponseAsync(Task CreateTriggerResponseAsync(Task return new TriggerResponse( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, - triggerProperties); + triggerProperties, + cosmosResponseMessage.Diagnostics); }); } @@ -202,7 +210,8 @@ internal Task CreateUserDefinedFunctionResponseAsyn return new UserDefinedFunctionResponse( cosmosResponseMessage.StatusCode, cosmosResponseMessage.Headers, - settings); + settings, + cosmosResponseMessage.Diagnostics); }); } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseResponse.cs index cbfbfabe76..48b24c1322 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseResponse.cs @@ -28,12 +28,14 @@ internal DatabaseResponse( HttpStatusCode httpStatusCode, Headers headers, DatabaseProperties databaseProperties, - Database database) + Database database, + CosmosDiagnostics diagnostics) { this.StatusCode = httpStatusCode; this.Headers = headers; this.Resource = databaseProperties; this.Database = database; + this.Diagnostics = diagnostics; } /// @@ -51,6 +53,9 @@ internal DatabaseResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Resource/Offer/CosmosOffers.cs b/Microsoft.Azure.Cosmos/src/Resource/Offer/CosmosOffers.cs index b8f28789dd..ec7e44eefe 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Offer/CosmosOffers.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Offer/CosmosOffers.cs @@ -52,7 +52,8 @@ internal async Task ReadThroughputIfExistsAsync( return new ThroughputResponse( HttpStatusCode.NotFound, headers: null, - throughputProperties: null); + throughputProperties: null, + diagnostics: null); } return await this.GetThroughputResponseAsync( @@ -107,7 +108,8 @@ internal async Task ReplaceThroughputIfExistsAsync( return new ThroughputResponse( responseMessage.StatusCode, headers: responseMessage.Headers, - throughputProperties: null); + throughputProperties: null, + diagnostics: responseMessage.Diagnostics); } catch (AggregateException ex) { @@ -115,7 +117,8 @@ internal async Task ReplaceThroughputIfExistsAsync( return new ThroughputResponse( responseMessage.StatusCode, headers: responseMessage.Headers, - throughputProperties: null); + throughputProperties: null, + diagnostics: responseMessage.Diagnostics); } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionResponse.cs index 73935a43c0..cf4b75cde7 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Permission/PermissionResponse.cs @@ -28,12 +28,14 @@ internal PermissionResponse( HttpStatusCode httpStatusCode, Headers headers, PermissionProperties permissionProperties, - Permission permission) + Permission permission, + CosmosDiagnostics diagnostics) { this.StatusCode = httpStatusCode; this.Headers = headers; this.Resource = permissionProperties; this.Permission = permission; + this.Diagnostics = diagnostics; } /// @@ -51,6 +53,9 @@ internal PermissionResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/QueryResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/QueryResponse.cs index 8a42bdf959..5366c4850b 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/QueryResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/QueryResponse.cs @@ -172,6 +172,8 @@ private QueryResponse( public override HttpStatusCode StatusCode { get; } + public override CosmosDiagnostics Diagnostics { get; } + public override int Count => this.cosmosElements?.Count() ?? 0; internal CosmosQueryResponseMessageHeaders QueryHeaders { get; } diff --git a/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/ReadFeedResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/ReadFeedResponse.cs index a2651c49d2..4f68ba2754 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/ReadFeedResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/QueryResponses/ReadFeedResponse.cs @@ -11,12 +11,14 @@ internal class ReadFeedResponse : FeedResponse protected ReadFeedResponse( HttpStatusCode httpStatusCode, ICollection resource, - Headers responseMessageHeaders) + Headers responseMessageHeaders, + CosmosDiagnostics diagnostics) { this.Count = resource.Count; this.Headers = responseMessageHeaders; this.Resource = resource; this.StatusCode = httpStatusCode; + this.Diagnostics = diagnostics; } public override int Count { get; } @@ -29,6 +31,8 @@ protected ReadFeedResponse( public override HttpStatusCode StatusCode { get; } + public override CosmosDiagnostics Diagnostics { get; } + public override IEnumerator GetEnumerator() { return this.Resource.GetEnumerator(); @@ -50,7 +54,8 @@ internal static ReadFeedResponse CreateResponse( ReadFeedResponse readFeedResponse = new ReadFeedResponse( httpStatusCode: responseMessage.StatusCode, resource: resources, - responseMessageHeaders: responseMessage.Headers); + responseMessageHeaders: responseMessage.Headers, + diagnostics: responseMessage.Diagnostics); return readFeedResponse; } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Response.cs b/Microsoft.Azure.Cosmos/src/Resource/Response.cs index d0959b01d0..af2ccc5937 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Response.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Response.cs @@ -66,7 +66,7 @@ public static implicit operator T(Response response) /// /// Gets the cosmos diagnostics information for the current request to Azure Cosmos DB service /// - public CosmosDiagnostics Diagnostics { get; set; } + public abstract CosmosDiagnostics Diagnostics { get; } /// /// Gets the maximum size limit for this entity from the Azure Cosmos DB service. diff --git a/Microsoft.Azure.Cosmos/src/Resource/Scripts/StoredProcedureExecuteResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/Scripts/StoredProcedureExecuteResponse.cs index 3b37358016..a87db20786 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Scripts/StoredProcedureExecuteResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Scripts/StoredProcedureExecuteResponse.cs @@ -26,13 +26,15 @@ protected StoredProcedureExecuteResponse() /// This will prevent memory leaks when handling the HttpResponseMessage /// internal StoredProcedureExecuteResponse( - HttpStatusCode httpStatusCode, - Headers headers, - T response) + HttpStatusCode httpStatusCode, + Headers headers, + T response, + CosmosDiagnostics diagnostics) { this.StatusCode = httpStatusCode; this.Headers = headers; this.Resource = response; + this.Diagnostics = diagnostics; } /// @@ -44,6 +46,9 @@ internal StoredProcedureExecuteResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Resource/Scripts/StoredProcedureResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/Scripts/StoredProcedureResponse.cs index 15827f8cd0..0cdcb0f095 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Scripts/StoredProcedureResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Scripts/StoredProcedureResponse.cs @@ -25,13 +25,15 @@ protected StoredProcedureResponse() /// This will prevent memory leaks when handling the HttpResponseMessage /// internal StoredProcedureResponse( - HttpStatusCode httpStatusCode, - Headers headers, - StoredProcedureProperties storedProcedureProperties) + HttpStatusCode httpStatusCode, + Headers headers, + StoredProcedureProperties storedProcedureProperties, + CosmosDiagnostics diagnostics) { this.StatusCode = httpStatusCode; this.Headers = headers; this.Resource = storedProcedureProperties; + this.Diagnostics = diagnostics; } /// @@ -43,6 +45,9 @@ internal StoredProcedureResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Resource/Scripts/TriggerResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/Scripts/TriggerResponse.cs index d189cad144..88439455c3 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Scripts/TriggerResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Scripts/TriggerResponse.cs @@ -25,13 +25,15 @@ protected TriggerResponse() /// This will prevent memory leaks when handling the HttpResponseMessage /// internal TriggerResponse( - HttpStatusCode httpStatusCode, - Headers headers, - TriggerProperties triggerProperties) + HttpStatusCode httpStatusCode, + Headers headers, + TriggerProperties triggerProperties, + CosmosDiagnostics diagnostics) { this.StatusCode = httpStatusCode; this.Headers = headers; this.Resource = triggerProperties; + this.Diagnostics = diagnostics; } /// @@ -43,6 +45,9 @@ internal TriggerResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Resource/Scripts/UserDefinedFunctionResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/Scripts/UserDefinedFunctionResponse.cs index b8196ff47e..739c61e9bc 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Scripts/UserDefinedFunctionResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Scripts/UserDefinedFunctionResponse.cs @@ -25,13 +25,15 @@ protected UserDefinedFunctionResponse() /// This will prevent memory leaks when handling the HttpResponseMessage /// internal UserDefinedFunctionResponse( - HttpStatusCode httpStatusCode, - Headers headers, - UserDefinedFunctionProperties userDefinedFunctionProperties) + HttpStatusCode httpStatusCode, + Headers headers, + UserDefinedFunctionProperties userDefinedFunctionProperties, + CosmosDiagnostics diagnostics) { this.StatusCode = httpStatusCode; this.Headers = headers; this.Resource = userDefinedFunctionProperties; + this.Diagnostics = diagnostics; } /// @@ -43,6 +45,9 @@ internal UserDefinedFunctionResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/PointOperationStatistics.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/PointOperationStatistics.cs index d2c7c3ca23..a3f6daa61f 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/PointOperationStatistics.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/PointOperationStatistics.cs @@ -6,11 +6,25 @@ namespace Microsoft.Azure.Cosmos { using System; using System.Collections.Generic; + using System.Net; + using System.Net.Http; using Newtonsoft.Json; using static Microsoft.Azure.Cosmos.CosmosClientSideRequestStatistics; internal class PointOperationStatistics : CosmosDiagnostics { + private static JsonSerializerSettings SerializerSettings = new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore, + Formatting = Formatting.None + }; + public HttpStatusCode StatusCode { get; } + public Documents.SubStatusCodes SubStatusCode { get; } + public double RequestCharge { get; } + public string ErrorMessage { get; } + public HttpMethod Method { get; } + public Uri RequestUri { get; } + public DateTime requestStartTime { get; private set; } public DateTime requestEndTime { get; private set; } @@ -21,25 +35,41 @@ internal class PointOperationStatistics : CosmosDiagnostics public Dictionary addressResolutionStatistics { get; private set; } - internal List contactedReplicas { get; set; } + public List contactedReplicas { get; set; } - internal HashSet failedReplicas { get; private set; } + public HashSet failedReplicas { get; private set; } public HashSet regionsContacted { get; private set; } public TimeSpan requestLatency { get; private set; } - public PointOperationStatistics(CosmosClientSideRequestStatistics clientSideRequestStatistics) + internal PointOperationStatistics( + HttpStatusCode statusCode, + Documents.SubStatusCodes subStatusCode, + double requestCharge, + string errorMessage, + HttpMethod method, + Uri requestUri, + CosmosClientSideRequestStatistics clientSideRequestStatistics) { - this.requestStartTime = clientSideRequestStatistics.requestStartTime; - this.requestEndTime = clientSideRequestStatistics.requestEndTime; - this.responseStatisticsList = clientSideRequestStatistics.responseStatisticsList; - this.supplementalResponseStatisticsList = clientSideRequestStatistics.supplementalResponseStatisticsList; - this.addressResolutionStatistics = clientSideRequestStatistics.addressResolutionStatistics; - this.contactedReplicas = clientSideRequestStatistics.ContactedReplicas; - this.failedReplicas = clientSideRequestStatistics.FailedReplicas; - this.regionsContacted = clientSideRequestStatistics.RegionsContacted; - this.requestLatency = clientSideRequestStatistics.RequestLatency; + this.StatusCode = statusCode; + this.SubStatusCode = subStatusCode; + this.RequestCharge = requestCharge; + this.ErrorMessage = errorMessage; + this.Method = method; + this.RequestUri = requestUri; + if (clientSideRequestStatistics != null) + { + this.requestStartTime = clientSideRequestStatistics.requestStartTime; + this.requestEndTime = clientSideRequestStatistics.requestEndTime; + this.responseStatisticsList = clientSideRequestStatistics.responseStatisticsList; + this.supplementalResponseStatisticsList = clientSideRequestStatistics.supplementalResponseStatisticsList; + this.addressResolutionStatistics = clientSideRequestStatistics.addressResolutionStatistics; + this.contactedReplicas = clientSideRequestStatistics.ContactedReplicas; + this.failedReplicas = clientSideRequestStatistics.FailedReplicas; + this.regionsContacted = clientSideRequestStatistics.RegionsContacted; + this.requestLatency = clientSideRequestStatistics.RequestLatency; + } } public override string ToString() @@ -53,7 +83,7 @@ public override string ToString() this.supplementalResponseStatisticsList.RemoveRange(0, countToRemove); } } - return JsonConvert.SerializeObject(this); + return JsonConvert.SerializeObject(this, PointOperationStatistics.SerializerSettings); } } } diff --git a/Microsoft.Azure.Cosmos/src/Resource/Throughput/ThroughputResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/Throughput/ThroughputResponse.cs index 3c34d048aa..c28157026f 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Throughput/ThroughputResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Throughput/ThroughputResponse.cs @@ -28,11 +28,13 @@ protected ThroughputResponse() internal ThroughputResponse( HttpStatusCode httpStatusCode, Headers headers, - ThroughputProperties throughputProperties) + ThroughputProperties throughputProperties, + CosmosDiagnostics diagnostics) { this.StatusCode = httpStatusCode; this.Headers = headers; this.Resource = throughputProperties; + this.Diagnostics = diagnostics; } /// @@ -44,6 +46,9 @@ internal ThroughputResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Resource/User/UserResponse.cs b/Microsoft.Azure.Cosmos/src/Resource/User/UserResponse.cs index 276e2cf60a..49bab4e75c 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/User/UserResponse.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/User/UserResponse.cs @@ -28,12 +28,14 @@ internal UserResponse( HttpStatusCode httpStatusCode, Headers headers, UserProperties userProperties, - User user) + User user, + CosmosDiagnostics diagnostics) { this.StatusCode = httpStatusCode; this.Headers = headers; this.Resource = userProperties; this.User = user; + this.Diagnostics = diagnostics; } /// @@ -51,6 +53,9 @@ internal UserResponse( /// public override HttpStatusCode StatusCode { get; } + /// + public override CosmosDiagnostics Diagnostics { get; } + /// public override double RequestCharge => this.Headers?.RequestCharge ?? 0; diff --git a/Microsoft.Azure.Cosmos/src/Util/Extensions.cs b/Microsoft.Azure.Cosmos/src/Util/Extensions.cs index 31fecd8eea..983e970f48 100644 --- a/Microsoft.Azure.Cosmos/src/Util/Extensions.cs +++ b/Microsoft.Azure.Cosmos/src/Util/Extensions.cs @@ -36,14 +36,15 @@ internal static ResponseMessage ToCosmosResponseMessage(this DocumentServiceResp } } - if (response.RequestStats != null) - { - CosmosClientSideRequestStatistics cosmosClientSideRequestStatistics = response.RequestStats as CosmosClientSideRequestStatistics; - if (cosmosClientSideRequestStatistics != null) - { - cosmosResponse.Diagnostics = new PointOperationStatistics(cosmosClientSideRequestStatistics); - } - } + CosmosClientSideRequestStatistics cosmosClientSideRequestStatistics = response.RequestStats as CosmosClientSideRequestStatistics; + cosmosResponse.Diagnostics = new PointOperationStatistics( + statusCode: response.StatusCode, + subStatusCode: response.SubStatusCode, + requestCharge: cosmosResponse.Headers.RequestCharge, + errorMessage: cosmosResponse.ErrorMessage, + method: requestMessage?.Method, + requestUri: requestMessage?.RequestUri, + clientSideRequestStatistics: cosmosClientSideRequestStatistics); return cosmosResponse; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs index 14d6c4b73a..535f3d15f2 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosContainerTests.cs @@ -108,7 +108,6 @@ public async Task ContainerBuilderContractTest() this.ValidateCreateContainerResponseContract(response); } - [Ignore] [TestMethod] public async Task PartitionedCRUDTest() { @@ -120,6 +119,10 @@ public async Task PartitionedCRUDTest() Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode); Assert.AreEqual(containerName, containerResponse.Resource.Id); Assert.AreEqual(partitionKeyPath, containerResponse.Resource.PartitionKey.Paths.First()); + Assert.IsNotNull(containerResponse.Diagnostics); + string diagnostics = containerResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); ContainerProperties settings = new ContainerProperties(containerName, partitionKeyPath) { @@ -137,14 +140,22 @@ public async Task PartitionedCRUDTest() Assert.AreEqual(partitionKeyPath, containerResponse.Resource.PartitionKey.Paths.First()); Assert.AreEqual(Cosmos.IndexingMode.None, containerResponse.Resource.IndexingPolicy.IndexingMode); Assert.IsFalse(containerResponse.Resource.IndexingPolicy.Automatic); + Assert.IsNotNull(containerResponse.Diagnostics); + diagnostics = containerResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); containerResponse = await container.ReadContainerAsync(); Assert.AreEqual(HttpStatusCode.OK, containerResponse.StatusCode); Assert.AreEqual(containerName, containerResponse.Resource.Id); - Assert.AreEqual(Cosmos.PartitionKeyDefinitionVersion.V2, containerResponse.Resource.PartitionKeyDefinitionVersion); + //Assert.AreEqual(Cosmos.PartitionKeyDefinitionVersion.V2, containerResponse.Resource.PartitionKeyDefinitionVersion); Assert.AreEqual(partitionKeyPath, containerResponse.Resource.PartitionKey.Paths.First()); Assert.AreEqual(Cosmos.IndexingMode.None, containerResponse.Resource.IndexingPolicy.IndexingMode); Assert.IsFalse(containerResponse.Resource.IndexingPolicy.Automatic); + Assert.IsNotNull(containerResponse.Diagnostics); + diagnostics = containerResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); containerResponse = await containerResponse.Container.DeleteContainerAsync(); Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDatabaseTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDatabaseTests.cs index b3174e3aa5..0430a5ab5a 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDatabaseTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDatabaseTests.cs @@ -72,9 +72,17 @@ public async Task CreateDropDatabase() { DatabaseResponse response = await this.CreateDatabaseHelper(); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); + Assert.IsNotNull(response.Diagnostics); + string diagnostics = response.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); response = await response.Database.DeleteAsync(cancellationToken: this.cancellationToken); Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode); + Assert.IsNotNull(response.Diagnostics); + diagnostics = response.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); } [TestMethod] @@ -199,6 +207,10 @@ public async Task CreateIfNotExists() createResponse = await this.CreateDatabaseHelper(createResponse.Resource.Id, databaseExists: true); Assert.AreEqual(HttpStatusCode.OK, createResponse.StatusCode); + Assert.IsNotNull(createResponse.Diagnostics); + string diagnostics = createResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("requestStartTime")); } [TestMethod] diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDiagnosticsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDiagnosticsTests.cs index 74af580587..9652e3faa8 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDiagnosticsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/CosmosDiagnosticsTests.cs @@ -148,5 +148,18 @@ public async Task QueryOperationDiagnostic() Assert.IsTrue(((QueryOperationStatistics)responseMessage.Diagnostics).queryMetrics.Values.First().OutputDocumentCount > 0); } } + + [TestMethod] + public async Task NonDataPlaneDiagnosticTest() + { + DatabaseResponse databaseResponse = await this.cosmosClient.CreateDatabaseAsync(Guid.NewGuid().ToString()); + Assert.IsNotNull(databaseResponse.Diagnostics); + string diagnostics = databaseResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); + Assert.IsTrue(diagnostics.Contains("SubStatusCode")); + Assert.IsTrue(diagnostics.Contains("RequestUri")); + Assert.IsTrue(diagnostics.Contains("Method")); + } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/StoredProcedureTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/StoredProcedureTests.cs index 52df197c23..2b61f7fbc5 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/StoredProcedureTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/StoredProcedureTests.cs @@ -71,12 +71,21 @@ public async Task CRUDTest() double requestCharge = storedProcedureResponse.RequestCharge; Assert.IsTrue(requestCharge > 0); Assert.AreEqual(HttpStatusCode.Created, storedProcedureResponse.StatusCode); + Assert.IsNotNull(storedProcedureResponse.Diagnostics); + string diagnostics = storedProcedureResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); + StoredProcedureTests.ValidateStoredProcedureSettings(sprocId, sprocBody, storedProcedureResponse); storedProcedureResponse = await this.scripts.ReadStoredProcedureAsync(sprocId); requestCharge = storedProcedureResponse.RequestCharge; Assert.IsTrue(requestCharge > 0); Assert.AreEqual(HttpStatusCode.OK, storedProcedureResponse.StatusCode); + Assert.IsNotNull(storedProcedureResponse.Diagnostics); + diagnostics = storedProcedureResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); StoredProcedureTests.ValidateStoredProcedureSettings(sprocId, sprocBody, storedProcedureResponse); string updatedBody = @"function(name) { var context = getContext(); @@ -88,6 +97,10 @@ public async Task CRUDTest() requestCharge = replaceResponse.RequestCharge; Assert.IsTrue(requestCharge > 0); Assert.AreEqual(HttpStatusCode.OK, replaceResponse.StatusCode); + Assert.IsNotNull(replaceResponse.Diagnostics); + diagnostics = replaceResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); StoredProcedureTests.ValidateStoredProcedureSettings(sprocId, updatedBody, replaceResponse); @@ -95,6 +108,10 @@ public async Task CRUDTest() requestCharge = deleteResponse.RequestCharge; Assert.IsTrue(requestCharge > 0); Assert.AreEqual(HttpStatusCode.NoContent, deleteResponse.StatusCode); + Assert.IsNotNull(deleteResponse.Diagnostics); + diagnostics = deleteResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); } [TestMethod] diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/TriggersTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/TriggersTests.cs index b17c36450f..5531ba2341 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/TriggersTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/TriggersTests.cs @@ -56,12 +56,20 @@ public async Task CRUDTest() double reqeustCharge = triggerResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.Created, triggerResponse.StatusCode); + Assert.IsNotNull(triggerResponse.Diagnostics); + string diagnostics = triggerResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); TriggersTests.ValidateTriggerSettings(settings, triggerResponse); triggerResponse = await this.scripts.ReadTriggerAsync(settings.Id); reqeustCharge = triggerResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.OK, triggerResponse.StatusCode); + Assert.IsNotNull(triggerResponse.Diagnostics); + diagnostics = triggerResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); TriggersTests.ValidateTriggerSettings(settings, triggerResponse); TriggerProperties updatedSettings = triggerResponse.Resource; @@ -72,11 +80,19 @@ public async Task CRUDTest() reqeustCharge = replaceResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.OK, replaceResponse.StatusCode); + Assert.IsNotNull(replaceResponse.Diagnostics); + diagnostics = replaceResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); replaceResponse = await this.scripts.DeleteTriggerAsync(updatedSettings.Id); reqeustCharge = replaceResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.NoContent, replaceResponse.StatusCode); + Assert.IsNotNull(replaceResponse.Diagnostics); + diagnostics = replaceResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); } [TestMethod] diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserDefinedFunctionsTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserDefinedFunctionsTests.cs index 88dc2b4c3c..8839085b37 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserDefinedFunctionsTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/UserDefinedFunctionsTests.cs @@ -54,12 +54,20 @@ public async Task CRUDTest() double reqeustCharge = response.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); + Assert.IsNotNull(response.Diagnostics); + string diagnostics = response.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); UserDefinedFunctionsTests.ValidateUserDefinedFunctionSettings(settings, response); response = await this.scripts.ReadUserDefinedFunctionAsync(settings.Id); reqeustCharge = response.RequestCharge; Assert.IsTrue(reqeustCharge > 0); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + Assert.IsNotNull(response.Diagnostics); + diagnostics = response.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); UserDefinedFunctionsTests.ValidateUserDefinedFunctionSettings(settings, response); UserDefinedFunctionProperties updatedSettings = response.Resource; @@ -69,11 +77,19 @@ public async Task CRUDTest() UserDefinedFunctionsTests.ValidateUserDefinedFunctionSettings(updatedSettings, replaceResponse); reqeustCharge = replaceResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); + Assert.IsNotNull(replaceResponse.Diagnostics); + diagnostics = replaceResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); Assert.AreEqual(HttpStatusCode.OK, replaceResponse.StatusCode); replaceResponse = await this.scripts.DeleteUserDefinedFunctionAsync(settings.Id); reqeustCharge = replaceResponse.RequestCharge; Assert.IsTrue(reqeustCharge > 0); + Assert.IsNotNull(replaceResponse.Diagnostics); + diagnostics = replaceResponse.Diagnostics.ToString(); + Assert.IsFalse(string.IsNullOrEmpty(diagnostics)); + Assert.IsTrue(diagnostics.Contains("StatusCode")); Assert.AreEqual(HttpStatusCode.NoContent, replaceResponse.StatusCode); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json index 70ab101380..3531cd2c67 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/DotNetSDKAPI.json @@ -1078,6 +1078,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -1537,6 +1549,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -1921,6 +1945,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Database Database": { "Type": "Property", "Attributes": [], @@ -2980,6 +3016,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -3537,6 +3585,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -4624,11 +4684,9 @@ "Attributes": [], "MethodInfo": null }, - "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()": { "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], + "Attributes": [], "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" }, "Microsoft.Azure.Cosmos.Headers get_Headers()": { @@ -4685,13 +4743,6 @@ "Type": "Property", "Attributes": [], "MethodInfo": null - }, - "Void set_Diagnostics(Microsoft.Azure.Cosmos.CosmosDiagnostics)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Void set_Diagnostics(Microsoft.Azure.Cosmos.CosmosDiagnostics)" } }, "NestedTypes": {} @@ -4813,13 +4864,6 @@ "Type": "Method", "Attributes": [], "MethodInfo": "Void set_Content(System.IO.Stream)" - }, - "Void set_Diagnostics(Microsoft.Azure.Cosmos.CosmosDiagnostics)[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { - "Type": "Method", - "Attributes": [ - "CompilerGeneratedAttribute" - ], - "MethodInfo": "Void set_Diagnostics(Microsoft.Azure.Cosmos.CosmosDiagnostics)" } }, "NestedTypes": {} @@ -4973,6 +5017,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -5208,6 +5264,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -5442,6 +5510,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -5607,6 +5687,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -6834,6 +6926,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ @@ -7094,6 +7198,18 @@ "Attributes": [], "MethodInfo": null }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics Diagnostics": { + "Type": "Property", + "Attributes": [], + "MethodInfo": null + }, + "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { + "Type": "Method", + "Attributes": [ + "CompilerGeneratedAttribute" + ], + "MethodInfo": "Microsoft.Azure.Cosmos.CosmosDiagnostics get_Diagnostics()" + }, "Microsoft.Azure.Cosmos.Headers get_Headers()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": { "Type": "Method", "Attributes": [ diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PointOperationStatisticsTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PointOperationStatisticsTest.cs index 3c4422abb7..0128898996 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PointOperationStatisticsTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PointOperationStatisticsTest.cs @@ -5,6 +5,7 @@ namespace Microsoft.Azure.Cosmos { using System.Collections.Generic; + using System.Net.Http; using Microsoft.VisualStudio.TestTools.UnitTesting; using static Microsoft.Azure.Cosmos.CosmosClientSideRequestStatistics; @@ -18,7 +19,15 @@ public void ToStringTest() CosmosClientSideRequestStatistics cosmosClientSideRequestStatistics = new CosmosClientSideRequestStatistics(); //Setting null supplementalResponseStatisticsList cosmosClientSideRequestStatistics.supplementalResponseStatisticsList = null; - PointOperationStatistics pointOperationStatistics = new PointOperationStatistics(cosmosClientSideRequestStatistics); + PointOperationStatistics pointOperationStatistics = new PointOperationStatistics( + statusCode: System.Net.HttpStatusCode.OK, + subStatusCode: Documents.SubStatusCodes.Unknown, + requestCharge: 42, + errorMessage: null, + method: HttpMethod.Get, + requestUri: new System.Uri("https://localhost:8081"), + clientSideRequestStatistics: cosmosClientSideRequestStatistics); + pointOperationStatistics.ToString(); Assert.IsNull(pointOperationStatistics.supplementalResponseStatisticsList); @@ -32,7 +41,14 @@ public void ToStringTest() new StoreResponseStatistics() }; - pointOperationStatistics = new PointOperationStatistics(cosmosClientSideRequestStatistics); + pointOperationStatistics = new PointOperationStatistics( + statusCode: System.Net.HttpStatusCode.OK, + subStatusCode: Documents.SubStatusCodes.Unknown, + requestCharge: 42, + errorMessage: null, + method: HttpMethod.Get, + requestUri: new System.Uri("https://localhost:8081"), + clientSideRequestStatistics: cosmosClientSideRequestStatistics); pointOperationStatistics.ToString(); Assert.AreEqual(5, pointOperationStatistics.supplementalResponseStatisticsList.Count); @@ -46,7 +62,14 @@ public void ToStringTest() new StoreResponseStatistics() }); - pointOperationStatistics = new PointOperationStatistics(cosmosClientSideRequestStatistics); + pointOperationStatistics = new PointOperationStatistics( + statusCode: System.Net.HttpStatusCode.OK, + subStatusCode: Documents.SubStatusCodes.Unknown, + requestCharge: 42, + errorMessage: null, + method: HttpMethod.Get, + requestUri: new System.Uri("https://localhost:8081"), + clientSideRequestStatistics: cosmosClientSideRequestStatistics); pointOperationStatistics.ToString(); Assert.AreEqual(10, pointOperationStatistics.supplementalResponseStatisticsList.Count); @@ -57,7 +80,14 @@ public void ToStringTest() new StoreResponseStatistics() }); - pointOperationStatistics = new PointOperationStatistics(cosmosClientSideRequestStatistics); + pointOperationStatistics = new PointOperationStatistics( + statusCode: System.Net.HttpStatusCode.OK, + subStatusCode: Documents.SubStatusCodes.Unknown, + requestCharge: 42, + errorMessage: null, + method: HttpMethod.Get, + requestUri: new System.Uri("https://localhost:8081"), + clientSideRequestStatistics: cosmosClientSideRequestStatistics); pointOperationStatistics.ToString(); Assert.AreEqual(10, pointOperationStatistics.supplementalResponseStatisticsList.Count); } diff --git a/changelog.md b/changelog.md index 8400b94627..9d43693b80 100644 --- a/changelog.md +++ b/changelog.md @@ -8,12 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - [#100](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/100) Configurable Tcp settings to CosmosClientOptions -- [#615](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/615) Added request diagnostics to Response's +- [#615](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/615), [#775](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/775) Added request diagnostics to Response's - [#622](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/622) Added CRUD and query operations for Users and Permissions which enables [ResourceToken](https://docs.microsoft.com/en-us/azure/cosmos-db/secure-access-to-data#resource-tokens) support - [#716](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/716) Added camel case serialization on LINQ query generation -- [#729](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/729) Added aggregate(CountAsync/SumAsync etc.) extensions for LINQ query +- [#729](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/729), [#776](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/776) Added aggregate(CountAsync/SumAsync etc.) extensions for LINQ query - [#743](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/743) Added WebProxy to CosmosClientOptions -- [#776](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/776) Converted all aggregate linq queries to return Response to allow access to request charge and diagnostics - [#767](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/767) Ability to limit to configured application region only ### Fixed