/

Correlation IDs

Correlation IDs help you track related operations across your application. Use them to trace request flows and debug issues in distributed systems.

Setting Correlation IDs

Using Fluent API

Java
String correlationId = "req_" + System.currentTimeMillis();

Log.withCorrelationId(correlationId).info("Request started");
Log.withCorrelationId(correlationId).debug("Processing data");
Log.withCorrelationId(correlationId).info("Request completed");

Request Flow Tracking

Java
public void handleRequest(HttpRequest request) {
    String correlationId = java.util.UUID.randomUUID().toString();
    
    Log.withCorrelationId(correlationId)
       .withTags("api", "request")
       .info("Request received");
    
    try {
        Object result = processRequest(request, correlationId);
        
        Log.withCorrelationId(correlationId)
           .withTags("api", "success")
           .info("Request processed successfully");
    } catch (Exception e) {
        Log.withCorrelationId(correlationId)
           .withTags("api", "error")
           .withException(e)
           .error("Request processing failed");
    }
}

Combining with Other Features

Java
String correlationId = "txn_" + System.currentTimeMillis();

Log.withCorrelationId(correlationId)
   .withTags("payment", "processing")
   .withContext("amount", 99.99)
   .withContext("currency", "USD")
   .info("Payment initiated");

Best Practices

Correlation ID Best Practices

  • Generate unique IDs using UUID or timestamp-based identifiers
  • Pass correlation IDs across service boundaries
  • Include in all related logs for complete request tracing
  • Use meaningful prefixes (e.g., "req_", "txn_", "job_")

Next Steps

Previous
User Identification