hashicorp / terraform-plugin-go

A low-level Go binding for the Terraform protocol for integrations to be built on top of.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

logging.ProtocolTrace(ctx, "Calling downstream")
resp, err := s.downstream.ReadDataSource(ctx, r)
if err != nil {
logging.ProtocolError(ctx, "Error from downstream", map[string]interface{}{logging.KeyError: err})
return nil, err
}
logging.ProtocolTrace(ctx, "Called downstream")

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