From 85cfe4d2ecb5fb541c8df6472cf751f34a614108 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Fri, 26 Jul 2019 10:44:27 -0700 Subject: [PATCH] Instrument KeyVault libraries with distributed tracing. (#7019) --- .../src/KeyClient.cs | 379 ++++++++++++++++-- .../src/KeyClient_private.cs | 74 ++-- .../tests/KeyClientLiveTests.cs | 1 - .../src/SecretClient.cs | 309 ++++++++++++-- .../tests/SecretClientLiveTests.cs | 1 - 5 files changed, 661 insertions(+), 103 deletions(-) diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs index 2f6b3856838f1..680dec71f0c5c 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient.cs @@ -76,7 +76,19 @@ public virtual Response CreateKey(string name, KeyType keyType, KeyCreateOp var parameters = new KeyRequestParameters(keyType, keyOptions); - return SendRequest(RequestMethod.Post, parameters, () => new Key(name), cancellationToken, KeysPath, name, "/create"); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.CreateKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Post, parameters, () => new Key(name), cancellationToken, KeysPath, name, "/create"); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -98,7 +110,19 @@ public virtual async Task> CreateKeyAsync(string name, KeyType key var parameters = new KeyRequestParameters(keyType, keyOptions); - return await SendRequestAsync(RequestMethod.Post, parameters, () => new Key(name), cancellationToken, KeysPath, name, "/create").ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.CreateKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Post, parameters, () => new Key(name), cancellationToken, KeysPath, name, "/create").ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -116,7 +140,19 @@ public virtual Response CreateEcKey(EcKeyCreateOptions ecKey, CancellationT var parameters = new KeyRequestParameters(ecKey); - return SendRequest(RequestMethod.Post, parameters, () => new Key(ecKey.Name), cancellationToken, KeysPath, ecKey.Name, "/create"); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.CreateEcKey"); + scope.AddAttribute("key", ecKey.Name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Post, parameters, () => new Key(ecKey.Name), cancellationToken, KeysPath, ecKey.Name, "/create"); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -134,7 +170,19 @@ public virtual async Task> CreateEcKeyAsync(EcKeyCreateOptions ecK var parameters = new KeyRequestParameters(ecKey); - return await SendRequestAsync(RequestMethod.Post, parameters, () => new Key(ecKey.Name), cancellationToken, KeysPath, ecKey.Name, "/create").ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.CreateEcKey"); + scope.AddAttribute("key", ecKey.Name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Post, parameters, () => new Key(ecKey.Name), cancellationToken, KeysPath, ecKey.Name, "/create").ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -152,7 +200,19 @@ public virtual Response CreateRsaKey(RsaKeyCreateOptions rsaKey, Cancellati var parameters = new KeyRequestParameters(rsaKey); - return SendRequest(RequestMethod.Post, parameters, () => new Key(rsaKey.Name), cancellationToken, KeysPath, rsaKey.Name, "/create"); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.CreateRsaKey"); + scope.AddAttribute("key", rsaKey.Name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Post, parameters, () => new Key(rsaKey.Name), cancellationToken, KeysPath, rsaKey.Name, "/create"); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -170,7 +230,19 @@ public virtual async Task> CreateRsaKeyAsync(RsaKeyCreateOptions r var parameters = new KeyRequestParameters(rsaKey); - return await SendRequestAsync(RequestMethod.Post, parameters, () => new Key(rsaKey.Name), cancellationToken, KeysPath, rsaKey.Name, "/create").ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.CreateRsaKey"); + scope.AddAttribute("key", rsaKey.Name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Post, parameters, () => new Key(rsaKey.Name), cancellationToken, KeysPath, rsaKey.Name, "/create").ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -193,7 +265,19 @@ public virtual Response UpdateKey(KeyBase key, IEnumerable k var parameters = new KeyRequestParameters(key, keyOperations); - return SendRequest(RequestMethod.Patch, parameters, () => new Key(key.Name), cancellationToken, KeysPath, key.Name, "/", key.Version); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.UpdateKey"); + scope.AddAttribute("key", key.Name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Patch, parameters, () => new Key(key.Name), cancellationToken, KeysPath, key.Name, "/", key.Version); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -216,7 +300,19 @@ public virtual async Task> UpdateKeyAsync(KeyBase key, IEnumerable var parameters = new KeyRequestParameters(key, keyOperations); - return await SendRequestAsync(RequestMethod.Patch, parameters, () => new Key(key.Name), cancellationToken, KeysPath, key.Name, "/", key.Version).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.UpdateKey"); + scope.AddAttribute("key", key.Name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Patch, parameters, () => new Key(key.Name), cancellationToken, KeysPath, key.Name, "/", key.Version).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -234,7 +330,19 @@ public virtual Response GetKey(string name, string version = null, Cancella { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return SendRequest(RequestMethod.Get, () => new Key(name), cancellationToken, KeysPath, name, "/", version); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.GetKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Get, () => new Key(name), cancellationToken, KeysPath, name, "/", version); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -252,7 +360,19 @@ public virtual async Task> GetKeyAsync(string name, string version { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return await SendRequestAsync(RequestMethod.Get, () => new Key(name), cancellationToken, KeysPath, name, "/", version).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.GetKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Get, () => new Key(name), cancellationToken, KeysPath, name, "/", version).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -270,7 +390,7 @@ public virtual IEnumerable> GetKeys(CancellationToken cancella { Uri firstPageUri = CreateFirstPageUri(KeysPath); - return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new KeyBase(), cancellationToken)); + return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new KeyBase(), "Azure.Security.KeyVault.Keys.KeyClient.GetKeys", cancellationToken)); } /// @@ -288,7 +408,7 @@ public virtual IAsyncEnumerable> GetKeysAsync(CancellationToke { Uri firstPageUri = CreateFirstPageUri(KeysPath); - return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new KeyBase(), cancellationToken)); + return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new KeyBase(), "Azure.Security.KeyVault.Keys.KeyClient.GetKeys", cancellationToken)); } /// @@ -306,7 +426,7 @@ public virtual IEnumerable> GetKeyVersions(string name, Cancel Uri firstPageUri = CreateFirstPageUri($"{KeysPath}{name}/versions"); - return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new KeyBase(), cancellationToken)); + return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new KeyBase(), "Azure.Security.KeyVault.Keys.KeyClient.GetKeyVersions", cancellationToken)); } /// @@ -324,7 +444,7 @@ public virtual IAsyncEnumerable> GetKeyVersionsAsync(string na Uri firstPageUri = CreateFirstPageUri($"{KeysPath}{name}/versions"); - return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new KeyBase(), cancellationToken)); + return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new KeyBase(), "Azure.Security.KeyVault.Keys.KeyClient.GetKeyVersions", cancellationToken)); } /// @@ -342,7 +462,19 @@ public virtual Response GetDeletedKey(string name, CancellationToken { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return SendRequest(RequestMethod.Get, () => new DeletedKey(name), cancellationToken, DeletedKeysPath, name); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.GetDeletedKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Get, () => new DeletedKey(name), cancellationToken, DeletedKeysPath, name); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -360,7 +492,19 @@ public virtual async Task> GetDeletedKeyAsync(string name, { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return await SendRequestAsync(RequestMethod.Get, () => new DeletedKey(name), cancellationToken, DeletedKeysPath, name).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.GetDeletedKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Get, () => new DeletedKey(name), cancellationToken, DeletedKeysPath, name).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -379,7 +523,19 @@ public virtual Response DeleteKey(string name, CancellationToken can { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return SendRequest(RequestMethod.Delete, () => new DeletedKey(name), cancellationToken, KeysPath, name); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.DeleteKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Delete, () => new DeletedKey(name), cancellationToken, KeysPath, name); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -398,7 +554,19 @@ public virtual async Task> DeleteKeyAsync(string name, Canc { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return await SendRequestAsync(RequestMethod.Delete, () => new DeletedKey(name), cancellationToken, KeysPath, name).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.DeleteKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Delete, () => new DeletedKey(name), cancellationToken, KeysPath, name).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -417,7 +585,7 @@ public virtual IEnumerable> GetDeletedKeys(CancellationToke { Uri firstPageUri = CreateFirstPageUri(DeletedKeysPath); - return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new DeletedKey(), cancellationToken)); + return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new DeletedKey(), "Azure.Security.KeyVault.Keys.KeyClient.GetDeletedKeys", cancellationToken)); } /// @@ -436,7 +604,7 @@ public virtual IAsyncEnumerable> GetDeletedKeysAsync(Cancel { Uri firstPageUri = CreateFirstPageUri(DeletedKeysPath); - return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new DeletedKey(), cancellationToken)); + return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new DeletedKey(), "Azure.Security.KeyVault.Keys.KeyClient.GetDeletedKeys", cancellationToken)); } /// @@ -454,7 +622,19 @@ public virtual Response PurgeDeletedKey(string name, CancellationToken cancellat { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return SendRequest(RequestMethod.Delete, cancellationToken, DeletedKeysPath, name); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.PurgeDeletedKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Delete, cancellationToken, DeletedKeysPath, name); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -472,7 +652,19 @@ public virtual async Task PurgeDeletedKeyAsync(string name, Cancellati { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return await SendRequestAsync(RequestMethod.Delete, cancellationToken, DeletedKeysPath, name).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.PurgeDeletedKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Delete, cancellationToken, DeletedKeysPath, name).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -491,7 +683,19 @@ public virtual Response RecoverDeletedKey(string name, CancellationToken ca { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return SendRequest(RequestMethod.Post, () => new Key(name), cancellationToken, DeletedKeysPath, name, "/recover"); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.RecoverDeletedKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Post, () => new Key(name), cancellationToken, DeletedKeysPath, name, "/recover"); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -510,7 +714,19 @@ public virtual async Task> RecoverDeletedKeyAsync(string name, Can { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - return await SendRequestAsync(RequestMethod.Post, () => new Key(name), cancellationToken, DeletedKeysPath, name, "/recover").ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.RecoverDeletedKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Post, () => new Key(name), cancellationToken, DeletedKeysPath, name, "/recover").ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -537,9 +753,21 @@ public virtual Response BackupKey(string name, CancellationToken cancell { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - var backup = SendRequest(RequestMethod.Post, () => new KeyBackup(), cancellationToken, KeysPath, name, "/backup"); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.BackupKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + var backup = SendRequest(RequestMethod.Post, () => new KeyBackup(), cancellationToken, KeysPath, name, "/backup"); - return new Response(backup.GetRawResponse(), backup.Value.Value); + return new Response(backup.GetRawResponse(), backup.Value.Value); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -566,9 +794,21 @@ public virtual async Task> BackupKeyAsync(string name, Cancella { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} can't be empty or null"); - var backup = await SendRequestAsync(RequestMethod.Post, () => new KeyBackup(), cancellationToken, KeysPath, name, "/backup").ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.BackupKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + var backup = await SendRequestAsync(RequestMethod.Post, () => new KeyBackup(), cancellationToken, KeysPath, name, "/backup").ConfigureAwait(false); - return new Response(backup.GetRawResponse(), backup.Value.Value); + return new Response(backup.GetRawResponse(), backup.Value.Value); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -595,7 +835,18 @@ public virtual Response RestoreKey(byte[] backup, CancellationToken cancell { if (backup == null) throw new ArgumentNullException(nameof(backup)); - return SendRequest(RequestMethod.Post, new KeyBackup { Value = backup }, () => new Key(), cancellationToken, KeysPath, "/restore"); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.RestoreKey"); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Post, new KeyBackup { Value = backup }, () => new Key(), cancellationToken, KeysPath, "/restore"); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -622,7 +873,18 @@ public virtual async Task> RestoreKeyAsync(byte[] backup, Cancella { if (backup == null) throw new ArgumentNullException(nameof(backup)); - return await SendRequestAsync(RequestMethod.Post, new KeyBackup { Value = backup }, () => new Key(), cancellationToken, KeysPath, "/restore").ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.RestoreKey"); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Post, new KeyBackup { Value = backup }, () => new Key(), cancellationToken, KeysPath, "/restore").ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -644,7 +906,19 @@ public virtual Response ImportKey(string name, JsonWebKey keyMaterial, Canc var keyImportOptions = new KeyImportOptions(name, keyMaterial); - return SendRequest(RequestMethod.Put, keyImportOptions, () => new Key(name), cancellationToken, KeysPath, name); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.ImportKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Put, keyImportOptions, () => new Key(name), cancellationToken, KeysPath, name); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -666,7 +940,19 @@ public virtual async Task> ImportKeyAsync(string name, JsonWebKey var keyImportOptions = new KeyImportOptions(name, keyMaterial); - return await SendRequestAsync(RequestMethod.Put, keyImportOptions, () => new Key(name), cancellationToken, KeysPath, name).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.ImportKey"); + scope.AddAttribute("key", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Put, keyImportOptions, () => new Key(name), cancellationToken, KeysPath, name).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -684,7 +970,20 @@ public virtual Response ImportKey(KeyImportOptions keyImportOptions, Cancel { if (keyImportOptions == default) throw new ArgumentNullException(nameof(keyImportOptions)); - return SendRequest(RequestMethod.Put, keyImportOptions, () => new Key(keyImportOptions.Name), cancellationToken, KeysPath, keyImportOptions.Name); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.ImportKey"); + scope.AddAttribute("key", keyImportOptions.Name); + scope.Start(); + + try + { + + return SendRequest(RequestMethod.Put, keyImportOptions, () => new Key(keyImportOptions.Name), cancellationToken, KeysPath, keyImportOptions.Name); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -702,7 +1001,19 @@ public virtual async Task> ImportKeyAsync(KeyImportOptions keyImpo { if (keyImportOptions == default) throw new ArgumentNullException(nameof(keyImportOptions)); - return await SendRequestAsync(RequestMethod.Put, keyImportOptions, () => new Key(keyImportOptions.Name), cancellationToken, KeysPath, keyImportOptions.Name).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Keys.KeyClient.ImportKey"); + scope.AddAttribute("key", keyImportOptions.Name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Put, keyImportOptions, () => new Key(keyImportOptions.Name), cancellationToken, KeysPath, keyImportOptions.Name).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs index 3c5241ee6d35e..95d5ed080a15a 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyClient_private.cs @@ -161,47 +161,69 @@ private Response CreateResponse(Response response, T result) return new Response(response, result); } - private async Task> GetPageAsync(Uri firstPageUri, string nextLink, Func itemFactory, CancellationToken cancellationToken) + private async Task> GetPageAsync(Uri firstPageUri, string nextLink, Func itemFactory, string operationName, CancellationToken cancellationToken) where T : Model { - // if we don't have a nextLink specified, use firstPageUri - if (nextLink != null) - { - firstPageUri = new Uri(nextLink); - } + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope(operationName); + scope.Start(); - using (Request request = CreateRequest(RequestMethod.Get, firstPageUri)) + try { - Response response = await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + // if we don't have a nextLink specified, use firstPageUri + if (nextLink != null) + { + firstPageUri = new Uri(nextLink); + } - // read the respose - Page responseAsPage = new Page(itemFactory); - responseAsPage.Deserialize(response.ContentStream); + using (Request request = CreateRequest(RequestMethod.Get, firstPageUri)) + { + Response response = await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + + // read the respose + Page responseAsPage = new Page(itemFactory); + responseAsPage.Deserialize(response.ContentStream); - // convert from the Page to PageResponse - return new PageResponse(responseAsPage.Items.ToArray(), response, responseAsPage.NextLink?.ToString()); + // convert from the Page to PageResponse + return new PageResponse(responseAsPage.Items.ToArray(), response, responseAsPage.NextLink?.ToString()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; } } - private PageResponse GetPage(Uri firstPageUri, string nextLink, Func itemFactory, CancellationToken cancellationToken) + private PageResponse GetPage(Uri firstPageUri, string nextLink, Func itemFactory, string operationName, CancellationToken cancellationToken) where T : Model { - // if we don't have a nextLink specified, use firstPageUri - if (nextLink != null) - { - firstPageUri = new Uri(nextLink); - } + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope(operationName); + scope.Start(); - using (Request request = CreateRequest(RequestMethod.Get, firstPageUri)) + try { - Response response = SendRequest(request, cancellationToken); + // if we don't have a nextLink specified, use firstPageUri + if (nextLink != null) + { + firstPageUri = new Uri(nextLink); + } - // read the respose - Page responseAsPage = new Page(itemFactory); - responseAsPage.Deserialize(response.ContentStream); + using (Request request = CreateRequest(RequestMethod.Get, firstPageUri)) + { + Response response = SendRequest(request, cancellationToken); + + // read the respose + Page responseAsPage = new Page(itemFactory); + responseAsPage.Deserialize(response.ContentStream); - // convert from the Page to PageResponse - return new PageResponse(responseAsPage.Items.ToArray(), response, responseAsPage.NextLink?.ToString()); + // convert from the Page to PageResponse + return new PageResponse(responseAsPage.Items.ToArray(), response, responseAsPage.NextLink?.ToString()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyClientLiveTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyClientLiveTests.cs index 49c2948c3312e..adf4e640f4c4c 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyClientLiveTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyClientLiveTests.cs @@ -17,7 +17,6 @@ public class KeyClientLiveTests : KeysTestBase public KeyClientLiveTests(bool isAsync) : base(isAsync) { - TestDiagnostics = false; } [Test] diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs index 2525ff9dd4fac..de8e45e30309f 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/SecretClient.cs @@ -76,7 +76,19 @@ public virtual async Task> GetAsync(string name, string version { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); - return await SendRequestAsync(RequestMethod.Get, () => new Secret(), cancellationToken, SecretsPath, name, "/", version).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Get"); + scope.AddAttribute("secret", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Get, () => new Secret(), cancellationToken, SecretsPath, name, "/", version).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -93,7 +105,19 @@ public virtual Response Get(string name, string version = null, Cancella { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); - return SendRequest(RequestMethod.Get, () => new Secret(), cancellationToken, SecretsPath, name, "/", version); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Get"); + scope.AddAttribute("secret", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Get, () => new Secret(), cancellationToken, SecretsPath, name, "/", version); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -112,7 +136,7 @@ public virtual IAsyncEnumerable> GetSecretVersionsAsync(str Uri firstPageUri = new Uri(_vaultUri, $"{SecretsPath}{name}/versions?api-version={ApiVersion}"); - return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new SecretBase(), cancellationToken)); + return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new SecretBase(), "Azure.Security.KeyVault.Secrets.SecretClient.GetSecretVersions", cancellationToken)); } /// @@ -131,7 +155,7 @@ public virtual IEnumerable> GetSecretVersions(string name, Uri firstPageUri = new Uri(_vaultUri, $"{SecretsPath}{name}/versions?api-version={ApiVersion}"); - return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new SecretBase(), cancellationToken)); + return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new SecretBase(), "Azure.Security.KeyVault.Secrets.SecretClient.GetSecretVersions", cancellationToken)); } /// @@ -148,7 +172,7 @@ public virtual IAsyncEnumerable> GetSecretsAsync(Cancellati { Uri firstPageUri = new Uri(_vaultUri, SecretsPath + $"?api-version={ApiVersion}"); - return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new SecretBase(), cancellationToken)); + return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new SecretBase(), "Azure.Security.KeyVault.Secrets.SecretClient.GetSecrets", cancellationToken)); } /// @@ -165,7 +189,7 @@ public virtual IEnumerable> GetSecrets(CancellationToken ca { Uri firstPageUri = new Uri(_vaultUri, SecretsPath + $"?api-version={ApiVersion}"); - return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new SecretBase(), cancellationToken)); + return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new SecretBase(), "Azure.Security.KeyVault.Secrets.SecretClient.GetSecrets", cancellationToken)); } /// @@ -184,7 +208,19 @@ public virtual async Task> UpdateAsync(SecretBase secret, C if (secret == null) throw new ArgumentNullException(nameof(secret)); if (secret.Version == null) throw new ArgumentNullException($"{nameof(secret)}.{nameof(secret.Version)}"); - return await SendRequestAsync(RequestMethod.Patch, secret, () => new SecretBase(), cancellationToken, SecretsPath, secret.Name, "/", secret.Version).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Update"); + scope.AddAttribute("secret", secret.Name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Patch, secret, () => new SecretBase(), cancellationToken, SecretsPath, secret.Name, "/", secret.Version).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -202,8 +238,19 @@ public virtual Response Update(SecretBase secret, CancellationToken { if (secret == null) throw new ArgumentNullException(nameof(secret)); if (secret.Version == null) throw new ArgumentNullException($"{nameof(secret)}.{nameof(secret.Version)}"); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Update"); + scope.AddAttribute("secret", secret.Name); + scope.Start(); - return SendRequest(RequestMethod.Patch, secret, () => new SecretBase(), cancellationToken, SecretsPath, secret.Name, "/", secret.Version); + try + { + return SendRequest(RequestMethod.Patch, secret, () => new SecretBase(), cancellationToken, SecretsPath, secret.Name, "/", secret.Version); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -220,7 +267,19 @@ public virtual async Task> SetAsync(Secret secret, Cancellation { if (secret == null) throw new ArgumentNullException(nameof(secret)); - return await SendRequestAsync(RequestMethod.Put, secret, () => new Secret(), cancellationToken, SecretsPath, secret.Name).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Set"); + scope.AddAttribute("secret", secret.Name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Put, secret, () => new Secret(), cancellationToken, SecretsPath, secret.Name).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -236,8 +295,19 @@ public virtual async Task> SetAsync(Secret secret, Cancellation public virtual Response Set(Secret secret, CancellationToken cancellationToken = default) { if (secret == null) throw new ArgumentNullException(nameof(secret)); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Set"); + scope.AddAttribute("secret", secret.Name); + scope.Start(); - return SendRequest(RequestMethod.Put, secret, () => new Secret(), cancellationToken, SecretsPath, secret.Name); + try + { + return SendRequest(RequestMethod.Put, secret, () => new Secret(), cancellationToken, SecretsPath, secret.Name); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -286,7 +356,19 @@ public virtual async Task> DeleteAsync(string name, Canc { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); - return await SendRequestAsync(RequestMethod.Delete, () => new DeletedSecret(), cancellationToken, SecretsPath, name).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Delete"); + scope.AddAttribute("secret", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Delete, () => new DeletedSecret(), cancellationToken, SecretsPath, name).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -303,7 +385,19 @@ public virtual Response Delete(string name, CancellationToken can { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); - return SendRequest(RequestMethod.Delete, () => new DeletedSecret(), cancellationToken, SecretsPath, name); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Delete"); + scope.AddAttribute("secret", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Delete, () => new DeletedSecret(), cancellationToken, SecretsPath, name); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -319,7 +413,19 @@ public virtual async Task> GetDeletedAsync(string name, { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); - return await SendRequestAsync(RequestMethod.Get, () => new DeletedSecret(), cancellationToken, DeletedSecretsPath, name).ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.GetDeleted"); + scope.AddAttribute("secret", name); + scope.Start(); + + try + { + return await SendRequestAsync(RequestMethod.Get, () => new DeletedSecret(), cancellationToken, DeletedSecretsPath, name).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -335,7 +441,19 @@ public virtual Response GetDeleted(string name, CancellationToken { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); - return SendRequest(RequestMethod.Get, () => new DeletedSecret(), cancellationToken, DeletedSecretsPath, name); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.GetDeleted"); + scope.AddAttribute("secret", name); + scope.Start(); + + try + { + return SendRequest(RequestMethod.Get, () => new DeletedSecret(), cancellationToken, DeletedSecretsPath, name); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -351,7 +469,7 @@ public virtual IAsyncEnumerable> GetDeletedSecretsAsync( { Uri firstPageUri = new Uri(_vaultUri, DeletedSecretsPath + $"?api-version={ApiVersion}"); - return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new DeletedSecret(), cancellationToken)); + return PageResponseEnumerator.CreateAsyncEnumerable(nextLink => GetPageAsync(firstPageUri, nextLink, () => new DeletedSecret(), "Azure.Security.KeyVault.Secrets.SecretClient.GetDeletedSecrets", cancellationToken)); } /// @@ -367,7 +485,7 @@ public virtual IEnumerable> GetDeletedSecrets(Cancellati { Uri firstPageUri = new Uri(_vaultUri, DeletedSecretsPath + $"?api-version={ApiVersion}"); - return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new DeletedSecret(), cancellationToken)); + return PageResponseEnumerator.CreateEnumerable(nextLink => GetPage(firstPageUri, nextLink, () => new DeletedSecret(), "Azure.Security.KeyVault.Secrets.SecretClient.GetDeletedSecrets", cancellationToken)); } /// @@ -383,8 +501,19 @@ public virtual IEnumerable> GetDeletedSecrets(Cancellati public virtual async Task> RecoverDeletedAsync(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.RecoverDeleted"); + scope.AddAttribute("secret", name); + scope.Start(); - return await SendRequestAsync(RequestMethod.Post, () => new SecretBase(), cancellationToken, DeletedSecretsPath, name, "/recover").ConfigureAwait(false); + try + { + return await SendRequestAsync(RequestMethod.Post, () => new SecretBase(), cancellationToken, DeletedSecretsPath, name, "/recover").ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -400,8 +529,19 @@ public virtual async Task> RecoverDeletedAsync(string name, public virtual Response RecoverDeleted(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.RecoverDeleted"); + scope.AddAttribute("secret", name); + scope.Start(); - return SendRequest(RequestMethod.Post, () => new SecretBase(), cancellationToken, DeletedSecretsPath, name, "/recover"); + try + { + return SendRequest(RequestMethod.Post, () => new SecretBase(), cancellationToken, DeletedSecretsPath, name, "/recover"); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -418,8 +558,19 @@ public virtual Response RecoverDeleted(string name, CancellationToke public virtual async Task PurgeDeletedAsync(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.PurgeDeleted"); + scope.AddAttribute("secret", name); + scope.Start(); - return await SendRequestAsync(RequestMethod.Delete, cancellationToken, DeletedSecretsPath, name).ConfigureAwait(false); + try + { + return await SendRequestAsync(RequestMethod.Delete, cancellationToken, DeletedSecretsPath, name).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -436,7 +587,18 @@ public virtual async Task PurgeDeletedAsync(string name, CancellationT public virtual Response PurgeDeleted(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.PurgeDeleted"); + scope.AddAttribute("secret", name); + scope.Start(); + try + { + } + catch (Exception e) + { + scope.Failed(e); + throw; + } return SendRequest(RequestMethod.Delete, cancellationToken, DeletedSecretsPath, name); } @@ -454,9 +616,21 @@ public virtual async Task> BackupAsync(string name, Cancellatio { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); - var backup = await SendRequestAsync(RequestMethod.Post, () => new VaultBackup(), cancellationToken, SecretsPath, name, "/backup").ConfigureAwait(false); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Backup"); + scope.AddAttribute("secret", name); + scope.Start(); - return new Response(backup.GetRawResponse(), backup.Value.Value); + try + { + var backup = await SendRequestAsync(RequestMethod.Post, () => new VaultBackup(), cancellationToken, SecretsPath, name, "/backup").ConfigureAwait(false); + + return new Response(backup.GetRawResponse(), backup.Value.Value); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -472,10 +646,21 @@ public virtual async Task> BackupAsync(string name, Cancellatio public virtual Response Backup(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrEmpty(name)) throw new ArgumentException($"{nameof(name)} must not be null or empty", nameof(name)); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Backup"); + scope.AddAttribute("secret", name); + scope.Start(); - var backup = SendRequest(RequestMethod.Post, () => new VaultBackup(), cancellationToken, SecretsPath, name, "/backup"); + try + { + var backup = SendRequest(RequestMethod.Post, () => new VaultBackup(), cancellationToken, SecretsPath, name, "/backup"); - return new Response(backup.GetRawResponse(), backup.Value.Value); + return new Response(backup.GetRawResponse(), backup.Value.Value); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -490,8 +675,18 @@ public virtual Response Backup(string name, CancellationToken cancellati public virtual async Task> RestoreAsync(byte[] backup, CancellationToken cancellationToken = default) { if (backup == null) throw new ArgumentNullException(nameof(backup)); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Restore"); + scope.Start(); - return await SendRequestAsync(RequestMethod.Post, new VaultBackup { Value = backup }, () => new SecretBase(), cancellationToken, SecretsPath, "restore").ConfigureAwait(false); + try + { + return await SendRequestAsync(RequestMethod.Post, new VaultBackup { Value = backup }, () => new SecretBase(), cancellationToken, SecretsPath, "restore").ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } /// @@ -506,8 +701,18 @@ public virtual async Task> RestoreAsync(byte[] backup, Canc public virtual Response Restore(byte[] backup, CancellationToken cancellationToken = default) { if (backup == null) throw new ArgumentNullException(nameof(backup)); + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope("Azure.Security.KeyVault.Secrets.SecretClient.Restore"); + scope.Start(); - return SendRequest(RequestMethod.Post, new VaultBackup { Value = backup }, () => new SecretBase(), cancellationToken, SecretsPath, "restore"); + try + { + return SendRequest(RequestMethod.Post, new VaultBackup { Value = backup }, () => new SecretBase(), cancellationToken, SecretsPath, "restore"); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } } private async Task> SendRequestAsync(RequestMethod method, TContent content, Func resultFactory, CancellationToken cancellationToken, params string[] path) @@ -604,7 +809,7 @@ private Response SendRequest(Request request, CancellationToken cancellationToke } } - private async Task> GetPageAsync(Uri firstPageUri, string nextLink, Func itemFactory, CancellationToken cancellationToken) + private async Task> GetPageAsync(Uri firstPageUri, string nextLink, Func itemFactory, string operationName, CancellationToken cancellationToken) where T : Model { // if we don't have a nextLink specified, use firstPageUri @@ -613,20 +818,31 @@ private async Task> GetPageAsync(Uri firstPageUri, string nex firstPageUri = new Uri(nextLink); } - using (Request request = CreateRequest(RequestMethod.Get, firstPageUri)) + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope(operationName); + scope.Start(); + + try { - Response response = await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + using (Request request = CreateRequest(RequestMethod.Get, firstPageUri)) + { + Response response = await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); - // read the respose - Page responseAsPage = new Page(itemFactory); - responseAsPage.Deserialize(response.ContentStream); + // read the respose + Page responseAsPage = new Page(itemFactory); + responseAsPage.Deserialize(response.ContentStream); - // convert from the Page to PageResponse - return new PageResponse(responseAsPage.Items.ToArray(), response, responseAsPage.NextLink?.ToString()); + // convert from the Page to PageResponse + return new PageResponse(responseAsPage.Items.ToArray(), response, responseAsPage.NextLink?.ToString()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; } } - private PageResponse GetPage(Uri firstPageUri, string nextLink, Func itemFactory, CancellationToken cancellationToken) + private PageResponse GetPage(Uri firstPageUri, string nextLink, Func itemFactory, string operationName, CancellationToken cancellationToken) where T : Model { // if we don't have a nextLink specified, use firstPageUri @@ -635,16 +851,27 @@ private PageResponse GetPage(Uri firstPageUri, string nextLink, Func it firstPageUri = new Uri(nextLink); } - using (Request request = CreateRequest(RequestMethod.Get, firstPageUri)) + using DiagnosticScope scope = _pipeline.Diagnostics.CreateScope(operationName); + scope.Start(); + + try { - Response response = SendRequest(request, cancellationToken); + using (Request request = CreateRequest(RequestMethod.Get, firstPageUri)) + { + Response response = SendRequest(request, cancellationToken); - // read the respose - Page responseAsPage = new Page(itemFactory); - responseAsPage.Deserialize(response.ContentStream); + // read the respose + Page responseAsPage = new Page(itemFactory); + responseAsPage.Deserialize(response.ContentStream); - // convert from the Page to PageResponse - return new PageResponse(responseAsPage.Items.ToArray(), response, responseAsPage.NextLink?.ToString()); + // convert from the Page to PageResponse + return new PageResponse(responseAsPage.Items.ToArray(), response, responseAsPage.NextLink?.ToString()); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretClientLiveTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretClientLiveTests.cs index be87bd56d5967..e8dab1e68e90e 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretClientLiveTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/SecretClientLiveTests.cs @@ -20,7 +20,6 @@ public class SecretClientLiveTests : KeyVaultTestBase public SecretClientLiveTests(bool isAsync) : base(isAsync) { - TestDiagnostics = false; } [Test]