Consider Logging Fields for RPC Duration and Diagnostic Counts/Messages
bflad opened this issue · comments
terraform-plugin-go version
v0.9.0
Use cases
Buried in a provider statistics proposal, there was the idea that some form of telemetry could be performed at the RPC layer. While that would be its own separate potential project, one of the ideas there was to capture RPC duration and diagnostics.
The project today already logs when it calls into downstream implementations, e.g.
terraform-plugin-go/tfprotov6/tf6server/server.go
Lines 654 to 660 in 48c8bfb
The "called" log could contain this information to aid in troubleshooting, since the "calling" log may be interspersed with other concurrent operations or otherwise be at a distance due to other logging. Having this information right there could save some filtering or otherwise manual determination of whether or not it was the provider or CLI that generated a diagnostic.
In the future, if any sort of telemetry project is done, this information could be directly used there as well.
Proposal
- Create logging keys for duration, warning diagnostics, and error diagnostics fields in internal/logging
- Before a call, start a duration timer.
- After a call, get the duration difference.
- Calculate the number of present warning and error diagnostics from a response.
- Append these fields to the "called" log message