Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public static async Task<IResult> Handle(
ILogger<CreateOrderHandler> logger)
{
var correlationId = context.Items["CorrelationId"]?.ToString() ?? Guid.NewGuid().ToString();
var stopwatch = Stopwatch.StartNew();

using var performanceScope = logger.BeginPerformanceScope("CreateOrder", correlationId);

try
{
Expand All @@ -38,10 +35,7 @@ public static async Task<IResult> Handle(
// Log operation start with safe context
logger.LogOrderCreationStarted(request.Products.Length, userType);

// Validate request using FluentValidation
var validationStartTime = Stopwatch.GetTimestamp();
var validationResult = await validator.ValidateAsync(request);
var validationDuration = Stopwatch.GetElapsedTime(validationStartTime);

if (!validationResult.IsValid)
{
Expand All @@ -57,8 +51,6 @@ public static async Task<IResult> Handle(
errors,
correlationId));
}

logger.LogValidationPassed("CreateOrder", (long)validationDuration.TotalMilliseconds);

Order? newOrder = null;
string orderType;
Expand All @@ -80,24 +72,6 @@ public static async Task<IResult> Handle(
await orders.Store(newOrder);
await orderWorkflow.StartWorkflowFor(newOrder);

stopwatch.Stop();

// Log successful completion with structured context
logger.LogOrderCreated(orderType, stopwatch.ElapsedMilliseconds);

// Log business metrics (NO PII)
var businessContext = new BusinessMetricsContext
{
CorrelationId = correlationId,
EventType = "OrderCreated",
OrderType = orderType,
UserTier = userType,
ProductCount = request.Products.Length,
Timestamp = DateTime.UtcNow,
ProcessingStage = "Created"
};
logger.LogBusinessMetrics("Order creation completed", businessContext);

return Results.Created($"/api/orders/{newOrder.OrderNumber}", new OrderDTO(newOrder));
}
catch (OrderValidationException ex)
Expand Down
4 changes: 2 additions & 2 deletions src/order-service/src/Orders.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@

app.UseAuthorization();

var orders = app.NewVersionedApi("Orders");

// Comprehensive health check endpoints
app.MapHealthChecks("/health", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions
{
Expand Down Expand Up @@ -306,6 +304,8 @@
await context.Response.WriteAsync(result);
}
});

var orders = app.NewVersionedApi("Orders");
// Version 1 API endpoints with specific rate limiting policies
orders.MapGet("/orders", GetUserOrdersHandler.Handle)
.HasApiVersion(1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"launchBrowser": false,
"applicationUrl": "http://localhost:5273",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Development",
"ENV": "local"
}
},
"https": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private async Task Publish(PutEventsRequestEntry evt)

scope.Span.SetTag("messaging.failedMessageCount", putEventsResponse.FailedEntryCount);
scope.Span.SetTag("messaging.publishStatusCode", putEventsResponse.HttpStatusCode.ToString());
scope.Span.Finish();
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling Finish() on a span that's part of a using scope may cause issues since the scope will also dispose/finish the span. This could lead to double-finishing the span or unexpected behavior. Consider removing this explicit call if the scope handles span lifecycle management.

Suggested change
scope.Span.Finish();

Copilot uses AI. Check for mistakes.
}

public async Task Publish(OrderCreatedEventV1 evt)
Expand Down
Loading