예제 #1
0
        public async Task <IActionResult> NewAsync([FromBody] Contracts.Inventory inventory)
        {
            var isnew       = tracer.CurrentTransaction == null;
            var transaction = isnew
                ? tracer.StartTransaction($"NewInventory", "post")
                              .WithLabel("inventory: product", inventory.Product)
                              .WithLabel("inventory: quantity", inventory.Quantity.ToString())
                : tracer.CurrentTransaction;

            if (inventory == default(Contracts.Inventory))
            {
                return(BadRequest("Body empty or null"));
            }

            inventory.Id = Guid.NewGuid();

            await repository.NewAsync(inventory, CancellationToken.None);

            messageProducer.SendMessage(new InventoryAddedEvent
            {
                Product  = inventory.Product,
                Quantity = inventory.Quantity
            });

            if (isnew)
            {
                transaction.End();
            }
            return(Ok());
        }
예제 #2
0
        public async Task NewAsync(Contracts.Inventory inventory, CancellationToken cancellationToken)
        {
            var isnew       = tracer.CurrentTransaction == null;
            var transaction = isnew
                ? tracer.StartTransaction($"New", "inventorydb")
                              .WithLabel("product", inventory.Product)
                : tracer.CurrentTransaction;

            var span = transaction.StartSpan($"New inventory", "mongodb", subType: ApiConstants.TypeExternal);

            span.SetLabel("Product", inventory.Product);
            span.SetLabel("Quantity", inventory.Quantity.ToString());

            await Inventory.InsertOneAsync(inventory, new InsertOneOptions { BypassDocumentValidation = false }, cancellationToken).ConfigureAwait(false);

            span?.End();
            if (isnew)
            {
                transaction.End();
            }
        }