cloud-sdk icon indicating copy to clipboard operation
cloud-sdk copied to clipboard

Support Correlation ID

Open PierreFritsch opened this issue 2 years ago • 1 comments

Will the sap-cloud-sdk-logger from @sap-cloud-sdk/util output the incoming correlation ID to the logs?

If not, how can we pass the correlation ID ourselves to the logger?

I couldn't find a corresponding hint in the documentation.

Background: We're seeing log entries from our app in Kibana, seemingly written by this logger, that are not instrumented with a correlation_id.

Cross-link: Also asked this question on stackoverflow - https://stackoverflow.com/questions/77366185/sap-cloud-sdk-logger-support-for-correlation-id

PierreFritsch avatar Oct 26 '23 10:10 PierreFritsch

Hey @PierreFritsch, this functionality isn't currently built into the SDK logger, we have received a similar feature request in our own repository (as opposed to this one, which is only for the documentation) here.

If you are using our logger directly, however, you can of course get the correlation ID from the headers yourself and set it in the log context like this:

const correlationId = myRequest.headers.correlationIdHeader // Here you have to check which of your headers contains the correlation id
setLogLevel('error', `Correlation ID: ${correlationId}`);

tomfrenken avatar Oct 27 '23 09:10 tomfrenken