Skip to content

Commit

Permalink
Add total orders counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourabh Shirhatti committed Nov 18, 2019
1 parent c8301c7 commit 82b2fde
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/BlazingPizza.Orders/OrdersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public async Task<ActionResult<Guid>> PlaceOrder(Order order)
order.OrderId = Guid.NewGuid();
order.TotalPrice = order.GetFormattedTotalPrice();
await _db.SaveOrder(order);
OrdersEventSource.Log.OrderCreated();
return order.OrderId;
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/BlazingPizza.Orders/OrdersEventSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace BlazingPizza.Orders
{
internal sealed class OrdersEventSource : EventSource
{
public static readonly OrdersEventSource Log = new OrdersEventSource();

private PollingCounter _totalOrdersCounter;

private long _totalOrders;

internal OrdersEventSource()
: base("BlazingOrders.Pizza")
{

}

internal void OrderCreated()
{
Interlocked.Increment(ref _totalOrders);
}

protected override void OnEventCommand(EventCommandEventArgs command)
{
if (command.Command == EventCommand.Enable)
{
_totalOrdersCounter ??= new PollingCounter("total-orders", this, () => _totalOrders)
{
DisplayName = "Total Orders"
};
}
}
}
}

0 comments on commit 82b2fde

Please sign in to comment.