Class RequestIdHeaders

java.lang.Object
org.openehealth.ipf.commons.audit.RequestIdHeaders

public abstract class RequestIdHeaders extends Object
The HTTP headers a request may carry the id correlating the audit records of its two ends in, and how to read that id out of them. Which of them are looked at is configured by AuditContext.getRequestIdHeaderNames().

Most such headers carry nothing but the id, so the header value is the id. The exception is the B3 single header, which packs the trace id, the span id and the sampling state into one value -- and the span id differs between the two ends of a transaction, so only its trace id correlates them. Taking that trace id also makes the single-header and the multi-header flavour of B3 interchangeable: both then yield the same id, which is what X_B3_TRACE_ID carries on its own.

TRACEPARENT is deliberately not reduced to its trace id: it is recorded whole, which is how IPF has always recorded it. Both ends of a transaction see the same header value on the wire, so it correlates them either way.

Which header an id came from is kept in the audit record, as the participant object ID type the id is recorded under -- see participantObjectIdType(String). A deployment that would rather record one type whatever the propagation format can fix it with AuditContext.getRequestIdType().

Since:
5.3
Author:
Christian Ohr
  • Field Details

  • Constructor Details

    • RequestIdHeaders

      public RequestIdHeaders()
  • Method Details

    • participantObjectIdType

      public static ParticipantObjectIdType participantObjectIdType(String headerName)
      The participant object ID type a correlation id from the given header is conventionally recorded under. It names the propagation format the id was taken from, which is what tells a reader how to line the id up against the traces it has.
      Parameters:
      headerName - name of the header the id came from, matched case-insensitively
      Returns:
      the type for it, or ParticipantObjectIdTypeCode.XRequestId for a header without a code of its own
    • extractRequestId

      public static Optional<String> extractRequestId(String headerName, String headerValue)
      Reads the correlation id out of a header value.
      Parameters:
      headerName - name of the header the value came from, matched case-insensitively
      headerValue - value of the header, may be null or blank
      Returns:
      the correlation id, or empty if the header carries none