Browse Source

Fix non-structured traces

pull/970/head
Savorboard 6 years ago
parent
commit
e8262539de
12 changed files with 31 additions and 65 deletions
  1. +0
    -6
      src/Services/Basket/Basket.API/Basket.API.csproj
  2. +4
    -16
      src/Services/Basket/Basket.API/Controllers/BasketController.cs
  3. +3
    -4
      src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs
  4. +4
    -5
      src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs
  5. +2
    -4
      src/Services/Basket/Basket.API/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs
  6. +2
    -4
      src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs
  7. +2
    -3
      src/Services/Basket/Basket.API/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs
  8. +6
    -8
      src/Services/Basket/Basket.UnitTests/Application/BasketWebApiTest.cs
  9. +2
    -9
      src/Services/Ordering/Ordering.SignalrHub/AutofacModules/ApplicationModule.cs
  10. +2
    -2
      src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs
  11. +2
    -2
      src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs
  12. +2
    -2
      src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs

+ 0
- 6
src/Services/Basket/Basket.API/Basket.API.csproj View File

@ -41,10 +41,4 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" />
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
</ItemGroup>
</Project>

+ 4
- 16
src/Services/Basket/Basket.API/Controllers/BasketController.cs View File

@ -2,14 +2,13 @@
using Basket.API.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
using Microsoft.Extensions.Logging;
using Serilog.Context;
using System;
using System.Net;
using System.Threading.Tasks;
using DotNetCore.CAP;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
{
@ -20,14 +19,14 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
{
private readonly IBasketRepository _repository;
private readonly IIdentityService _identityService;
private readonly IEventBus _eventBus;
private readonly ICapPublisher _eventBus;
private readonly ILogger<BasketController> _logger;
public BasketController(
ILogger<BasketController> logger,
IBasketRepository repository,
IIdentityService identityService,
IEventBus eventBus)
ICapPublisher eventBus)
{
_logger = logger;
_repository = repository;
@ -78,18 +77,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Controllers
// Once basket is checkout, sends an integration event to
// ordering.api to convert basket to order and proceeds with
// order creation process
try
{
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} from {AppName} - ({@IntegrationEvent})", eventMessage.Id, Program.AppName, eventMessage);
_eventBus.Publish(eventMessage);
}
catch (Exception ex)
{
_logger.LogError(ex, "ERROR Publishing integration event: {IntegrationEventId} from {AppName}", eventMessage.Id, Program.AppName);
throw;
}
_eventBus.Publish(nameof(UserCheckoutAcceptedIntegrationEvent), eventMessage);
return Accepted();
}


+ 3
- 4
src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/OrderStartedIntegrationEventHandler.cs View File

@ -1,5 +1,4 @@
using Basket.API.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Basket.API;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.Extensions.Logging;
@ -10,7 +9,7 @@ using DotNetCore.CAP;
namespace Basket.API.IntegrationEvents.EventHandling
{
public class OrderStartedIntegrationEventHandler : IIntegrationEventHandler<OrderStartedIntegrationEvent>, ICapSubscribe
public class OrderStartedIntegrationEventHandler : ICapSubscribe
{
private readonly IBasketRepository _repository;
private readonly ILogger<OrderStartedIntegrationEventHandler> _logger;
@ -26,9 +25,9 @@ namespace Basket.API.IntegrationEvents.EventHandling
//TODO: [CapSubscribe(nameof(OrderStartedIntegrationEvent))]
public async Task Handle(OrderStartedIntegrationEvent @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
using (LogContext.PushProperty("IntegrationEventContext", $"{Program.AppName}"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", Program.AppName, @event);
await _repository.DeleteBasketAsync(@event.UserId.ToString());
}


+ 4
- 5
src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs View File

@ -1,5 +1,4 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.Extensions.Logging;
using Serilog.Context;
@ -10,7 +9,7 @@ using DotNetCore.CAP;
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling
{
public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>, ICapSubscribe
public class ProductPriceChangedIntegrationEventHandler : ICapSubscribe
{
private readonly ILogger<ProductPriceChangedIntegrationEventHandler> _logger;
private readonly IBasketRepository _repository;
@ -26,9 +25,9 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
//TODO: [CapSubscribe(nameof(ProductPriceChangedIntegrationEvent))]
public async Task Handle(ProductPriceChangedIntegrationEvent @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
using (LogContext.PushProperty("IntegrationEventContext", $"{Program.AppName}"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
_logger.LogInformation("----- Handling integration event: {AppName} - ({@IntegrationEvent})", Program.AppName, @event);
var userIds = _repository.GetUsers();


+ 2
- 4
src/Services/Basket/Basket.API/IntegrationEvents/Events/OrderStartedIntegrationEvent.cs View File

@ -1,11 +1,9 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
namespace Basket.API.IntegrationEvents.Events
namespace Basket.API.IntegrationEvents.Events
{
// Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public class OrderStartedIntegrationEvent : IntegrationEvent
public class OrderStartedIntegrationEvent
{
public string UserId { get; set; }


+ 2
- 4
src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs View File

@ -1,11 +1,9 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events
{
// Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public class ProductPriceChangedIntegrationEvent : IntegrationEvent
public class ProductPriceChangedIntegrationEvent
{
public int ProductId { get; private set; }


+ 2
- 3
src/Services/Basket/Basket.API/IntegrationEvents/Events/UserCheckoutAcceptedIntegrationEvent.cs View File

@ -1,10 +1,9 @@
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using System;
namespace Basket.API.IntegrationEvents.Events
{
public class UserCheckoutAcceptedIntegrationEvent : IntegrationEvent
public class UserCheckoutAcceptedIntegrationEvent
{
public string UserId { get; }


+ 6
- 8
src/Services/Basket/Basket.UnitTests/Application/BasketWebApiTest.cs View File

@ -2,7 +2,6 @@
using Basket.API.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Basket.API.Controllers;
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
using Microsoft.Extensions.Logging;
@ -11,6 +10,7 @@ using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using DotNetCore.CAP;
using Xunit;
using IBasketIdentityService = Microsoft.eShopOnContainers.Services.Basket.API.Services.IIdentityService;
@ -20,14 +20,14 @@ namespace UnitTest.Basket.Application
{
private readonly Mock<IBasketRepository> _basketRepositoryMock;
private readonly Mock<IBasketIdentityService> _identityServiceMock;
private readonly Mock<IEventBus> _serviceBusMock;
private readonly Mock<ICapPublisher> _serviceBusMock;
private readonly Mock<ILogger<BasketController>> _loggerMock;
public BasketWebApiTest()
{
_basketRepositoryMock = new Mock<IBasketRepository>();
_identityServiceMock = new Mock<IBasketIdentityService>();
_serviceBusMock = new Mock<IEventBus>();
_serviceBusMock = new Mock<ICapPublisher>();
_loggerMock = new Mock<ILogger<BasketController>>();
}
@ -42,7 +42,7 @@ namespace UnitTest.Basket.Application
.Returns(Task.FromResult(fakeCustomerBasket));
_identityServiceMock.Setup(x => x.GetUserIdentity()).Returns(fakeCustomerId);
_serviceBusMock.Setup(x => x.Publish(It.IsAny<UserCheckoutAcceptedIntegrationEvent>()));
_serviceBusMock.Setup(x => x.Publish(nameof(UserCheckoutAcceptedIntegrationEvent), It.IsAny<UserCheckoutAcceptedIntegrationEvent>(), null));
//Act
var basketController = new BasketController(
@ -54,7 +54,6 @@ namespace UnitTest.Basket.Application
var actionResult = await basketController.GetBasketByIdAsync(fakeCustomerId);
//Assert
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
Assert.Equal(((CustomerBasket)actionResult.Value).BuyerId, fakeCustomerId);
}
@ -68,7 +67,7 @@ namespace UnitTest.Basket.Application
_basketRepositoryMock.Setup(x => x.UpdateBasketAsync(It.IsAny<CustomerBasket>()))
.Returns(Task.FromResult(fakeCustomerBasket));
_identityServiceMock.Setup(x => x.GetUserIdentity()).Returns(fakeCustomerId);
_serviceBusMock.Setup(x => x.Publish(It.IsAny<UserCheckoutAcceptedIntegrationEvent>()));
_serviceBusMock.Setup(x => x.Publish(nameof(UserCheckoutAcceptedIntegrationEvent), It.IsAny<UserCheckoutAcceptedIntegrationEvent>(), null));
//Act
var basketController = new BasketController(
@ -80,7 +79,6 @@ namespace UnitTest.Basket.Application
var actionResult = await basketController.UpdateBasketAsync(fakeCustomerBasket);
//Assert
Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
Assert.Equal(((CustomerBasket)actionResult.Value).BuyerId, fakeCustomerId);
}
@ -132,7 +130,7 @@ namespace UnitTest.Basket.Application
//Act
var result = await basketController.CheckoutAsync(new BasketCheckout(), Guid.NewGuid().ToString()) as AcceptedResult;
_serviceBusMock.Verify(mock => mock.Publish(It.IsAny<UserCheckoutAcceptedIntegrationEvent>()), Times.Once);
_serviceBusMock.Verify(mock => mock.Publish(nameof(UserCheckoutAcceptedIntegrationEvent), It.IsAny<UserCheckoutAcceptedIntegrationEvent>(), null), Times.Once);
Assert.NotNull(result);
}


+ 2
- 9
src/Services/Ordering/Ordering.SignalrHub/AutofacModules/ApplicationModule.cs View File

@ -1,11 +1,4 @@
using Autofac;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Ordering.SignalrHub.IntegrationEvents;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace Ordering.SignalrHub.AutofacModules
{
@ -22,8 +15,8 @@ namespace Ordering.SignalrHub.AutofacModules
protected override void Load(ContainerBuilder builder)
{
builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToAwaitingValidationIntegrationEvent).GetTypeInfo().Assembly)
.AsClosedTypesOf(typeof(IIntegrationEventHandler<>));
// builder.RegisterAssemblyTypes(typeof(OrderStatusChangedToAwaitingValidationIntegrationEvent).GetTypeInfo().Assembly)
// .AsClosedTypesOf(typeof(IIntegrationEventHandler<>));
}
}


+ 2
- 2
src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToCancelledIntegrationEventHandler.cs View File

@ -24,9 +24,9 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling
//TODO: [CapSubscribe(nameof(OrderStatusChangedToCancelledIntegrationEvent))]
public async Task Handle(OrderStatusChangedToCancelledIntegrationEvent @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
using (LogContext.PushProperty("IntegrationEventContext", $"{Program.AppName}"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
_logger.LogInformation("----- Handling integration event: {AppName} - ({@IntegrationEvent})", Program.AppName, @event);
await _hubContext.Clients
.Group(@event.BuyerName)


+ 2
- 2
src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToPaidIntegrationEventHandler.cs View File

@ -24,9 +24,9 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling
//TODO [CapSubscribe(nameof(OrderStatusChangedToPaidIntegrationEvent))]
public async Task Handle(OrderStatusChangedToPaidIntegrationEvent @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
using (LogContext.PushProperty("IntegrationEventContext", $"{Program.AppName}"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
_logger.LogInformation("----- Handling integration event: {AppName} - ({@IntegrationEvent})", Program.AppName, @event);
await _hubContext.Clients
.Group(@event.BuyerName)


+ 2
- 2
src/Services/Ordering/Ordering.SignalrHub/IntegrationEvents/EventHandling/OrderStatusChangedToShippedIntegrationEventHandler.cs View File

@ -24,9 +24,9 @@ namespace Ordering.SignalrHub.IntegrationEvents.EventHandling
//TODO [CapSubscribe(nameof(OrderStatusChangedToShippedIntegrationEvent))]
public async Task Handle(OrderStatusChangedToShippedIntegrationEvent @event)
{
using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}"))
using (LogContext.PushProperty("IntegrationEventContext", $"{Program.AppName}"))
{
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event);
_logger.LogInformation("----- Handling integration event: {AppName} - ({@IntegrationEvent})", Program.AppName, @event);
await _hubContext.Clients
.Group(@event.BuyerName)


Loading…
Cancel
Save