I’d like to pass
tf_req_id parameter to the backend APIs to enable logs correlation. At the moment I’ve been using additional, provider specific
requestId parameter, but it feels redundant. Printing both request IDs also creates a clutter in the logs as they’re both long strings.
tf_req_id is inside the ctx passed to provider, but its contents seem to be logging related and can not be easily accessed, because they’re handled in
github.com/hashicorp/terraform-plugin-log/internal/logging that can not be imported. Perhaps it can be hacked somehow to get the request ID value, but is there a recommended way to access this variable?
Hi @w.wroblewski Thank you for raising this topic.
The terraform-plugin-log associated
tf_req_id field value was intended to only be meaningful for tracking the logs associated with debugging the code of a single provider request and not have too much meaning outside of that purpose, but this seems like a decent enough use case to promote that sort of identifier as more of a real “feature” that terraform-plugin-log could just happen to also use itself. I’d suggest raising a feature request in the terraform-plugin-framework/sdk GitHub repository for consideration since ultimately it’ll need to be exposed in some way at that level for provider code. We’ll need to figure out where it makes the most sense to generate that identifier, whether the lower level terraform-plugin-go server code or across the protocol from Terraform (in case there is benefit to associating Terraform core logs before/after a provider operation as well).