oasp / oasp4js

OASP4JS deprecated repository
Apache License 2.0
9 stars 161 forks source link

Create unique correlation ID and request counter to send with every request #90

Closed hohwille closed 8 years ago

hohwille commented 8 years ago

In OASP4J there is a concept called correlationID that is used as MDC and is included into each log entry. The idea is to be able to follow and trace a call trough the entire application landscape of a SOA or MicroServices architecture.

Therefore the client has to include an HTTP Header CorrelationId that should be set as following:

So if clientId is 9fbe72def1924fa the first request will have

CorrelationId: 9fbe72def1924fa-1
hohwille commented 8 years ago

UUID with JS: https://jsfiddle.net/briguy37/2MVFd/

hohwille commented 8 years ago

In Angular create an interceptor as factory and register it in config via:

$httpProvider.interceptors.push('myInterceptor');

The interceptor has to provide a function like this:

request: function (config) {
  requestCounter++;
  config.headers['X-Correlation-Id'] = uuid + requestCounter;
  return config;
}
hohwille commented 8 years ago

https://github.com/oasp/oasp4j/pull/427

maybeec commented 8 years ago

For oasp4j, this issues can be closed. PR merged.