Correlation ID
The Correlation ID allows you to associate a unique identifier with each gRPC request. This identifier can be used for tracking and correlating log messages related to specific requests. By including the Correlation ID in the log messages, you can easily trace and analyze the logs for debugging and monitoring purposes.
The gRPC server accepts a custom header called correlation-id
. This header is
a string with a maximum length of 64 characters. If the provided
correlation-id
is longer than 64 characters, it will be automatically
truncated to fit the limit.
Logging Format
When a correlation-id
is set by the user, it will be included in the log
messages generated by the micro-service. The log message format is as follows:
[<timestamp>] [<log-level>] <method-name>: <message> [cid=<correlation-id>]
Here's an example of a request using
grpcurl
tool in Linux
terminal with a correlation-id
included:
$ echo '{"audio":{"content": "'$(cat paul_1.wav | base64 -w0)'"}}' | grpcurl -use-reflection -plaintext -rpc-header "correlation-id: db2b2269-b700-41a3-b437-e2d55bc3add6" -d @ localhost:8080 phonexia.grpc.technologies.speaker_identification.v1.VoiceprintExtraction/Extract
Here's an example of a log message with a correlation-id
included:
[2023-11-16 10:21:54.910] [debug] Extract: Billed time: 36 s [cid=db2b2269-b700-41a3-b437-e2d55bc3add6]
Please ensure that the correlation-id
is provided as part of the gRPC request
headers if you want it to be included in the log messages. If the
correlation-id
is not set, the log messages will not include the cid
field.