Log Tags
Logging Tags, or Log Tags, facilitate a grouping of microservice logs by associating metadata to each gRPC request. Users can define multiple tags, all of which will be included in the logging messages. This may be beneficial for tracking and correlating log messages related to specific requests. For example, by including a unique Correlation ID in the log messages, users can easily trace and analyze the logs for debugging and monitoring purposes.
Log Tags offer a higher level of abstraction than what would be possible with a
Correlation ID alone. One such case could be the implementation of a retry
mechanism. If part of the system fails and the request to the microservice must
be retried with the identical Correlation ID, it would be impossible to
distinguish between the logs from the individual executions. Using Log Tags
allows users to differentiate specific retries by setting a tag such as
log-tag-retries-number to a serial number of the retries.
Logging tags are passed to the gRPC server
as metadata in custom headers. These
headers are strings and must start with the prefix log-tag-, followed by the
name itself. In the log messages, the prefix is then omitted, and only the name
is logged.
The length of the Log Tag name (not including the log-tag- prefix) as well as
its value can not exceed 64 characters, otherwise it will be automatically
truncated to fit the limit.
Logging Format
When log-tags are set by the user, they will be included in the log messages
generated by the microservice separated by comma. The log message format is as
follows:
[<timestamp>] [<log-level>] <method-name>: <message> [tag-name-1=<value-1>,tag-name-2=<value-2>]
Here's an example of a request using
grpcurl tool in Linux
terminal with included log-tags called log-tag-cid and
log-tag-retries-number:
$ echo '{"audio":{"content": "'$(cat paul_1.wav | base64 -w0)'"}}' | grpcurl -use-reflection -plaintext -rpc-header "log-tag-cid: db2b2269" -rpc-header log-tag-retries-number:1 -d @ localhost:8080 phonexia.grpc.technologies.speaker_identification.v1.VoiceprintExtraction/Extract
Here is an example of a log message with the cid and retries-number Log Tags
included:
[2024-04-03 01:42:00.000] [debug] Extract: Billed time: 39 s [cid=db2b2269,retries-number=1]
If you wish for the Correlation ID or any other log tag to be included in the log messages, please ensure that it is provided as part of the gRPC request headers. If the headers are not provided, the log messages will not include these fields.