hashicorp / hashicorp/terraform-plugin-log
Fallback to Generic Logger Output
- Dominant language
- Go
- Stars
- 23
- Forks
- 11
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 1
Description
### terraform-plugin-log version
```
v0.3.0
```
### Use cases
For much of the terraform-plugin-log logging logic, it will fallback to dropping messages when the `context.Context` is not appropriately setup, e.g.
https://github.com/hashicorp/terraform-plugin-log/blob/94541a862d7fb4b6920239ef9206072c650971fa/tflog/provider.go#L31-L38
In production, is quite trivial for provider developers to get into situations where the `context.Context` is not setup properly. For example, using the non-context-aware fields of [`github.com/hashicorp/terraform-plugin-sdk/helper/schema.Resource`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/helper/schema#Resource) or using any SDK, errantly using a separate `context.Context` that was not setup (e.g. via `context.Background()` or `context.TODO()`).
Another use case is SDK-based unit testing, where it takes some effort to setup the logging contexts or its easy to miss in each and every test.
Not having any log output with no indication of an issue is more confusing than expecting everyone downstream to figure out the issue on their own.
### Proposal
If a logging message is to be written, but the appropriate logging context is not available, fallback to a last resort `github.com/hashicorp/hc-log.Logger` and write to it instead. On first usage of the last resort `Logger`, it should also output a warning message about the missing context-based `Logger`, so provider or SDK developers can understand any differences in logging behavior.
### References
- https://discuss.hashicorp.com/t/terraform-plugin-log-not-outputting-logs/38590/2
Contributor guide
Research direction
Start with tflog/provider.go at the linked lines and trace the logging paths that currently drop messages when the context is missing. Implement the proposed hc-log.Logger fallback and first-use warning, then verify that missing-context logging produces both the generic output and the warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, terraform
- Domain
- observability-sre
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100