diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/AsyncSearch.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/AsyncSearch.cs index 159c1281be09..e53c9650a98c 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/AsyncSearch.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/AsyncSearch.cs @@ -14,6 +14,7 @@ */ using Amazon.DynamoDBv2.DocumentModel; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DataModel { @@ -46,6 +47,8 @@ public partial class AsyncSearch : IAsyncSearch private DynamoDBContext _sourceContext { get; set; } private DynamoDBFlatConfig _config { get; set; } + internal TracerProvider TracerProvider { get; set; } + /// /// This constructor is used for mocking. Users that want to mock AsyncSearch can create a subclass of AsyncSearch and make a public parameterless constructor. /// @@ -59,6 +62,8 @@ internal AsyncSearch(DynamoDBContext source, DynamoDBContext.ContextSearch conte _sourceContext = source; _documentSearch = contextSearch.Search; _config = contextSearch.FlatConfig; + TracerProvider = source?.Client?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs index 7dae11417f1c..9bfd012824f5 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchGet.cs @@ -16,6 +16,8 @@ using System; using System.Collections.Generic; using Amazon.DynamoDBv2.DocumentModel; +using Amazon.Runtime.Telemetry.Tracing; + #if AWS_ASYNC_API using System.Threading.Tasks; @@ -105,6 +107,8 @@ public abstract partial class BatchGet : IBatchGet { internal DocumentBatchGet DocumentBatch { get; set; } + internal TracerProvider TracerProvider { get; set; } + internal abstract void CreateDocumentBatch(); internal abstract void PopulateResults(List items); @@ -167,6 +171,8 @@ internal BatchGet(DynamoDBContext context, DynamoDBFlatConfig config) _context = context; _config = config; _itemStorageConfig = context.StorageConfigCache.GetConfig(config); + TracerProvider = context?.Client?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } private void ExecuteHelper() @@ -239,6 +245,8 @@ public partial class MultiTableBatchGet : IMultiTableBatchGet { private List allBatches = new List(); + internal TracerProvider TracerProvider { get; set; } + /// /// Constructs a MultiTableBatchGet object from a number of /// BatchGet objects @@ -247,6 +255,7 @@ public partial class MultiTableBatchGet : IMultiTableBatchGet public MultiTableBatchGet(params IBatchGet[] batches) { allBatches = new List(batches); + TracerProvider = GetTracerProvider(allBatches); } internal MultiTableBatchGet(IBatchGet first, params IBatchGet[] rest) @@ -254,6 +263,7 @@ internal MultiTableBatchGet(IBatchGet first, params IBatchGet[] rest) allBatches = new List(); allBatches.Add(first); allBatches.AddRange(rest); + TracerProvider = GetTracerProvider(allBatches); } /// @@ -317,5 +327,19 @@ private async Task ExecuteHelperAsync(CancellationToken cancellationToken) } } #endif + + private TracerProvider GetTracerProvider(List allBatches) + { + var tracerProvider = AWSConfigs.TelemetryProvider.TracerProvider; + if (allBatches.Count > 0) + { + var firstBatch = allBatches[0]; + if (firstBatch is BatchGet batchGet) + { + tracerProvider = batchGet.TracerProvider; + } + } + return tracerProvider; + } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWrite.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWrite.cs index 4f773862f684..b25cde128e9e 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWrite.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BatchWrite.cs @@ -17,6 +17,8 @@ using System.Collections.Generic; using Amazon.DynamoDBv2.DocumentModel; using System.Globalization; +using Amazon.Runtime.Telemetry.Tracing; + #if AWS_ASYNC_API using System.Threading.Tasks; #endif @@ -96,6 +98,8 @@ public interface IBatchWrite : IBatchWrite public abstract partial class BatchWrite : IBatchWrite { internal DocumentBatchWrite DocumentBatch { get; set; } + + internal TracerProvider TracerProvider { get; set; } } /// @@ -132,6 +136,9 @@ internal BatchWrite(DynamoDBContext context, Type valuesType, DynamoDBFlatConfig // Table.CreateBatchWrite() returns the IDocumentBatchWrite interface. // But since we rely on the internal behavior of DocumentBatchWrite, we instantiate it via the constructor. DocumentBatch = new DocumentBatchWrite(table); + + TracerProvider = context?.Client?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } /// @@ -228,6 +235,8 @@ public partial class MultiTableBatchWrite : IMultiTableBatchWrite { private List allBatches = new(); + internal TracerProvider TracerProvider { get; set; } + /// /// Constructs a MultiTableBatchWrite object from a number of /// BatchWrite objects @@ -236,6 +245,7 @@ public partial class MultiTableBatchWrite : IMultiTableBatchWrite public MultiTableBatchWrite(params IBatchWrite[] batches) { allBatches = new List(batches); + TracerProvider = GetTracerProvider(allBatches); } internal MultiTableBatchWrite(IBatchWrite first, params IBatchWrite[] rest) @@ -243,6 +253,7 @@ internal MultiTableBatchWrite(IBatchWrite first, params IBatchWrite[] rest) allBatches = new List(); allBatches.Add(first); allBatches.AddRange(rest); + TracerProvider = GetTracerProvider(allBatches); } /// @@ -276,5 +287,19 @@ private Task ExecuteHelperAsync(CancellationToken cancellationToken) return superBatch.ExecuteHelperAsync(cancellationToken); } #endif + + private TracerProvider GetTracerProvider(List allBatches) + { + var tracerProvider = AWSConfigs.TelemetryProvider.TracerProvider; + if (allBatches.Count > 0) + { + var firstBatch = allBatches[0]; + if (firstBatch is BatchWrite batchWrite) + { + tracerProvider = batchWrite.TracerProvider; + } + } + return tracerProvider; + } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs index 7daa14368bb6..ae4e15bb06be 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactGet.cs @@ -20,6 +20,7 @@ using System.Threading.Tasks; #endif using Amazon.DynamoDBv2.DocumentModel; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DataModel { @@ -97,6 +98,8 @@ public abstract partial class TransactGet : ITransactGet { internal DocumentTransactGet DocumentTransaction { get; set; } + internal TracerProvider TracerProvider { get; set; } + internal abstract void PopulateResults(); /// @@ -161,6 +164,9 @@ internal TransactGet(DynamoDBContext context, DynamoDBFlatConfig config) // Table.CreateTransactGet() returns the IDocumentTransactGet interface. // But since we rely on the internal behavior of DocumentTransactGet, we instantiate it via the constructor. DocumentTransaction = new DocumentTransactGet(table); + + TracerProvider = context?.Client?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } private void ExecuteHelper() @@ -211,6 +217,8 @@ public partial class MultiTableTransactGet : IMultiTableTransactGet { private readonly List allTransactionParts; + internal TracerProvider TracerProvider { get; set; } + /// /// Constructs a MultiTableTransactGet object from a number of /// TransactGet objects. @@ -219,6 +227,7 @@ public partial class MultiTableTransactGet : IMultiTableTransactGet public MultiTableTransactGet(params ITransactGet[] transactionParts) { allTransactionParts = new List(transactionParts); + TracerProvider = GetTracerProvider(allTransactionParts); } internal MultiTableTransactGet(ITransactGet first, params ITransactGet[] rest) @@ -226,6 +235,7 @@ internal MultiTableTransactGet(ITransactGet first, params ITransactGet[] rest) allTransactionParts = new List(); allTransactionParts.Add(first); allTransactionParts.AddRange(rest); + TracerProvider = GetTracerProvider(allTransactionParts); } /// @@ -269,5 +279,18 @@ private async Task ExecuteHelperAsync(CancellationToken cancellationToken) } } #endif + private TracerProvider GetTracerProvider(List allTransactionParts) + { + var tracerProvider = AWSConfigs.TelemetryProvider.TracerProvider; + if (allTransactionParts.Count > 0) + { + var firstTransactionPart = allTransactionParts[0]; + if (firstTransactionPart is TransactGet transactGet) + { + tracerProvider = transactGet.TracerProvider; + } + } + return tracerProvider; + } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs index de61ba6addaa..bff1eb006727 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/TransactWrite.cs @@ -21,6 +21,7 @@ using System.Threading.Tasks; #endif using Amazon.DynamoDBv2.DocumentModel; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DataModel { @@ -165,6 +166,8 @@ public abstract partial class TransactWrite : ITransactWrite { internal DocumentTransactWrite DocumentTransaction { get; set; } + internal TracerProvider TracerProvider { get; set; } + internal abstract void PopulateObjects(); } @@ -192,6 +195,9 @@ internal TransactWrite(DynamoDBContext context, DynamoDBFlatConfig config) // table.CreateTransactWrite() return the IDocumentTransactWrite interface. // But since we rely on the internal behavior of DocumentTransactWrite, we instatiate it via the constructor. DocumentTransaction = new DocumentTransactWrite(table); + + TracerProvider = context?.Client?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } /// @@ -457,6 +463,8 @@ public partial class MultiTableTransactWrite : IMultiTableTransactWrite { private readonly List allTransactionParts; + internal TracerProvider TracerProvider { get; set; } + /// /// Constructs a MultiTableTransactWrite object from a number of /// TransactWrite objects @@ -465,6 +473,7 @@ public partial class MultiTableTransactWrite : IMultiTableTransactWrite public MultiTableTransactWrite(params ITransactWrite[] transactionParts) { allTransactionParts = new List(transactionParts); + TracerProvider = GetTracerProvider(allTransactionParts); } internal MultiTableTransactWrite(ITransactWrite first, params ITransactWrite[] rest) @@ -472,6 +481,7 @@ internal MultiTableTransactWrite(ITransactWrite first, params ITransactWrite[] r allTransactionParts = new List(); allTransactionParts.Add(first); allTransactionParts.AddRange(rest); + TracerProvider = GetTracerProvider(allTransactionParts); } /// @@ -514,6 +524,20 @@ private async Task ExecuteHelperAsync(CancellationToken cancellationToken) abstractTransactWrite.PopulateObjects(); } } + + private TracerProvider GetTracerProvider(List allTransactionParts) + { + var tracerProvider = AWSConfigs.TelemetryProvider.TracerProvider; + if (allTransactionParts.Count > 0) + { + var firstTransactionPart = allTransactionParts[0]; + if (firstTransactionPart is TransactWrite transactWrite) + { + tracerProvider = transactWrite.TracerProvider; + } + } + return tracerProvider; + } #endif } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs index c37d83a73c6d..d15b938aeb36 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/AsyncSearch.Async.cs @@ -13,6 +13,7 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -52,17 +53,25 @@ public partial class AsyncSearch : IAsyncSearch /// public virtual async Task> GetNextSetAsync(CancellationToken cancellationToken = default(CancellationToken)) { - var documents = await _documentSearch.GetNextSetHelperAsync(cancellationToken).ConfigureAwait(false); - List items = _sourceContext.FromDocumentsHelper(documents, this._config).ToList(); - return items; + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(AsyncSearch), nameof(GetNextSetAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + var documents = await _documentSearch.GetNextSetHelperAsync(cancellationToken).ConfigureAwait(false); + List items = _sourceContext.FromDocumentsHelper(documents, this._config).ToList(); + return items; + } } /// public virtual async Task> GetRemainingAsync(CancellationToken cancellationToken = default(CancellationToken)) { - var documents = await _documentSearch.GetRemainingHelperAsync(cancellationToken).ConfigureAwait(false); - List items = _sourceContext.FromDocumentsHelper(documents, this._config).ToList(); - return items; + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(AsyncSearch), nameof(GetRemainingAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + var documents = await _documentSearch.GetRemainingHelperAsync(cancellationToken).ConfigureAwait(false); + List items = _sourceContext.FromDocumentsHelper(documents, this._config).ToList(); + return items; + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchGet.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchGet.Async.cs index 561e70161b56..8f8819e51f11 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchGet.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchGet.Async.cs @@ -14,6 +14,7 @@ */ #pragma warning disable 1574 +using Amazon.Runtime.Telemetry.Tracing; using System.Threading; using System.Threading.Tasks; @@ -39,9 +40,13 @@ public abstract partial class BatchGet public partial class BatchGet : BatchGet, IBatchGet { /// - public override Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(BatchGet), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } @@ -60,9 +65,13 @@ public partial interface IMultiTableBatchGet public partial class MultiTableBatchGet : IMultiTableBatchGet { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableBatchGet), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchWrite.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchWrite.Async.cs index ec77b8766dd5..7ceef88a5634 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchWrite.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/BatchWrite.Async.cs @@ -16,6 +16,7 @@ using System.Threading.Tasks; using System.Threading; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DataModel { @@ -42,9 +43,13 @@ public abstract partial class BatchWrite : IBatchWrite public partial class BatchWrite : BatchWrite, IBatchWrite { /// - public override Task ExecuteAsync(CancellationToken cancellationToken) + public override async Task ExecuteAsync(CancellationToken cancellationToken) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(BatchWrite), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } @@ -65,9 +70,13 @@ public partial interface IMultiTableBatchWrite public partial class MultiTableBatchWrite : IMultiTableBatchWrite { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableBatchWrite), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs index 731287ef7fda..bea5ad0782bf 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/Context.Async.cs @@ -31,41 +31,59 @@ public partial class DynamoDBContext : IDynamoDBContext #region Save async /// - public Task SaveAsync(T value, CancellationToken cancellationToken = default) + public async Task SaveAsync(T value, CancellationToken cancellationToken = default) { - return SaveHelperAsync(value, new DynamoDBFlatConfig(null, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) + { + await SaveHelperAsync(value, new DynamoDBFlatConfig(null, Config), cancellationToken).ConfigureAwait(false); + } } /// [Obsolete("Use the SaveAsync overload that takes SaveConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to SaveAsync.")] - public Task SaveAsync(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task SaveAsync(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { - return SaveHelperAsync(value, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) + { + await SaveHelperAsync(value, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task SaveAsync(T value, SaveConfig saveConfig, CancellationToken cancellationToken = default) + public async Task SaveAsync(T value, SaveConfig saveConfig, CancellationToken cancellationToken = default) { - return SaveHelperAsync(value, new DynamoDBFlatConfig(saveConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) + { + await SaveHelperAsync(value, new DynamoDBFlatConfig(saveConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task SaveAsync(Type valueType, object value, CancellationToken cancellationToken = default) + public async Task SaveAsync(Type valueType, object value, CancellationToken cancellationToken = default) { - return SaveHelperAsync(valueType, value, new DynamoDBFlatConfig(null, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) + { + await SaveHelperAsync(valueType, value, new DynamoDBFlatConfig(null, Config), cancellationToken).ConfigureAwait(false); + } } /// [Obsolete("Use the SaveAsync overload that takes SaveConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to SaveAsync.")] - public Task SaveAsync(Type valueType, object value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task SaveAsync(Type valueType, object value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { - return SaveHelperAsync(valueType, value, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) + { + await SaveHelperAsync(valueType, value, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task SaveAsync(Type valueType, object value, SaveConfig saveConfig, CancellationToken cancellationToken = default) + public async Task SaveAsync(Type valueType, object value, SaveConfig saveConfig, CancellationToken cancellationToken = default) { - return SaveHelperAsync(valueType, value, new DynamoDBFlatConfig(saveConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(SaveAsync))) + { + await SaveHelperAsync(valueType, value, new DynamoDBFlatConfig(saveConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken).ConfigureAwait(false); + } } #endregion @@ -73,60 +91,87 @@ public Task SaveAsync(Type valueType, object value, SaveConfig saveConfig, Cance #region Load async /// - public Task LoadAsync(object hashKey, CancellationToken cancellationToken = default) + public async Task LoadAsync(object hashKey, CancellationToken cancellationToken = default) { - return LoadHelperAsync(hashKey, null, new DynamoDBFlatConfig(null, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) + { + return await LoadHelperAsync(hashKey, null, new DynamoDBFlatConfig(null, Config), cancellationToken).ConfigureAwait(false); + } } /// [Obsolete("Use the LoadAsync overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to LoadAsync.")] - public Task LoadAsync(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { - return LoadHelperAsync(hashKey, null, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) + { + return await LoadHelperAsync(hashKey, null, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task LoadAsync(object hashKey, LoadConfig loadConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync(object hashKey, LoadConfig loadConfig, CancellationToken cancellationToken = default) { - return LoadHelperAsync(hashKey, null, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) + { + return await LoadHelperAsync(hashKey, null, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task LoadAsync(object hashKey, object rangeKey, CancellationToken cancellationToken = default) + public async Task LoadAsync(object hashKey, object rangeKey, CancellationToken cancellationToken = default) { - return LoadHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(null, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) + { + return await LoadHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(null, Config), cancellationToken).ConfigureAwait(false); + } } /// [Obsolete("Use the LoadAsync overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to LoadAsync.")] - public Task LoadAsync(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { - return LoadHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) + { + return await LoadHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task LoadAsync(object hashKey, object rangeKey, LoadConfig loadConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync(object hashKey, object rangeKey, LoadConfig loadConfig, CancellationToken cancellationToken = default) { - return LoadHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) + { + return await LoadHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task LoadAsync(T keyObject, CancellationToken cancellationToken = default) + public async Task LoadAsync(T keyObject, CancellationToken cancellationToken = default) { - return LoadHelperAsync(keyObject, new DynamoDBFlatConfig(null, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) + { + return await LoadHelperAsync(keyObject, new DynamoDBFlatConfig(null, Config), cancellationToken).ConfigureAwait(false); + } } /// [Obsolete("Use the LoadAsync overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to LoadAsync.")] - public Task LoadAsync(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync(T keyObject, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { - return LoadHelperAsync(keyObject, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) + { + return await LoadHelperAsync(keyObject, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task LoadAsync(T keyObject, LoadConfig loadConfig, CancellationToken cancellationToken = default) + public async Task LoadAsync(T keyObject, LoadConfig loadConfig, CancellationToken cancellationToken = default) { - return LoadHelperAsync(keyObject, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(LoadAsync))) + { + return await LoadHelperAsync(keyObject, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken).ConfigureAwait(false); + } } #endregion @@ -134,60 +179,87 @@ public Task LoadAsync(T keyObject, LoadConfig loadConfig, CancellationToke #region Delete async /// - public Task DeleteAsync(T value, CancellationToken cancellationToken = default) + public async Task DeleteAsync(T value, CancellationToken cancellationToken = default) { - return DeleteHelperAsync(value, new DynamoDBFlatConfig(null, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) + { + await DeleteHelperAsync(value, new DynamoDBFlatConfig(null, Config), cancellationToken).ConfigureAwait(false); + } } /// [Obsolete("Use the DeleteAsync overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to DeleteAsync.")] - public Task DeleteAsync(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync(T value, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { - return DeleteHelperAsync(value, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) + { + await DeleteHelperAsync(value, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteAsync(T value, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync(T value, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) { - return DeleteHelperAsync(value, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) + { + await DeleteHelperAsync(value, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteAsync(object hashKey, CancellationToken cancellationToken = default) + public async Task DeleteAsync(object hashKey, CancellationToken cancellationToken = default) { - return DeleteHelperAsync(hashKey, null, new DynamoDBFlatConfig(null, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) + { + await DeleteHelperAsync(hashKey, null, new DynamoDBFlatConfig(null, Config), cancellationToken).ConfigureAwait(false); + } } /// [Obsolete("Use the DeleteAsync overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to DeleteAsync.")] - public Task DeleteAsync(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync(object hashKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { - return DeleteHelperAsync(hashKey, null, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) + { + await DeleteHelperAsync(hashKey, null, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteAsync(object hashKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync(object hashKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) { - return DeleteHelperAsync(hashKey, null, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) + { + await DeleteHelperAsync(hashKey, null, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteAsync(object hashKey, object rangeKey, CancellationToken cancellationToken = default) + public async Task DeleteAsync(object hashKey, object rangeKey, CancellationToken cancellationToken = default) { - return DeleteHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(null, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) + { + await DeleteHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(null, Config), cancellationToken).ConfigureAwait(false); + } } /// [Obsolete("Use the DeleteAsync overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to DeleteAsync.")] - public Task DeleteAsync(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig, CancellationToken cancellationToken = default) { - return DeleteHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) + { + await DeleteHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(operationConfig, Config), cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteAsync(object hashKey, object rangeKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) + public async Task DeleteAsync(object hashKey, object rangeKey, DeleteConfig deleteConfig, CancellationToken cancellationToken = default) { - return DeleteHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(DeleteAsync))) + { + await DeleteHelperAsync(hashKey, rangeKey, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config), cancellationToken).ConfigureAwait(false); + } } #endregion @@ -195,16 +267,22 @@ public Task DeleteAsync(object hashKey, object rangeKey, DeleteConfig deleteC #region BatchGet async /// - public Task ExecuteBatchGetAsync(params IBatchGet[] batches) + public async Task ExecuteBatchGetAsync(params IBatchGet[] batches) { - return ExecuteBatchGetAsync(batches, default(CancellationToken)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ExecuteBatchGetAsync))) + { + await ExecuteBatchGetAsync(batches, default(CancellationToken)).ConfigureAwait(false); + } } /// - public Task ExecuteBatchGetAsync(IBatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteBatchGetAsync(IBatchGet[] batches, CancellationToken cancellationToken = default(CancellationToken)) { - MultiTableBatchGet superBatch = new MultiTableBatchGet(batches); - return superBatch.ExecuteAsync(cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ExecuteBatchGetAsync))) + { + MultiTableBatchGet superBatch = new MultiTableBatchGet(batches); + await superBatch.ExecuteAsync(cancellationToken).ConfigureAwait(false); + } } #endregion @@ -212,10 +290,13 @@ public Task ExecuteBatchGetAsync(params IBatchGet[] batches) #region BatchWrite async /// - public Task ExecuteBatchWriteAsync(IBatchWrite[] batches, CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteBatchWriteAsync(IBatchWrite[] batches, CancellationToken cancellationToken = default(CancellationToken)) { - MultiTableBatchWrite superBatch = new MultiTableBatchWrite(batches); - return superBatch.ExecuteAsync(cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ExecuteBatchWriteAsync))) + { + MultiTableBatchWrite superBatch = new MultiTableBatchWrite(batches); + await superBatch.ExecuteAsync(cancellationToken).ConfigureAwait(false); + } } #endregion @@ -223,10 +304,13 @@ public Task ExecuteBatchGetAsync(params IBatchGet[] batches) #region TransactGet async /// - public Task ExecuteTransactGetAsync(ITransactGet[] transactionParts, CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteTransactGetAsync(ITransactGet[] transactionParts, CancellationToken cancellationToken = default(CancellationToken)) { - MultiTableTransactGet transaction = new MultiTableTransactGet(transactionParts); - return transaction.ExecuteAsync(cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ExecuteTransactGetAsync))) + { + MultiTableTransactGet transaction = new MultiTableTransactGet(transactionParts); + await transaction.ExecuteAsync(cancellationToken).ConfigureAwait(false); + } } #endregion @@ -234,10 +318,13 @@ public Task ExecuteBatchGetAsync(params IBatchGet[] batches) #region TransactWrite async /// - public Task ExecuteTransactWriteAsync(ITransactWrite[] transactionParts, CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteTransactWriteAsync(ITransactWrite[] transactionParts, CancellationToken cancellationToken = default(CancellationToken)) { - MultiTableTransactWrite transaction = new MultiTableTransactWrite(transactionParts); - return transaction.ExecuteAsync(cancellationToken); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ExecuteTransactWriteAsync))) + { + MultiTableTransactWrite transaction = new MultiTableTransactWrite(transactionParts); + await transaction.ExecuteAsync(cancellationToken).ConfigureAwait(false); + } } #endregion @@ -247,51 +334,69 @@ public Task ExecuteBatchGetAsync(params IBatchGet[] batches) /// public IAsyncSearch ScanAsync(IEnumerable conditions) { - var scan = ConvertScan(conditions, null); - return FromSearchAsync(scan); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ScanAsync))) + { + var scan = ConvertScan(conditions, null); + return FromSearchAsync(scan); + } } /// [Obsolete("Use the ScanAsync overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to ScanAsync.")] public IAsyncSearch ScanAsync(IEnumerable conditions, DynamoDBOperationConfig operationConfig = null) { - var scan = ConvertScan(conditions, operationConfig); - return FromSearchAsync(scan); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ScanAsync))) + { + var scan = ConvertScan(conditions, operationConfig); + return FromSearchAsync(scan); + } } /// public IAsyncSearch ScanAsync(IEnumerable conditions, ScanConfig scanConfig) { - var scan = ConvertScan(conditions, scanConfig?.ToDynamoDBOperationConfig()); - return FromSearchAsync(scan); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ScanAsync))) + { + var scan = ConvertScan(conditions, scanConfig?.ToDynamoDBOperationConfig()); + return FromSearchAsync(scan); + } } /// public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig) { - if (scanConfig == null) throw new ArgumentNullException("scanConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromScanAsync))) + { + if (scanConfig == null) throw new ArgumentNullException("scanConfig"); - var search = ConvertFromScan(scanConfig, null); - return FromSearchAsync(search); + var search = ConvertFromScan(scanConfig, null); + return FromSearchAsync(search); + } } /// [Obsolete("Use the FromScanAsync overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromScanAsync.")] public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig = null) { - if (scanConfig == null) throw new ArgumentNullException("scanConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromScanAsync))) + { + if (scanConfig == null) throw new ArgumentNullException("scanConfig"); - var search = ConvertFromScan(scanConfig, operationConfig); - return FromSearchAsync(search); + var search = ConvertFromScan(scanConfig, operationConfig); + return FromSearchAsync(search); + } } /// public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, FromScanConfig fromScanConfig) { - if (scanConfig == null) throw new ArgumentNullException("scanConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromScanAsync))) + { + if (scanConfig == null) throw new ArgumentNullException("scanConfig"); - var search = ConvertFromScan(scanConfig, fromScanConfig?.ToDynamoDBOperationConfig()); - return FromSearchAsync(search); + var search = ConvertFromScan(scanConfig, fromScanConfig?.ToDynamoDBOperationConfig()); + return FromSearchAsync(search); + } } #endregion @@ -301,82 +406,109 @@ public IAsyncSearch FromScanAsync(ScanOperationConfig scanConfig, FromScan /// public IAsyncSearch QueryAsync(object hashKeyValue) { - var query = ConvertQueryByValue(hashKeyValue, null, null); - return FromSearchAsync(query); + using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) + { + var query = ConvertQueryByValue(hashKeyValue, null, null); + return FromSearchAsync(query); + } } /// [Obsolete("Use the QueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to QueryAsync.")] public IAsyncSearch QueryAsync(object hashKeyValue, DynamoDBOperationConfig operationConfig = null) { - var query = ConvertQueryByValue(hashKeyValue, null, operationConfig); - return FromSearchAsync(query); + using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) + { + var query = ConvertQueryByValue(hashKeyValue, null, operationConfig); + return FromSearchAsync(query); + } } /// public IAsyncSearch QueryAsync(object hashKeyValue, QueryConfig queryConfig) { - var query = ConvertQueryByValue(hashKeyValue, null, queryConfig?.ToDynamoDBOperationConfig()); - return FromSearchAsync(query); + using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) + { + var query = ConvertQueryByValue(hashKeyValue, null, queryConfig?.ToDynamoDBOperationConfig()); + return FromSearchAsync(query); + } } /// public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values) { - if (values == null) - throw new ArgumentNullException("values"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) + { + if (values == null) + throw new ArgumentNullException("values"); - var query = ConvertQueryByValue(hashKeyValue, op, values, null); - return FromSearchAsync(query); + var query = ConvertQueryByValue(hashKeyValue, op, values, null); + return FromSearchAsync(query); + } } /// [Obsolete("Use the QueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to QueryAsync.")] public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig = null) { - if (values == null) - throw new ArgumentNullException("values"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) + { + if (values == null) + throw new ArgumentNullException("values"); - var query = ConvertQueryByValue(hashKeyValue, op, values, operationConfig); - return FromSearchAsync(query); + var query = ConvertQueryByValue(hashKeyValue, op, values, operationConfig); + return FromSearchAsync(query); + } } /// public IAsyncSearch QueryAsync(object hashKeyValue, QueryOperator op, IEnumerable values, QueryConfig queryConfig) { - if (values == null) - throw new ArgumentNullException("values"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(QueryAsync))) + { + if (values == null) + throw new ArgumentNullException("values"); - var query = ConvertQueryByValue(hashKeyValue, op, values, queryConfig?.ToDynamoDBOperationConfig()); - return FromSearchAsync(query); + var query = ConvertQueryByValue(hashKeyValue, op, values, queryConfig?.ToDynamoDBOperationConfig()); + return FromSearchAsync(query); + } } /// public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig) { - if (queryConfig == null) throw new ArgumentNullException("queryConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromQueryAsync))) + { + if (queryConfig == null) throw new ArgumentNullException("queryConfig"); - var search = ConvertFromQuery(queryConfig, null); - return FromSearchAsync(search); + var search = ConvertFromQuery(queryConfig, null); + return FromSearchAsync(search); + } } /// [Obsolete("Use the FromQueryAsync overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromQueryAsync.")] public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig = null) { - if (queryConfig == null) throw new ArgumentNullException("queryConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromQueryAsync))) + { + if (queryConfig == null) throw new ArgumentNullException("queryConfig"); - var search = ConvertFromQuery(queryConfig, operationConfig); - return FromSearchAsync(search); + var search = ConvertFromQuery(queryConfig, operationConfig); + return FromSearchAsync(search); + } } /// public IAsyncSearch FromQueryAsync(QueryOperationConfig queryConfig, FromQueryConfig fromQueryConfig) { - if (queryConfig == null) throw new ArgumentNullException("queryConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromQueryAsync))) + { + if (queryConfig == null) throw new ArgumentNullException("queryConfig"); - var search = ConvertFromQuery(queryConfig, fromQueryConfig?.ToDynamoDBOperationConfig()); - return FromSearchAsync(search); + var search = ConvertFromQuery(queryConfig, fromQueryConfig?.ToDynamoDBOperationConfig()); + return FromSearchAsync(search); + } } #endregion diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/TransactGet.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/TransactGet.Async.cs index e970efd3e38b..a760d27b1762 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/TransactGet.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/TransactGet.Async.cs @@ -13,6 +13,7 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; using System.Threading; using System.Threading.Tasks; @@ -37,9 +38,13 @@ public abstract partial class TransactGet : ITransactGet public partial class TransactGet : TransactGet, ITransactGet { /// - public override Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(TransactGet), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } @@ -58,9 +63,13 @@ public partial interface IMultiTableTransactGet public partial class MultiTableTransactGet : IMultiTableTransactGet { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableTransactGet), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/TransactWrite.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/TransactWrite.Async.cs index 4910c851591d..1904c85d6f7f 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/TransactWrite.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_async/TransactWrite.Async.cs @@ -13,6 +13,7 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; using System.Threading; using System.Threading.Tasks; @@ -37,9 +38,13 @@ public abstract partial class TransactWrite : ITransactWrite public partial class TransactWrite : TransactWrite, ITransactWrite { /// - public override Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public override async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(TransactWrite), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } @@ -57,9 +62,13 @@ public partial interface IMultiTableTransactWrite public partial class MultiTableTransactWrite : IMultiTableTransactWrite { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableTransactWrite), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchGet.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchGet.Sync.cs index 121e45c69fbf..ee905a5c3143 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchGet.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchGet.Sync.cs @@ -13,6 +13,8 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; + namespace Amazon.DynamoDBv2.DataModel { public partial interface IBatchGet @@ -34,7 +36,11 @@ public partial class BatchGet : BatchGet, IBatchGet /// public override void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(BatchGet), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } @@ -52,7 +58,11 @@ public partial class MultiTableBatchGet : IMultiTableBatchGet /// /> public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableBatchGet), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchWrite.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchWrite.Sync.cs index 68da3b2737fd..a85fffbdc6e1 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchWrite.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/BatchWrite.Sync.cs @@ -13,6 +13,8 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; + namespace Amazon.DynamoDBv2.DataModel { public partial interface IBatchWrite @@ -37,7 +39,11 @@ public partial class BatchWrite : BatchWrite, IBatchWrite /// public override void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(BatchWrite), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } @@ -57,7 +63,11 @@ public partial class MultiTableBatchWrite : IMultiTableBatchWrite /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableBatchWrite), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/Context.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/Context.Sync.cs index 612209360b23..a3d3892053b7 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/Context.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/Context.Sync.cs @@ -15,7 +15,7 @@ using System; using System.Collections.Generic; - +using System.Linq.Expressions; using Amazon.DynamoDBv2.DocumentModel; namespace Amazon.DynamoDBv2.DataModel @@ -27,20 +27,29 @@ public partial class DynamoDBContext : IDynamoDBContext /// public void Save(T value) { - SaveHelper(value, new DynamoDBFlatConfig(null, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Save))) + { + SaveHelper(value, new DynamoDBFlatConfig(null, Config)); + } } /// [Obsolete("Use the Save overload that takes SaveConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Save.")] public void Save(T value, DynamoDBOperationConfig operationConfig = null) { - SaveHelper(value, new DynamoDBFlatConfig(operationConfig, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Save))) + { + SaveHelper(value, new DynamoDBFlatConfig(operationConfig, Config)); + } } /// public void Save(T value, SaveConfig saveConfig) { - SaveHelper(value, new DynamoDBFlatConfig(saveConfig?.ToDynamoDBOperationConfig(), Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Save))) + { + SaveHelper(value, new DynamoDBFlatConfig(saveConfig?.ToDynamoDBOperationConfig(), Config)); + } } #endregion @@ -50,58 +59,85 @@ public void Save(T value, SaveConfig saveConfig) /// public T Load(object hashKey) { - return LoadHelper(hashKey, null, new DynamoDBFlatConfig(null, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Load))) + { + return LoadHelper(hashKey, null, new DynamoDBFlatConfig(null, Config)); + } } /// [Obsolete("Use the Load overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Load.")] public T Load(object hashKey, DynamoDBOperationConfig operationConfig) { - return LoadHelper(hashKey, null, new DynamoDBFlatConfig(operationConfig, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Load))) + { + return LoadHelper(hashKey, null, new DynamoDBFlatConfig(operationConfig, Config)); + } } /// public T Load(object hashKey, LoadConfig loadConfig) { - return LoadHelper(hashKey, null, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Load))) + { + return LoadHelper(hashKey, null, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config)); + } } /// public T Load(object hashKey, object rangeKey) { - return LoadHelper(hashKey, rangeKey, new DynamoDBFlatConfig(null, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Load))) + { + return LoadHelper(hashKey, rangeKey, new DynamoDBFlatConfig(null, Config)); + } } /// [Obsolete("Use the Load overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Load.")] public T Load(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig) { - return LoadHelper(hashKey, rangeKey, new DynamoDBFlatConfig(operationConfig, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Load))) + { + return LoadHelper(hashKey, rangeKey, new DynamoDBFlatConfig(operationConfig, Config)); + } } /// public T Load(object hashKey, object rangeKey, LoadConfig loadConfig) { - return LoadHelper(hashKey, rangeKey, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Load))) + { + return LoadHelper(hashKey, rangeKey, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config)); + } } /// public T Load(T keyObject) { - return LoadHelper(keyObject, new DynamoDBFlatConfig(null, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Load))) + { + return LoadHelper(keyObject, new DynamoDBFlatConfig(null, Config)); + } } /// [Obsolete("Use the Load overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Load.")] public T Load(T keyObject, DynamoDBOperationConfig operationConfig = null) { - return LoadHelper(keyObject, new DynamoDBFlatConfig(operationConfig, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Load))) + { + return LoadHelper(keyObject, new DynamoDBFlatConfig(operationConfig, Config)); + } } /// public T Load(T keyObject, LoadConfig loadConfig) { - return LoadHelper(keyObject, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Load))) + { + return LoadHelper(keyObject, new DynamoDBFlatConfig(loadConfig?.ToDynamoDBOperationConfig(), Config)); + } } #endregion @@ -111,59 +147,86 @@ public T Load(T keyObject, LoadConfig loadConfig) /// public void Delete(T value) { - DeleteHelper(value, new DynamoDBFlatConfig(null, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Delete))) + { + DeleteHelper(value, new DynamoDBFlatConfig(null, Config)); + } } /// [Obsolete("Use the Delete overload that takes LoadConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Delete.")] public void Delete(T value, DynamoDBOperationConfig operationConfig) { - DeleteHelper(value, new DynamoDBFlatConfig(operationConfig, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Delete))) + { + DeleteHelper(value, new DynamoDBFlatConfig(operationConfig, Config)); + } } /// public void Delete(T value, DeleteConfig deleteConfig) { - DeleteHelper(value, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Delete))) + { + DeleteHelper(value, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config)); + } } /// /// Hash key element of the object to delete. public void Delete(object hashKey) { - DeleteHelper(hashKey, null, new DynamoDBFlatConfig(null, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Delete))) + { + DeleteHelper(hashKey, null, new DynamoDBFlatConfig(null, Config)); + } } /// [Obsolete("Use the Delete overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Delete.")] public void Delete(object hashKey, DynamoDBOperationConfig operationConfig) { - DeleteHelper(hashKey, null, new DynamoDBFlatConfig(operationConfig, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Delete))) + { + DeleteHelper(hashKey, null, new DynamoDBFlatConfig(operationConfig, Config)); + } } /// public void Delete(object hashKey, DeleteConfig deleteConfig) { - DeleteHelper(hashKey, null, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Delete))) + { + DeleteHelper(hashKey, null, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config)); + } } /// public void Delete(object hashKey, object rangeKey) { - DeleteHelper(hashKey, rangeKey, new DynamoDBFlatConfig(null, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Delete))) + { + DeleteHelper(hashKey, rangeKey, new DynamoDBFlatConfig(null, Config)); + } } /// [Obsolete("Use the Delete overload that takes DeleteConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Delete.")] public void Delete(object hashKey, object rangeKey, DynamoDBOperationConfig operationConfig) { - DeleteHelper(hashKey, rangeKey, new DynamoDBFlatConfig(operationConfig, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Delete))) + { + DeleteHelper(hashKey, rangeKey, new DynamoDBFlatConfig(operationConfig, Config)); + } } /// public void Delete(object hashKey, object rangeKey, DeleteConfig deleteConfig) { - DeleteHelper(hashKey, rangeKey, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Delete))) + { + DeleteHelper(hashKey, rangeKey, new DynamoDBFlatConfig(deleteConfig?.ToDynamoDBOperationConfig(), Config)); + } } #endregion @@ -172,8 +235,11 @@ public void Delete(object hashKey, object rangeKey, DeleteConfig deleteConfig /// public void ExecuteBatchGet(params IBatchGet[] batches) { - MultiTableBatchGet superBatch = new MultiTableBatchGet(batches); - superBatch.Execute(); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ExecuteBatchGet))) + { + MultiTableBatchGet superBatch = new MultiTableBatchGet(batches); + superBatch.Execute(); + } } #endregion @@ -183,8 +249,11 @@ public void ExecuteBatchGet(params IBatchGet[] batches) /// public void ExecuteTransactGet(params ITransactGet[] transactionParts) { - MultiTableTransactGet transaction = new MultiTableTransactGet(transactionParts); - transaction.Execute(); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ExecuteTransactGet))) + { + MultiTableTransactGet transaction = new MultiTableTransactGet(transactionParts); + transaction.Execute(); + } } #endregion @@ -194,8 +263,11 @@ public void ExecuteTransactGet(params ITransactGet[] transactionParts) /// public void ExecuteBatchWrite(params IBatchWrite[] batches) { - MultiTableBatchWrite superBatch = new MultiTableBatchWrite(batches); - superBatch.Execute(); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ExecuteBatchWrite))) + { + MultiTableBatchWrite superBatch = new MultiTableBatchWrite(batches); + superBatch.Execute(); + } } #endregion @@ -205,8 +277,11 @@ public void ExecuteBatchWrite(params IBatchWrite[] batches) /// public void ExecuteTransactWrite(params ITransactWrite[] transactionParts) { - MultiTableTransactWrite transaction = new MultiTableTransactWrite(transactionParts); - transaction.Execute(); + using (DynamoDBTelemetry.CreateSpan(this, nameof(ExecuteTransactWrite))) + { + MultiTableTransactWrite transaction = new MultiTableTransactWrite(transactionParts); + transaction.Execute(); + } } #endregion @@ -216,50 +291,68 @@ public void ExecuteTransactWrite(params ITransactWrite[] transactionParts) /// public IEnumerable Scan(params ScanCondition[] conditions) { - return Scan(conditions, (ScanConfig)null); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Scan))) + { + return Scan(conditions, (ScanConfig)null); + } } /// [Obsolete("Use the Scan overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Scan.")] public IEnumerable Scan(IEnumerable conditions, DynamoDBOperationConfig operationConfig) { - var scan = ConvertScan(conditions, operationConfig); - return FromSearch(scan); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Scan))) + { + var scan = ConvertScan(conditions, operationConfig); + return FromSearch(scan); + } } /// public IEnumerable Scan(IEnumerable conditions, ScanConfig scanConfig) { - var scan = ConvertScan(conditions, scanConfig?.ToDynamoDBOperationConfig()); - return FromSearch(scan); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Scan))) + { + var scan = ConvertScan(conditions, scanConfig?.ToDynamoDBOperationConfig()); + return FromSearch(scan); + } } /// public IEnumerable FromScan(ScanOperationConfig scanConfig) { - if (scanConfig == null) throw new ArgumentNullException("scanConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromScan))) + { + if (scanConfig == null) throw new ArgumentNullException(nameof(scanConfig)); - var search = ConvertFromScan(scanConfig, null); - return FromSearch(search); + var search = ConvertFromScan(scanConfig, null); + return FromSearch(search); + } } /// [Obsolete("Use the FromScan overload that takes ScanConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromScan.")] public IEnumerable FromScan(ScanOperationConfig scanConfig, DynamoDBOperationConfig operationConfig = null) { - if (scanConfig == null) throw new ArgumentNullException("scanConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromScan))) + { + if (scanConfig == null) throw new ArgumentNullException(nameof(scanConfig)); - var search = ConvertFromScan(scanConfig, operationConfig); - return FromSearch(search); + var search = ConvertFromScan(scanConfig, operationConfig); + return FromSearch(search); + } } /// public IEnumerable FromScan(ScanOperationConfig scanConfig, FromScanConfig fromScanConfig) { - if (scanConfig == null) throw new ArgumentNullException("scanConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromScan))) + { + if (scanConfig == null) throw new ArgumentNullException(nameof(scanConfig)); - var search = ConvertFromScan(scanConfig, fromScanConfig?.ToDynamoDBOperationConfig()); - return FromSearch(search); + var search = ConvertFromScan(scanConfig, fromScanConfig?.ToDynamoDBOperationConfig()); + return FromSearch(search); + } } #endregion @@ -269,78 +362,105 @@ public IEnumerable FromScan(ScanOperationConfig scanConfig, FromScanConfig /// public IEnumerable Query(object hashKeyValue) { - var query = ConvertQueryByValue(hashKeyValue, null, null); - return FromSearch(query); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Query))) + { + var query = ConvertQueryByValue(hashKeyValue, null, null); + return FromSearch(query); + } } /// [Obsolete("Use the Query overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Query.")] public IEnumerable Query(object hashKeyValue, DynamoDBOperationConfig operationConfig) { - var query = ConvertQueryByValue(hashKeyValue, null, operationConfig); - return FromSearch(query); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Query))) + { + var query = ConvertQueryByValue(hashKeyValue, null, operationConfig); + return FromSearch(query); + } } /// public IEnumerable Query(object hashKeyValue, QueryConfig queryConfig) { - var query = ConvertQueryByValue(hashKeyValue, null, queryConfig?.ToDynamoDBOperationConfig()); - return FromSearch(query); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Query))) + { + var query = ConvertQueryByValue(hashKeyValue, null, queryConfig?.ToDynamoDBOperationConfig()); + return FromSearch(query); + } } /// public IEnumerable Query(object hashKeyValue, QueryOperator op, params object[] values) { - if (values == null || values.Length == 0) - throw new ArgumentOutOfRangeException("values"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Query))) + { + if (values == null || values.Length == 0) + throw new ArgumentOutOfRangeException(nameof(values)); - return Query(hashKeyValue, op, values, (QueryConfig)null); + return Query(hashKeyValue, op, values, (QueryConfig)null); + } } /// [Obsolete("Use the Query overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to Query.")] public IEnumerable Query(object hashKeyValue, QueryOperator op, IEnumerable values, DynamoDBOperationConfig operationConfig) { - if (values == null) - throw new ArgumentNullException("values"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Query))) + { + if (values == null) + throw new ArgumentNullException(nameof(values)); - var query = ConvertQueryByValue(hashKeyValue, op, values, operationConfig); - return FromSearch(query); + var query = ConvertQueryByValue(hashKeyValue, op, values, operationConfig); + return FromSearch(query); + } } /// public IEnumerable Query(object hashKeyValue, QueryOperator op, IEnumerable values, QueryConfig queryConfig) { - if (values == null) - throw new ArgumentNullException("values"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(Query))) + { + if (values == null) + throw new ArgumentNullException(nameof(values)); - var query = ConvertQueryByValue(hashKeyValue, op, values, queryConfig?.ToDynamoDBOperationConfig()); - return FromSearch(query); + var query = ConvertQueryByValue(hashKeyValue, op, values, queryConfig?.ToDynamoDBOperationConfig()); + return FromSearch(query); + } } /// public IEnumerable FromQuery(QueryOperationConfig queryConfig) { - return FromQuery(queryConfig, (FromQueryConfig)null); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromQuery))) + { + return FromQuery(queryConfig, (FromQueryConfig)null); + } } /// [Obsolete("Use the FromQuery overload that takes QueryConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to FromQuery.")] public IEnumerable FromQuery(QueryOperationConfig queryConfig, DynamoDBOperationConfig operationConfig) { - if (queryConfig == null) throw new ArgumentNullException("queryConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromQuery))) + { + if (queryConfig == null) throw new ArgumentNullException(nameof(queryConfig)); - var search = ConvertFromQuery(queryConfig, operationConfig); - return FromSearch(search); + var search = ConvertFromQuery(queryConfig, operationConfig); + return FromSearch(search); + } } /// public IEnumerable FromQuery(QueryOperationConfig queryConfig, FromQueryConfig fromQueryConfig) { - if (queryConfig == null) throw new ArgumentNullException("queryConfig"); + using (DynamoDBTelemetry.CreateSpan(this, nameof(FromQuery))) + { + if (queryConfig == null) throw new ArgumentNullException(nameof(queryConfig)); - var search = ConvertFromQuery(queryConfig, fromQueryConfig?.ToDynamoDBOperationConfig()); - return FromSearch(search); + var search = ConvertFromQuery(queryConfig, fromQueryConfig?.ToDynamoDBOperationConfig()); + return FromSearch(search); + } } #endregion @@ -350,20 +470,29 @@ public IEnumerable FromQuery(QueryOperationConfig queryConfig, FromQueryCo /// public ITable GetTargetTable() { - return GetTargetTable((GetTargetTableConfig)null); + using (DynamoDBTelemetry.CreateSpan(this, nameof(GetTargetTable))) + { + return GetTargetTable((GetTargetTableConfig)null); + } } /// [Obsolete("Use the GetTargetTable overload that takes GetTargetTableConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to GetTargetTable.")] public ITable GetTargetTable(DynamoDBOperationConfig operationConfig = null) { - return GetTargetTableInternal(new DynamoDBFlatConfig(operationConfig, Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(GetTargetTable))) + { + return GetTargetTableInternal(new DynamoDBFlatConfig(operationConfig, Config)); + } } /// public ITable GetTargetTable(GetTargetTableConfig getTargetTableConfig) { - return GetTargetTableInternal(new DynamoDBFlatConfig(getTargetTableConfig?.ToDynamoDBOperationConfig(), Config)); + using (DynamoDBTelemetry.CreateSpan(this, nameof(GetTargetTable))) + { + return GetTargetTableInternal(new DynamoDBFlatConfig(getTargetTableConfig?.ToDynamoDBOperationConfig(), Config)); + } } #endregion diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/TransactGet.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/TransactGet.Sync.cs index a964b8f79c24..492f5542f824 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/TransactGet.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/TransactGet.Sync.cs @@ -13,6 +13,8 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; + namespace Amazon.DynamoDBv2.DataModel { public partial interface ITransactGet @@ -34,7 +36,11 @@ public partial class TransactGet : TransactGet, ITransactGet /// public override void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(TransactGet), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } @@ -52,7 +58,11 @@ public partial class MultiTableTransactGet /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableTransactGet), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/TransactWrite.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/TransactWrite.Sync.cs index 4b166e850d38..4ccc1203f92d 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/TransactWrite.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/_bcl/TransactWrite.Sync.cs @@ -13,6 +13,8 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; + namespace Amazon.DynamoDBv2.DataModel { public partial interface ITransactWrite @@ -34,7 +36,11 @@ public partial class TransactWrite : TransactWrite, ITransactWrite /// public override void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(TransactWrite), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } @@ -51,7 +57,11 @@ public partial class MultiTableTransactWrite : IMultiTableTransactWrite /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableTransactWrite), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentBatchGet.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentBatchGet.cs index aed84740d092..0529f34635e4 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentBatchGet.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentBatchGet.cs @@ -21,6 +21,7 @@ using System.Threading.Tasks; #endif using Amazon.DynamoDBv2.Model; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DocumentModel { @@ -90,6 +91,7 @@ public partial class DocumentBatchGet : IDocumentBatchGet internal Table TargetTable { get; private set; } internal List Keys { get; private set; } + internal TracerProvider TracerProvider { get; private set; } #endregion @@ -121,6 +123,8 @@ public DocumentBatchGet(Table targetTable) { TargetTable = targetTable; Keys = new List(); + TracerProvider = targetTable?.DDBClient?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } #endregion @@ -242,6 +246,8 @@ public partial class MultiTableDocumentBatchGet : IMultiTableDocumentBatchGet { #region Properties + internal TracerProvider TracerProvider { get; private set; } + /// public List Batches { get; private set; } @@ -275,6 +281,7 @@ public MultiTableDocumentBatchGet(params IDocumentBatchGet[] batches) throw new ArgumentNullException("batches"); Batches = new List(batches); + TracerProvider = GetTracerProvider(Batches); } #endregion @@ -295,7 +302,7 @@ public void AddBatch(IDocumentBatchGet batch) internal void ExecuteHelper() { var errMsg = $"All {nameof(IDocumentBatchGet)} objects must be of type {nameof(DocumentBatchGet)}"; - var docBatches = Batches.Select( x => x as DocumentBatchGet ?? throw new InvalidOperationException(errMsg)).ToList(); + var docBatches = Batches.Select(x => x as DocumentBatchGet ?? throw new InvalidOperationException(errMsg)).ToList(); MultiBatchGet resultsObject = new MultiBatchGet { Batches = docBatches @@ -345,6 +352,19 @@ internal async Task ExecuteHelperAsync(CancellationToken cancellationToken) #endif #endregion + + private TracerProvider GetTracerProvider(List batches) + { + var tracerProvider = AWSConfigs.TelemetryProvider.TracerProvider; + if (batches.Count > 0) + { + if (batches[0] is DocumentBatchGet documentBatchGet) + { + tracerProvider = documentBatchGet.TracerProvider; + } + } + return tracerProvider; + } } /// diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentBatchWrite.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentBatchWrite.cs index 63122f863ab9..e280fb707608 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentBatchWrite.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentBatchWrite.cs @@ -22,6 +22,7 @@ using System.Threading.Tasks; #endif using Amazon.DynamoDBv2.Model; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DocumentModel { @@ -83,6 +84,7 @@ public partial class DocumentBatchWrite : IDocumentBatchWrite internal Table TargetTable { get; private set; } internal List ToDelete { get; private set; } internal List ToPut { get; private set; } + internal TracerProvider TracerProvider { get; private set; } #endregion @@ -98,6 +100,8 @@ public DocumentBatchWrite(Table targetTable) TargetTable = targetTable; ToDelete = new List(); ToPut = new List(); + TracerProvider = targetTable?.DDBClient?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } #endregion @@ -209,6 +213,8 @@ public partial class MultiTableDocumentBatchWrite : IMultiTableDocumentBatchWrit { #region Properties + internal TracerProvider TracerProvider { get; private set; } + /// public List Batches { get; private set; } @@ -228,6 +234,7 @@ public MultiTableDocumentBatchWrite(params IDocumentBatchWrite[] batches) throw new ArgumentNullException("batches"); Batches = new List(batches); + TracerProvider = GetTracerProvider(Batches); } #endregion @@ -269,6 +276,19 @@ internal Task ExecuteHelperAsync(CancellationToken cancellationToken) #endif #endregion + + private TracerProvider GetTracerProvider(List batches) + { + var tracerProvider = AWSConfigs.TelemetryProvider.TracerProvider; + if (batches.Count > 0) + { + if (batches[0] is DocumentBatchWrite documentBatchWrite) + { + tracerProvider = documentBatchWrite.TracerProvider; + } + } + return tracerProvider; + } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentTransactGet.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentTransactGet.cs index 8a77e44bf89e..9f0ac419f402 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentTransactGet.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentTransactGet.cs @@ -21,6 +21,7 @@ using System.Threading.Tasks; #endif using Amazon.DynamoDBv2.Model; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DocumentModel { @@ -108,6 +109,7 @@ public partial class DocumentTransactGet : IDocumentTransactGet internal Table TargetTable { get; private set; } internal List Items { get; private set; } + internal TracerProvider TracerProvider { get; private set; } #endregion @@ -130,6 +132,8 @@ public DocumentTransactGet(Table targetTable) { TargetTable = targetTable; Items = new List(); + TracerProvider = targetTable?.DDBClient?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } #endregion @@ -244,6 +248,8 @@ public partial class MultiTableDocumentTransactGet : IMultiTableDocumentTransact { #region Properties + internal TracerProvider TracerProvider { get; private set; } + /// public List TransactionParts { get; private set; } @@ -263,6 +269,7 @@ public MultiTableDocumentTransactGet(params IDocumentTransactGet[] transactionPa throw new ArgumentNullException(nameof(transactionParts)); TransactionParts = new List(transactionParts); + TracerProvider = GetTracerProvider(TransactionParts); } #endregion @@ -322,6 +329,19 @@ private MultiTransactGet GetMultiTransactGet() }; } + private TracerProvider GetTracerProvider(List batches) + { + var tracerProvider = AWSConfigs.TelemetryProvider.TracerProvider; + if (batches.Count > 0) + { + if (batches[0] is DocumentTransactGet documentTransactGet) + { + tracerProvider = documentTransactGet.TracerProvider; + } + } + return tracerProvider; + } + #endregion } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentTransactWrite.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentTransactWrite.cs index 3ec32bd4c5b8..f58f23e4aefc 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentTransactWrite.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentTransactWrite.cs @@ -21,6 +21,7 @@ using System.Threading.Tasks; #endif using Amazon.DynamoDBv2.Model; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DocumentModel { @@ -213,6 +214,7 @@ public partial class DocumentTransactWrite : IDocumentTransactWrite internal Table TargetTable { get; private set; } internal List Items { get; private set; } + internal TracerProvider TracerProvider { get; private set; } #endregion @@ -232,6 +234,8 @@ public DocumentTransactWrite(Table targetTable) { TargetTable = targetTable; Items = new List(); + TracerProvider = targetTable?.DDBClient?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } #endregion @@ -564,6 +568,8 @@ public partial class MultiTableDocumentTransactWrite : IMultiTableDocumentTransa { #region Properties + internal TracerProvider TracerProvider { get; private set; } + /// public List TransactionParts { get; private set; } @@ -583,6 +589,7 @@ public MultiTableDocumentTransactWrite(params IDocumentTransactWrite[] transacti throw new ArgumentNullException(nameof(transactionParts)); TransactionParts = new List(transactionParts); + TracerProvider = GetTracerProvider(TransactionParts); } #endregion @@ -654,6 +661,19 @@ private MultiTransactWrite GetMultiTransactWrite() }; } + private TracerProvider GetTracerProvider(List batches) + { + var tracerProvider = AWSConfigs.TelemetryProvider.TracerProvider; + if (batches.Count > 0) + { + if (batches[0] is DocumentBatchWrite documentTransactWrite) + { + tracerProvider = documentTransactWrite.TracerProvider; + } + } + return tracerProvider; + } + #endregion } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Search.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Search.cs index 5a1ef0114715..1b6b6d8c10b7 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Search.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Search.cs @@ -19,6 +19,8 @@ using Amazon.DynamoDBv2.Model; using System.Globalization; +using Amazon.Runtime.Telemetry.Tracing; + #if AWS_ASYNC_API using System.Threading.Tasks; #endif @@ -191,6 +193,8 @@ internal Search(SearchType searchMethod) { SearchMethod = searchMethod; Reset(); + TracerProvider = SourceTable?.DDBClient?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } #endregion @@ -270,6 +274,8 @@ internal set #region Private/internal members + internal TracerProvider TracerProvider { get; private set; } + internal List GetNextSetHelper() { List ret = new List(); diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Table.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Table.cs index 7c67a4b0a281..7e46d20ef477 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Table.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Table.cs @@ -27,6 +27,7 @@ using System.Globalization; using Amazon.DynamoDBv2.DataModel; using Amazon.Runtime.Internal.Util; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DocumentModel { @@ -270,6 +271,7 @@ internal enum DynamoDBConsumer internal IEnumerable StoreAsEpoch { get { return Config.AttributesToStoreAsEpoch; } } internal IEnumerable KeyNames { get { return Keys.Keys; } } internal IAmazonDynamoDB DDBClient { get; private set; } + internal TracerProvider TracerProvider { get; private set; } #endregion @@ -619,6 +621,8 @@ internal Table(IAmazonDynamoDB ddbClient, TableConfig config) DDBClient = ddbClient; Config = config; + TracerProvider = DDBClient?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; } @@ -643,10 +647,15 @@ public static void ClearTableCache() [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static ITable LoadTable(IAmazonDynamoDB ddbClient, TableConfig config) { - Table table = new Table(ddbClient, config); - var tableDescriptionCache = table.GetTableDescriptionCache(); - table.LoadTableInfo(tableDescriptionCache); - return table; + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(LoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + Table table = new Table(ddbClient, config); + var tableDescriptionCache = table.GetTableDescriptionCache(); + table.LoadTableInfo(tableDescriptionCache); + return table; + } } /// @@ -849,7 +858,12 @@ internal static Table CreateTableFromItemStorageConfig(IAmazonDynamoDB client, T [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName) { - return LoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, false); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(LoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return LoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, false); + } } /// @@ -865,7 +879,12 @@ public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName) [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion) { - return LoadTable(ddbClient, tableName, conversion, false); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(LoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return LoadTable(ddbClient, tableName, conversion, false); + } } /// @@ -881,7 +900,12 @@ public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName, Dyna [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName, bool isEmptyStringValueEnabled) { - return LoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, isEmptyStringValueEnabled); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(LoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return LoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, isEmptyStringValueEnabled); + } } /// @@ -898,9 +922,14 @@ public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName, bool [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, bool isEmptyStringValueEnabled) { - var config = new TableConfig(tableName, conversion, DynamoDBConsumer.DocumentModel, storeAsEpoch: null, isEmptyStringValueEnabled: isEmptyStringValueEnabled, metadataCachingMode: MetadataCachingMode.Default); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(LoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + var config = new TableConfig(tableName, conversion, DynamoDBConsumer.DocumentModel, storeAsEpoch: null, isEmptyStringValueEnabled: isEmptyStringValueEnabled, metadataCachingMode: MetadataCachingMode.Default); - return LoadTable(ddbClient, config); + return LoadTable(ddbClient, config); + } } /// @@ -920,9 +949,14 @@ public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName, Dyna [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, bool isEmptyStringValueEnabled, MetadataCachingMode metadataCachingMode) { - var config = new TableConfig(tableName, conversion, DynamoDBConsumer.DocumentModel, storeAsEpoch: null, isEmptyStringValueEnabled: isEmptyStringValueEnabled, metadataCachingMode: metadataCachingMode); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(LoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + var config = new TableConfig(tableName, conversion, DynamoDBConsumer.DocumentModel, storeAsEpoch: null, isEmptyStringValueEnabled: isEmptyStringValueEnabled, metadataCachingMode: metadataCachingMode); - return LoadTable(ddbClient, config); + return LoadTable(ddbClient, config); + } } /// @@ -942,7 +976,12 @@ public static ITable LoadTable(IAmazonDynamoDB ddbClient, string tableName, Dyna [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, out ITable table) { - return TryLoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, false, out table); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryLoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return TryLoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, false, out table); + } } /// @@ -961,7 +1000,12 @@ public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, out [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, out ITable table) { - return TryLoadTable(ddbClient, tableName, conversion, false, out table); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryLoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return TryLoadTable(ddbClient, tableName, conversion, false, out table); + } } /// @@ -980,7 +1024,12 @@ public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, Dyn [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, bool isEmptyStringValueEnabled, out ITable table) { - return TryLoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, isEmptyStringValueEnabled, out table); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryLoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return TryLoadTable(ddbClient, tableName, DynamoDBEntryConversion.CurrentConversion, isEmptyStringValueEnabled, out table); + } } /// @@ -1000,7 +1049,13 @@ public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, boo [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static bool TryLoadTable(IAmazonDynamoDB ddbClient, string tableName, DynamoDBEntryConversion conversion, bool isEmptyStringValueEnabled, out ITable table) { - return TryLoadTable(ddbClient, tableName, conversion, isEmptyStringValueEnabled, MetadataCachingMode.Default, out table); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryLoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return TryLoadTable(ddbClient, tableName, conversion, isEmptyStringValueEnabled, MetadataCachingMode.Default, out table); + } + } /// @@ -1028,14 +1083,19 @@ public static bool TryLoadTable(IAmazonDynamoDB ddbClient, MetadataCachingMode? metadataCachingMode, out ITable table) { - var config = new TableConfig(tableName, + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryLoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + var config = new TableConfig(tableName, conversion, DynamoDBConsumer.DocumentModel, storeAsEpoch: null, isEmptyStringValueEnabled: isEmptyStringValueEnabled, metadataCachingMode: metadataCachingMode); - return TryLoadTable(ddbClient, config, out table); + return TryLoadTable(ddbClient, config, out table); + } } /// @@ -1053,21 +1113,26 @@ public static bool TryLoadTable(IAmazonDynamoDB ddbClient, [Obsolete("Use the TableBuilder to construct a Table with the recommended configuration.")] public static bool TryLoadTable(IAmazonDynamoDB ddbClient, TableConfig config, out ITable table) { - if (config == null) - throw new ArgumentNullException("config"); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryLoadTable)); + var tracerProvider = ddbClient.Config.TelemetryProvider.TracerProvider; + using (DynamoDBTelemetry.CreateSpan(tracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + if (config == null) + throw new ArgumentNullException(nameof(config)); #pragma warning disable CA1031 // Do not catch general exception types - try - { - table = LoadTable(ddbClient, config); - return true; - } - catch - { - table = null; - return false; - } + try + { + table = LoadTable(ddbClient, config); + return true; + } + catch + { + table = null; + return false; + } #pragma warning restore CA1031 // Do not catch general exception types + } } #endregion diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentBatchGet.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentBatchGet.Async.cs index a0ef642ab898..ed2a5a0c36f9 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentBatchGet.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentBatchGet.Async.cs @@ -14,6 +14,7 @@ */ #pragma warning disable 1574 +using Amazon.Runtime.Telemetry.Tracing; using System.Threading; using System.Threading.Tasks; @@ -33,9 +34,13 @@ public partial interface IDocumentBatchGet public partial class DocumentBatchGet : IDocumentBatchGet { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(DocumentBatchGet), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } @@ -53,9 +58,13 @@ public partial interface IMultiTableDocumentBatchGet public partial class MultiTableDocumentBatchGet : IMultiTableDocumentBatchGet { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableDocumentBatchGet), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentBatchWrite.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentBatchWrite.Async.cs index aa791aceb1e8..eec9dd5b7da4 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentBatchWrite.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentBatchWrite.Async.cs @@ -14,6 +14,7 @@ */ #pragma warning disable 1574 +using Amazon.Runtime.Telemetry.Tracing; using System.Threading; using System.Threading.Tasks; @@ -35,9 +36,15 @@ public partial interface IDocumentBatchWrite public partial class DocumentBatchWrite : IDocumentBatchWrite { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + { + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(DocumentBatchWrite), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } + } } } @@ -57,9 +64,15 @@ public partial interface IMultiTableDocumentBatchWrite public partial class MultiTableDocumentBatchWrite : IMultiTableDocumentBatchWrite { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + { + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableDocumentBatchWrite), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentTransactGet.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentTransactGet.Async.cs index 3a3a3239c3ca..b50b371153d8 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentTransactGet.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentTransactGet.Async.cs @@ -13,6 +13,7 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; using System.Threading; using System.Threading.Tasks; @@ -36,9 +37,13 @@ public partial interface IDocumentTransactGet public partial class DocumentTransactGet : IDocumentTransactGet { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(DocumentTransactGet), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } @@ -56,9 +61,13 @@ public partial interface IMultiTableDocumentTransactGet public partial class MultiTableDocumentTransactGet : IMultiTableDocumentTransactGet { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableDocumentTransactGet), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentTransactWrite.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentTransactWrite.Async.cs index 18b39e01c350..dee87f4f792e 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentTransactWrite.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/DocumentTransactWrite.Async.cs @@ -13,6 +13,7 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; using System.Threading; using System.Threading.Tasks; @@ -31,9 +32,13 @@ public partial interface IDocumentTransactWrite public partial class DocumentTransactWrite : IDocumentTransactWrite { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(DocumentTransactWrite), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } @@ -50,9 +55,13 @@ public partial interface IMultiTableDocumentTransactWrite public partial class MultiTableDocumentTransactWrite : IMultiTableDocumentTransactWrite { /// - public Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return ExecuteHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableDocumentTransactWrite), nameof(ExecuteAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + await ExecuteHelperAsync(cancellationToken).ConfigureAwait(false); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/Search.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/Search.Async.cs index 575fafe3b4f2..1a733b30904e 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/Search.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/Search.Async.cs @@ -14,6 +14,7 @@ */ #pragma warning disable 1574 +using Amazon.Runtime.Telemetry.Tracing; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -46,15 +47,23 @@ public partial interface ISearch public partial class Search : ISearch { /// - public Task> GetNextSetAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task> GetNextSetAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return GetNextSetHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Search), nameof(GetNextSetAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await GetNextSetHelperAsync(cancellationToken).ConfigureAwait(false); + } } /// - public Task> GetRemainingAsync(CancellationToken cancellationToken = default(CancellationToken)) + public async Task> GetRemainingAsync(CancellationToken cancellationToken = default(CancellationToken)) { - return GetRemainingHelperAsync(cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Search), nameof(GetRemainingAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await GetRemainingHelperAsync(cancellationToken).ConfigureAwait(false); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/Table.Async.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/Table.Async.cs index adca09ba7bef..63b37ad4165b 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/Table.Async.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_async/Table.Async.cs @@ -25,6 +25,7 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; using Amazon.Runtime.Internal; +using Amazon.Runtime.Telemetry.Tracing; namespace Amazon.DynamoDBv2.DocumentModel { @@ -271,16 +272,24 @@ public partial class Table : ITable #region PutItemAsync /// - public Task PutItemAsync(Document doc, CancellationToken cancellationToken = default(CancellationToken)) + public async Task PutItemAsync(Document doc, CancellationToken cancellationToken = default(CancellationToken)) { - return PutItemHelperAsync(doc, null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(PutItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await PutItemHelperAsync(doc, null, cancellationToken).ConfigureAwait(false); + } } /// - public Task PutItemAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task PutItemAsync(Document doc, PutItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return PutItemHelperAsync(doc, config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(PutItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await PutItemHelperAsync(doc, config, cancellationToken).ConfigureAwait(false); + } } #endregion @@ -288,40 +297,64 @@ public partial class Table : ITable #region GetItemAsync /// - public Task GetItemAsync(Primitive hashKey, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetItemAsync(Primitive hashKey, CancellationToken cancellationToken = default(CancellationToken)) { - return GetItemHelperAsync(MakeKey(hashKey, null), null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(GetItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await GetItemHelperAsync(MakeKey(hashKey, null), null, cancellationToken).ConfigureAwait(false); + } } /// - public Task GetItemAsync(Primitive hashKey, GetItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetItemAsync(Primitive hashKey, GetItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return GetItemHelperAsync(MakeKey(hashKey, null), config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(GetItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await GetItemHelperAsync(MakeKey(hashKey, null), config, cancellationToken).ConfigureAwait(false); + } } /// - public Task GetItemAsync(Primitive hashKey, Primitive rangeKey, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetItemAsync(Primitive hashKey, Primitive rangeKey, CancellationToken cancellationToken = default(CancellationToken)) { - return GetItemHelperAsync(MakeKey(hashKey, rangeKey), null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(GetItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await GetItemHelperAsync(MakeKey(hashKey, rangeKey), null, cancellationToken).ConfigureAwait(false); + } } /// - public Task GetItemAsync(Primitive hashKey, Primitive rangeKey, GetItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetItemAsync(Primitive hashKey, Primitive rangeKey, GetItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return GetItemHelperAsync(MakeKey(hashKey, rangeKey), config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(GetItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await GetItemHelperAsync(MakeKey(hashKey, rangeKey), config, cancellationToken).ConfigureAwait(false); + } } /// - public Task GetItemAsync(IDictionary key, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetItemAsync(IDictionary key, CancellationToken cancellationToken = default(CancellationToken)) { - return GetItemHelperAsync(MakeKey(key), null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(GetItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await GetItemHelperAsync(MakeKey(key), null, cancellationToken).ConfigureAwait(false); + } } /// - public Task GetItemAsync(IDictionary key, GetItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task GetItemAsync(IDictionary key, GetItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return GetItemHelperAsync(MakeKey(key), config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(GetItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await GetItemHelperAsync(MakeKey(key), config, cancellationToken).ConfigureAwait(false); + } } #endregion @@ -329,51 +362,83 @@ public partial class Table : ITable #region UpdateItemAsync /// - public Task UpdateItemAsync(Document doc, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpdateItemAsync(Document doc, CancellationToken cancellationToken = default(CancellationToken)) { - return UpdateHelperAsync(doc, null, null, null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await UpdateHelperAsync(doc, null, null, null, cancellationToken).ConfigureAwait(false); + } } /// - public Task UpdateItemAsync(Document doc, UpdateItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpdateItemAsync(Document doc, UpdateItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return UpdateHelperAsync(doc, null, null, config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await UpdateHelperAsync(doc, null, null, config, cancellationToken).ConfigureAwait(false); + } } /// - public Task UpdateItemAsync(Document doc, IDictionary key, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpdateItemAsync(Document doc, IDictionary key, CancellationToken cancellationToken = default(CancellationToken)) { - return UpdateHelperAsync(doc, MakeKey(key), null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await UpdateHelperAsync(doc, MakeKey(key), null, cancellationToken).ConfigureAwait(false); + } } /// - public Task UpdateItemAsync(Document doc, IDictionary key, UpdateItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpdateItemAsync(Document doc, IDictionary key, UpdateItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return UpdateHelperAsync(doc, MakeKey(key), config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await UpdateHelperAsync(doc, MakeKey(key), config, cancellationToken).ConfigureAwait(false); + } } /// - public Task UpdateItemAsync(Document doc, Primitive hashKey, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpdateItemAsync(Document doc, Primitive hashKey, CancellationToken cancellationToken = default(CancellationToken)) { - return UpdateHelperAsync(doc, hashKey, null, null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await UpdateHelperAsync(doc, hashKey, null, null, cancellationToken).ConfigureAwait(false); + } } /// - public Task UpdateItemAsync(Document doc, Primitive hashKey, UpdateItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpdateItemAsync(Document doc, Primitive hashKey, UpdateItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return UpdateHelperAsync(doc, hashKey, null, config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await UpdateHelperAsync(doc, hashKey, null, config, cancellationToken).ConfigureAwait(false); + } } /// - public Task UpdateItemAsync(Document doc, Primitive hashKey, Primitive rangeKey, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpdateItemAsync(Document doc, Primitive hashKey, Primitive rangeKey, CancellationToken cancellationToken = default(CancellationToken)) { - return UpdateHelperAsync(doc, hashKey, rangeKey, null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await UpdateHelperAsync(doc, hashKey, rangeKey, null, cancellationToken).ConfigureAwait(false); + } } /// - public Task UpdateItemAsync(Document doc, Primitive hashKey, Primitive rangeKey, UpdateItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task UpdateItemAsync(Document doc, Primitive hashKey, Primitive rangeKey, UpdateItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return UpdateHelperAsync(doc, hashKey, rangeKey, config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await UpdateHelperAsync(doc, hashKey, rangeKey, config, cancellationToken).ConfigureAwait(false); + } } @@ -382,53 +447,85 @@ public partial class Table : ITable #region DeleteItemAsync /// - public Task DeleteItemAsync(Document document, CancellationToken cancellationToken = default(CancellationToken)) + public async Task DeleteItemAsync(Document document, CancellationToken cancellationToken = default(CancellationToken)) { - return DeleteHelperAsync(MakeKey(document), null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await DeleteHelperAsync(MakeKey(document), null, cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteItemAsync(Document document, DeleteItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task DeleteItemAsync(Document document, DeleteItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return DeleteHelperAsync(MakeKey(document), config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await DeleteHelperAsync(MakeKey(document), config, cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteItemAsync(Primitive hashKey, CancellationToken cancellationToken = default(CancellationToken)) + public async Task DeleteItemAsync(Primitive hashKey, CancellationToken cancellationToken = default(CancellationToken)) { - return DeleteHelperAsync(MakeKey(hashKey, null), null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await DeleteHelperAsync(MakeKey(hashKey, null), null, cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteItemAsync(Primitive hashKey, DeleteItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task DeleteItemAsync(Primitive hashKey, DeleteItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return DeleteHelperAsync(MakeKey(hashKey, null), config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await DeleteHelperAsync(MakeKey(hashKey, null), config, cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteItemAsync(Primitive hashKey, Primitive rangeKey, CancellationToken cancellationToken = default(CancellationToken)) + public async Task DeleteItemAsync(Primitive hashKey, Primitive rangeKey, CancellationToken cancellationToken = default(CancellationToken)) { - return DeleteHelperAsync(MakeKey(hashKey, rangeKey), null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await DeleteHelperAsync(MakeKey(hashKey, rangeKey), null, cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteItemAsync(Primitive hashKey, Primitive rangeKey, DeleteItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task DeleteItemAsync(Primitive hashKey, Primitive rangeKey, DeleteItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return DeleteHelperAsync(MakeKey(hashKey, rangeKey), config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await DeleteHelperAsync(MakeKey(hashKey, rangeKey), config, cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteItemAsync(IDictionary key, CancellationToken cancellationToken = default(CancellationToken)) + public async Task DeleteItemAsync(IDictionary key, CancellationToken cancellationToken = default(CancellationToken)) { - return DeleteHelperAsync(MakeKey(key), null, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await DeleteHelperAsync(MakeKey(key), null, cancellationToken).ConfigureAwait(false); + } } /// - public Task DeleteItemAsync(IDictionary key, DeleteItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) + public async Task DeleteItemAsync(IDictionary key, DeleteItemOperationConfig config, CancellationToken cancellationToken = default(CancellationToken)) { - return DeleteHelperAsync(MakeKey(key), config, cancellationToken); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItemAsync)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return await DeleteHelperAsync(MakeKey(key), config, cancellationToken).ConfigureAwait(false); + } } - + #endregion } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentBatchGet.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentBatchGet.Sync.cs index f43592e50f76..ab0482226f5f 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentBatchGet.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentBatchGet.Sync.cs @@ -13,6 +13,8 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; + namespace Amazon.DynamoDBv2.DocumentModel { public partial interface IDocumentBatchGet @@ -29,7 +31,11 @@ public partial class DocumentBatchGet : IDocumentBatchGet /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(DocumentBatchGet), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } @@ -47,7 +53,11 @@ public partial class MultiTableDocumentBatchGet : IMultiTableDocumentBatchGet /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableDocumentBatchGet), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentBatchWrite.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentBatchWrite.Sync.cs index 826e73d584b4..bd0ecf556b92 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentBatchWrite.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentBatchWrite.Sync.cs @@ -13,6 +13,8 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; + namespace Amazon.DynamoDBv2.DocumentModel { public partial interface IDocumentBatchWrite @@ -31,7 +33,11 @@ public partial class DocumentBatchWrite : IDocumentBatchWrite /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(DocumentBatchWrite), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } @@ -51,7 +57,11 @@ public partial class MultiTableDocumentBatchWrite : IMultiTableDocumentBatchWrit /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableDocumentBatchWrite), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentTransactGet.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentTransactGet.Sync.cs index 2827a4660611..aca9de5c2956 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentTransactGet.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentTransactGet.Sync.cs @@ -13,6 +13,8 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; + namespace Amazon.DynamoDBv2.DocumentModel { public partial interface IDocumentTransactGet @@ -29,7 +31,11 @@ public partial class DocumentTransactGet : IDocumentTransactGet /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(DocumentTransactGet), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } @@ -47,7 +53,11 @@ public partial class MultiTableDocumentTransactGet : IMultiTableDocumentTransact /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableDocumentTransactGet), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentTransactWrite.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentTransactWrite.Sync.cs index 8054342804e5..a56018c41034 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentTransactWrite.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/DocumentTransactWrite.Sync.cs @@ -13,6 +13,8 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; + namespace Amazon.DynamoDBv2.DocumentModel { public partial interface IDocumentTransactWrite @@ -28,7 +30,11 @@ public partial class DocumentTransactWrite : IDocumentTransactWrite /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(DocumentTransactWrite), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } @@ -49,7 +55,11 @@ public partial class MultiTableDocumentTransactWrite : IMultiTableDocumentTransa /// public void Execute() { - ExecuteHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(MultiTableDocumentTransactWrite), nameof(Execute)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + ExecuteHelper(); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/Search.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/Search.Sync.cs index b2a916ccdb54..f63fa3be9475 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/Search.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/Search.Sync.cs @@ -13,6 +13,7 @@ * permissions and limitations under the License. */ +using Amazon.Runtime.Telemetry.Tracing; using System.Collections.Generic; namespace Amazon.DynamoDBv2.DocumentModel @@ -41,13 +42,21 @@ public partial class Search : ISearch /// public List GetNextSet() { - return GetNextSetHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Search), nameof(GetNextSet)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return GetNextSetHelper(); + } } /// public List GetRemaining() { - return GetRemainingHelper(); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Search), nameof(GetRemaining)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return GetRemainingHelper(); + } } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/Table.Sync.cs b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/Table.Sync.cs index 31a26baa6bdf..e5deb5cc0352 100644 --- a/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/Table.Sync.cs +++ b/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/_bcl/Table.Sync.cs @@ -14,6 +14,7 @@ */ using Amazon.DynamoDBv2.Model; +using Amazon.Runtime.Telemetry.Tracing; using System.Collections.Generic; namespace Amazon.DynamoDBv2.DocumentModel @@ -246,20 +247,28 @@ public partial class Table : ITable /// public Document PutItem(Document doc, PutItemOperationConfig config = null) { - return PutItemHelper(doc, config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(PutItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return PutItemHelper(doc, config); + } } /// public bool TryPutItem(Document doc, PutItemOperationConfig config = null) { - try - { - PutItemHelper(doc, config); - return true; - } - catch (ConditionalCheckFailedException) + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryPutItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) { - return false; + try + { + PutItemHelper(doc, config); + return true; + } + catch (ConditionalCheckFailedException) + { + return false; + } } } @@ -271,19 +280,32 @@ public bool TryPutItem(Document doc, PutItemOperationConfig config = null) /// public Document GetItem(Primitive hashKey, GetItemOperationConfig config = null) { - return GetItem(hashKey, null, config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(GetItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return GetItem(hashKey, null, config); + } } /// public Document GetItem(Primitive hashKey, Primitive rangeKey, GetItemOperationConfig config = null) { - return GetItemHelper(MakeKey(hashKey, rangeKey), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(GetItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return GetItemHelper(MakeKey(hashKey, rangeKey), config); + } } /// public Document GetItem(IDictionary key, GetItemOperationConfig config = null) { - return GetItemHelper(MakeKey(key), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(GetItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return GetItemHelper(MakeKey(key), config); + } + } #endregion @@ -294,80 +316,112 @@ public Document GetItem(IDictionary key, GetItemOperation /// public Document UpdateItem(Document doc, UpdateItemOperationConfig config = null) { - return UpdateHelper(doc, MakeKey(doc), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return UpdateHelper(doc, MakeKey(doc), config); + } } /// public bool TryUpdateItem(Document doc, UpdateItemOperationConfig config = null) { - try - { - UpdateHelper(doc, MakeKey(doc), config); - return true; - } - catch (ConditionalCheckFailedException) + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryUpdateItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) { - return false; + try + { + UpdateHelper(doc, MakeKey(doc), config); + return true; + } + catch (ConditionalCheckFailedException) + { + return false; + } } } /// public Document UpdateItem(Document doc, IDictionary key, UpdateItemOperationConfig config = null) { - return UpdateHelper(doc, MakeKey(key), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return UpdateHelper(doc, MakeKey(key), config); + } } /// public bool TryUpdateItem(Document doc, IDictionary key, UpdateItemOperationConfig config = null) { - try + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryUpdateItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) { - UpdateHelper(doc, MakeKey(key), config); - return true; - } - catch (ConditionalCheckFailedException) - { - return false; + try + { + UpdateHelper(doc, MakeKey(key), config); + return true; + } + catch (ConditionalCheckFailedException) + { + return false; + } } } /// public Document UpdateItem(Document doc, Primitive hashKey, UpdateItemOperationConfig config = null) { - return UpdateHelper(doc, MakeKey(hashKey, null), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return UpdateHelper(doc, MakeKey(hashKey, null), config); + } } /// public bool TryUpdateItem(Document doc, Primitive hashKey, UpdateItemOperationConfig config = null) { - try + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryUpdateItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) { - UpdateHelper(doc, MakeKey(hashKey, null), config); - return true; - } - catch (ConditionalCheckFailedException) - { - return false; + try + { + UpdateHelper(doc, MakeKey(hashKey, null), config); + return true; + } + catch (ConditionalCheckFailedException) + { + return false; + } } } /// public Document UpdateItem(Document doc, Primitive hashKey, Primitive rangeKey, UpdateItemOperationConfig config = null) { - return UpdateHelper(doc, MakeKey(hashKey, rangeKey), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(UpdateItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return UpdateHelper(doc, MakeKey(hashKey, rangeKey), config); + } } /// public bool TryUpdateItem(Document doc, Primitive hashKey, Primitive rangeKey, UpdateItemOperationConfig config = null) { - try + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryUpdateItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) { - UpdateHelper(doc, MakeKey(hashKey, rangeKey), config); - return true; - } - catch (ConditionalCheckFailedException) - { - return false; + try + { + UpdateHelper(doc, MakeKey(hashKey, rangeKey), config); + return true; + } + catch (ConditionalCheckFailedException) + { + return false; + } } } @@ -379,80 +433,112 @@ public bool TryUpdateItem(Document doc, Primitive hashKey, Primitive rangeKey, U /// public Document DeleteItem(Document document, DeleteItemOperationConfig config = null) { - return DeleteHelper(MakeKey(document), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return DeleteHelper(MakeKey(document), config); + } } /// public bool TryDeleteItem(Document document, DeleteItemOperationConfig config = null) { - try - { - DeleteItem(document, config); - return true; - } - catch (ConditionalCheckFailedException) + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryDeleteItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) { - return false; + try + { + DeleteItem(document, config); + return true; + } + catch (ConditionalCheckFailedException) + { + return false; + } } } /// public Document DeleteItem(Primitive hashKey, DeleteItemOperationConfig config = null) { - return DeleteHelper(MakeKey(hashKey, null), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return DeleteHelper(MakeKey(hashKey, null), config); + } } /// public bool TryDeleteItem(Primitive hashKey, DeleteItemOperationConfig config = null) { - try + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryDeleteItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) { - DeleteItem(hashKey, config); - return true; - } - catch (ConditionalCheckFailedException) - { - return false; + try + { + DeleteItem(hashKey, config); + return true; + } + catch (ConditionalCheckFailedException) + { + return false; + } } } /// public Document DeleteItem(Primitive hashKey, Primitive rangeKey, DeleteItemOperationConfig config = null) { - return DeleteHelper(MakeKey(hashKey, rangeKey), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return DeleteHelper(MakeKey(hashKey, rangeKey), config); + } } /// public bool TryDeleteItem(Primitive hashKey, Primitive rangeKey, DeleteItemOperationConfig config = null) { - try - { - DeleteItem(hashKey, rangeKey, config); - return true; - } - catch (ConditionalCheckFailedException) + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryDeleteItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) { - return false; + try + { + DeleteItem(hashKey, rangeKey, config); + return true; + } + catch (ConditionalCheckFailedException) + { + return false; + } } } /// public Document DeleteItem(IDictionary key, DeleteItemOperationConfig config = null) { - return DeleteHelper(MakeKey(key), config); + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(DeleteItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) + { + return DeleteHelper(MakeKey(key), config); + } } /// public bool TryDeleteItem(IDictionary key, DeleteItemOperationConfig config = null) { - try - { - DeleteHelper(MakeKey(key), config); - return true; - } - catch (ConditionalCheckFailedException) + var operationName = DynamoDBTelemetry.ExtractOperationName(nameof(Table), nameof(TryDeleteItem)); + using (DynamoDBTelemetry.CreateSpan(TracerProvider, operationName, spanKind: SpanKind.CLIENT)) { - return false; + try + { + DeleteHelper(MakeKey(key), config); + return true; + } + catch (ConditionalCheckFailedException) + { + return false; + } } } diff --git a/sdk/src/Services/DynamoDBv2/Custom/DynamoDBTelemetry.cs b/sdk/src/Services/DynamoDBv2/Custom/DynamoDBTelemetry.cs new file mode 100644 index 000000000000..d3913b64b071 --- /dev/null +++ b/sdk/src/Services/DynamoDBv2/Custom/DynamoDBTelemetry.cs @@ -0,0 +1,59 @@ +using System; +using Amazon.DynamoDBv2.DataModel; +using Amazon.Runtime.Telemetry; +using Amazon.Runtime.Telemetry.Tracing; +using Attributes = Amazon.Runtime.Telemetry.Attributes; + +namespace Amazon.DynamoDBv2 +{ + internal static class DynamoDBTelemetry + { + private static string DynamoDBTracerScope = $"{TelemetryConstants.TelemetryScopePrefix}.DynamoDBv2"; + + internal static string ExtractOperationName(string className, string methodName) + { + if (methodName.EndsWith("Async", StringComparison.Ordinal)) + methodName = methodName.Substring(0, methodName.Length - 5); + return $"{className}.{methodName}"; + } + + internal static TraceSpan CreateSpan( + TracerProvider tracerProvider, + string operationName, + Attributes initialAttributes = null, + SpanKind spanKind = SpanKind.INTERNAL, + SpanContext parentContext = null) + { + if (initialAttributes == null) + initialAttributes = new Attributes(); + + initialAttributes.Set(TelemetryConstants.MethodAttributeKey, operationName); + initialAttributes.Set(TelemetryConstants.SystemAttributeKey, TelemetryConstants.SystemAttributeValue); + initialAttributes.Set(TelemetryConstants.ServiceAttributeKey, DynamoDBTracerScope); + + var tracer = tracerProvider.GetTracer(DynamoDBTracerScope); + return tracer.CreateSpan(operationName, initialAttributes, spanKind, parentContext); + } + + internal static TraceSpan CreateSpan(DynamoDBContext context, + string methodName, + Attributes initialAttributes = null, + SpanContext parentContext = null) + { + var operationName = ExtractOperationName(nameof(DynamoDBContext), methodName); + + if (initialAttributes == null) + initialAttributes = new Attributes(); + + initialAttributes.Set(TelemetryConstants.MethodAttributeKey, operationName); + initialAttributes.Set(TelemetryConstants.SystemAttributeKey, TelemetryConstants.SystemAttributeValue); + initialAttributes.Set(TelemetryConstants.ServiceAttributeKey, DynamoDBTracerScope); + + var tracerProvider = context?.Client?.Config?.TelemetryProvider?.TracerProvider + ?? AWSConfigs.TelemetryProvider.TracerProvider; + + var tracer = tracerProvider.GetTracer(DynamoDBTracerScope); + return tracer.CreateSpan(operationName, initialAttributes, SpanKind.CLIENT, parentContext); + } + } +} diff --git a/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DynamoDBTests.cs b/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DynamoDBTests.cs index d65de7d00f52..e532f5b47acf 100644 --- a/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DynamoDBTests.cs +++ b/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DynamoDBTests.cs @@ -489,6 +489,9 @@ public void DisableFetchingTableMetadata_KeyWithConverter_DateTimeToString() request.Key.ContainsKey("CreationDate") && request.Key["CreationDate"].S == "0001-01-01T00:00:00.000Z"))); + + mock.Verify(x => x.Config, Times.AtLeastOnce()); + mock.VerifyNoOtherCalls(); } @@ -514,6 +517,9 @@ public void DisableFetchingTableMetadata_KeyWithConverter_DateTimeToNumber() request.Key.ContainsKey("CreationDate") && request.Key["CreationDate"].N == "1024"))); + + mock.Verify(x => x.Config, Times.AtLeastOnce()); + mock.VerifyNoOtherCalls(); } @@ -539,6 +545,8 @@ public void DisableFetchingTableMetadata_KeyWithConverter_DateTimeToBinary() request.Key.ContainsKey("CreationDate") && BitConverter.ToString(request.Key["CreationDate"].B.ToArray()) == "00-04-00-00-00-00-00-40"))); + mock.Verify(x => x.Config, Times.AtLeastOnce()); + mock.VerifyNoOtherCalls(); } @@ -556,6 +564,8 @@ public void DisableFetchingTableMetadata_KeyWithConverter_DateTimeToBool_ThrowsE Assert.ThrowsException(() => context.Load(new DateTime(1024, DateTimeKind.Utc))); + mock.Verify(x => x.Config, Times.AtLeastOnce()); + mock.VerifyNoOtherCalls(); }