SAP / cloud-sdk

The SAP Cloud SDK documentation and support repository.
https://sap.github.io/cloud-sdk/
Apache License 2.0
44 stars 41 forks source link

Support Correlation ID #1580

Open PierreFritsch opened 11 months ago

PierreFritsch commented 11 months ago

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

tomfrenken commented 11 months ago

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}`);