Skip to content

93Omar/CorrelationPoC

Repository files navigation

Correlation ID PoC for ASP.NET Web APIs

Introduction to Correlation ID

In distributed systems, such as microservice architectures, a single client request often traverses multiple services or components. Tracking the flow of such requests and diagnosing issues can be challenging because logs are scattered across different systems. A Correlation ID is a unique identifier assigned to each request that travels through all involved services. This ID helps bind the entire transaction together, enabling developers to trace the request end-to-end, correlate logs, and troubleshoot effectively.

The Correlation ID is typically passed via HTTP headers (e.g., x-correlation-id) and included in logs generated by each service. This approach simplifies debugging, performance monitoring, and root cause analysis by providing a unified view of the request's lifecycle across distributed components.

PoC Overview

This Proof of Concept (PoC) demonstrates how to implement correlation between logs of two ASP.NET Web APIs communicating via HTTP REST calls:

  • WebApplicationSender calls WebApplicationReceiver.
  • Both APIs include a middleware named CorrelationMiddleware responsible for managing the Correlation ID.
  • The middleware applies the following logic:
    • If the incoming HTTP request contains an x-correlation-id header, its value is used as the Correlation ID.
    • Otherwise, a new GUID is generated and assigned as the Correlation ID.
  • The Correlation ID is then included in all logs for that request.
  • On the sender side, a DelegatingHandler named CorrelationDelegatingHandler adds the x-correlation-id header to outgoing HTTP requests.
  • This setup ensures that both APIs share the same Correlation ID for related requests, enabling seamless log correlation and easier troubleshooting.

Benefits

  • Enables end-to-end tracing of requests across multiple services.
  • Simplifies debugging by grouping related logs with the same Correlation ID.
  • Improves observability and performance monitoring.
  • Facilitates accountability and audit trails by linking logs to specific transactions.

This PoC serves as a foundational example for implementing correlation IDs in ASP.NET Web APIs, following best practices for distributed system observability.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages