Skip to content

Commit c2a9ae8

Browse files
authored
internal: Update all provider defined method call logs to TRACE (#818)
* demote all provider defined method call logs to trace * add changelog * switch msg * add prose for logging
1 parent 55f0d6b commit c2a9ae8

24 files changed

+166
-148
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: NOTES
2+
body: 'internal: Changed provider defined method execution logs from `DEBUG` log level
3+
to `TRACE`'
4+
time: 2023-08-03T17:36:40.939931-04:00
5+
custom:
6+
Issue: "818"

.github/CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ We welcome issues of all kinds including feature requests, bug reports, or docum
5454
Thank you for contributing!
5555

5656
- **Early validation of idea and implementation plan**: Most code changes in this project, unless trivial typo fixes or cosmetic, should be discussed and approved by maintainers in an issue before an implementation is created. This project is complicated enough that there are often several ways to implement something, each of which has different implications and tradeoffs. Working through an implementation plan with the maintainers before you dive into implementation will help ensure that your efforts may be approved and merged.
57+
- **Logging**: Refer to the [logging](#logging) section for guidance on choosing the appropriate log level for messages.
5758
- **Unit and Integration Tests**: It may go without saying, but every new patch should be covered by tests wherever possible (see [Testing](#testing) below).
5859
- **Go Modules**: We use [Go Modules](https://github.com/golang/go/wiki/Modules) to manage and version all our dependencies. Please make sure that you reflect dependency changes in your pull requests appropriately (e.g. `go get`, `go mod tidy` or other commands). Refer to the [dependency updates](#dependency-updates) section for more information about how this project maintains existing dependencies.
5960
- **Changelog**: Refer to the [changelog](#changelog) section for more information about how to create changelog entries.
@@ -126,6 +127,17 @@ To run the Go linters locally, install the `golangci-lint` tool, and run:
126127
golangci-lint run ./...
127128
```
128129

130+
## Logging
131+
132+
Code contributions that introduce new log messages should utilize the helper functions in the [`internal/logging`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/internal/logging) package. Here are some examples on when to use each helper:
133+
134+
- [`FrameworkError`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/internal/logging#FrameworkError) - Logs at `ERROR` level, can be used to provide additional detail alongside user-facing errors that are returned with [`diag.Diagnostics`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/diag#Diagnostics).
135+
- [`FrameworkWarn`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/internal/logging#FrameworkWarn) - Logs at `WARN` level, can be used to signal unexpected scenarios that may not result in a user-facing error, but can be used to track down potential provider implementation bugs.
136+
- [`FrameworkDebug`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/internal/logging#FrameworkDebug) - Logs at `DEBUG` level, can be used to describe internal logic behavior, such as [semantic equality](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/custom-types#semantic-equality) being triggered to preserve a prior value, or a null `Computed` attribute being marked as unknown.
137+
- [`FrameworkTrace`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/internal/logging#FrameworkTrace) - Logs at `TRACE` level, can be used to describe internal logic execution, such as logging a message before and after a provider-defined method is called. As the name suggests, these messages are used to "trace" where a program is at during execution.
138+
139+
More general guidance about logging can be found in the [Plugin Development documentation.](https://developer.hashicorp.com/terraform/plugin/log/managing)
140+
129141
## Testing
130142

131143
Code contributions should be supported by both unit and integration tests wherever possible.

internal/fwschemadata/data_set_at_path.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ func (d *Data) SetAtPath(ctx context.Context, path path.Path, val interface{}) d
7171

7272
if attrTypeWithValidate, ok := attrType.(xattr.TypeWithValidate); ok {
7373
logging.FrameworkTrace(ctx, "Type implements TypeWithValidate")
74-
logging.FrameworkDebug(ctx, "Calling provider defined Type Validate")
74+
logging.FrameworkTrace(ctx, "Calling provider defined Type Validate")
7575
diags.Append(attrTypeWithValidate.Validate(ctx, tfVal, path)...)
76-
logging.FrameworkDebug(ctx, "Called provider defined Type Validate")
76+
logging.FrameworkTrace(ctx, "Called provider defined Type Validate")
7777

7878
if diags.HasError() {
7979
return diags
@@ -189,9 +189,9 @@ func (d Data) SetAtPathTransformFunc(ctx context.Context, path path.Path, tfVal
189189

190190
if attrTypeWithValidate, ok := parentAttrType.(xattr.TypeWithValidate); ok {
191191
logging.FrameworkTrace(ctx, "Type implements TypeWithValidate")
192-
logging.FrameworkDebug(ctx, "Calling provider defined Type Validate")
192+
logging.FrameworkTrace(ctx, "Calling provider defined Type Validate")
193193
diags.Append(attrTypeWithValidate.Validate(ctx, parentValue, parentPath)...)
194-
logging.FrameworkDebug(ctx, "Called provider defined Type Validate")
194+
logging.FrameworkTrace(ctx, "Called provider defined Type Validate")
195195

196196
if diags.HasError() {
197197
return nil, diags

internal/fwschemadata/data_value.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func (d Data) ValueAtPath(ctx context.Context, schemaPath path.Path) (attr.Value
7878

7979
if attrTypeWithValidate, ok := attrType.(xattr.TypeWithValidate); ok {
8080
logging.FrameworkTrace(ctx, "Type implements TypeWithValidate")
81-
logging.FrameworkDebug(ctx, "Calling provider defined Type Validate")
81+
logging.FrameworkTrace(ctx, "Calling provider defined Type Validate")
8282
diags.Append(attrTypeWithValidate.Validate(ctx, tfValue, schemaPath)...)
83-
logging.FrameworkDebug(ctx, "Called provider defined Type Validate")
83+
logging.FrameworkTrace(ctx, "Called provider defined Type Validate")
8484

8585
if diags.HasError() {
8686
return nil, diags

internal/fwserver/attribute_plan_modification.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ func AttributePlanModifyBool(ctx context.Context, attribute fwxschema.AttributeW
685685
Private: resp.Private,
686686
}
687687

688-
logging.FrameworkDebug(
688+
logging.FrameworkTrace(
689689
ctx,
690690
"Calling provider defined planmodifier.Bool",
691691
map[string]interface{}{
@@ -695,7 +695,7 @@ func AttributePlanModifyBool(ctx context.Context, attribute fwxschema.AttributeW
695695

696696
planModifier.PlanModifyBool(ctx, planModifyReq, planModifyResp)
697697

698-
logging.FrameworkDebug(
698+
logging.FrameworkTrace(
699699
ctx,
700700
"Called provider defined planmodifier.Bool",
701701
map[string]interface{}{
@@ -845,7 +845,7 @@ func AttributePlanModifyFloat64(ctx context.Context, attribute fwxschema.Attribu
845845
Private: resp.Private,
846846
}
847847

848-
logging.FrameworkDebug(
848+
logging.FrameworkTrace(
849849
ctx,
850850
"Calling provider defined planmodifier.Float64",
851851
map[string]interface{}{
@@ -855,7 +855,7 @@ func AttributePlanModifyFloat64(ctx context.Context, attribute fwxschema.Attribu
855855

856856
planModifier.PlanModifyFloat64(ctx, planModifyReq, planModifyResp)
857857

858-
logging.FrameworkDebug(
858+
logging.FrameworkTrace(
859859
ctx,
860860
"Called provider defined planmodifier.Float64",
861861
map[string]interface{}{
@@ -1005,7 +1005,7 @@ func AttributePlanModifyInt64(ctx context.Context, attribute fwxschema.Attribute
10051005
Private: resp.Private,
10061006
}
10071007

1008-
logging.FrameworkDebug(
1008+
logging.FrameworkTrace(
10091009
ctx,
10101010
"Calling provider defined planmodifier.Int64",
10111011
map[string]interface{}{
@@ -1015,7 +1015,7 @@ func AttributePlanModifyInt64(ctx context.Context, attribute fwxschema.Attribute
10151015

10161016
planModifier.PlanModifyInt64(ctx, planModifyReq, planModifyResp)
10171017

1018-
logging.FrameworkDebug(
1018+
logging.FrameworkTrace(
10191019
ctx,
10201020
"Called provider defined planmodifier.Int64",
10211021
map[string]interface{}{
@@ -1165,7 +1165,7 @@ func AttributePlanModifyList(ctx context.Context, attribute fwxschema.AttributeW
11651165
Private: resp.Private,
11661166
}
11671167

1168-
logging.FrameworkDebug(
1168+
logging.FrameworkTrace(
11691169
ctx,
11701170
"Calling provider defined planmodifier.List",
11711171
map[string]interface{}{
@@ -1175,7 +1175,7 @@ func AttributePlanModifyList(ctx context.Context, attribute fwxschema.AttributeW
11751175

11761176
planModifier.PlanModifyList(ctx, planModifyReq, planModifyResp)
11771177

1178-
logging.FrameworkDebug(
1178+
logging.FrameworkTrace(
11791179
ctx,
11801180
"Called provider defined planmodifier.List",
11811181
map[string]interface{}{
@@ -1325,7 +1325,7 @@ func AttributePlanModifyMap(ctx context.Context, attribute fwxschema.AttributeWi
13251325
Private: resp.Private,
13261326
}
13271327

1328-
logging.FrameworkDebug(
1328+
logging.FrameworkTrace(
13291329
ctx,
13301330
"Calling provider defined planmodifier.Map",
13311331
map[string]interface{}{
@@ -1335,7 +1335,7 @@ func AttributePlanModifyMap(ctx context.Context, attribute fwxschema.AttributeWi
13351335

13361336
planModifier.PlanModifyMap(ctx, planModifyReq, planModifyResp)
13371337

1338-
logging.FrameworkDebug(
1338+
logging.FrameworkTrace(
13391339
ctx,
13401340
"Called provider defined planmodifier.Map",
13411341
map[string]interface{}{
@@ -1485,7 +1485,7 @@ func AttributePlanModifyNumber(ctx context.Context, attribute fwxschema.Attribut
14851485
Private: resp.Private,
14861486
}
14871487

1488-
logging.FrameworkDebug(
1488+
logging.FrameworkTrace(
14891489
ctx,
14901490
"Calling provider defined planmodifier.Number",
14911491
map[string]interface{}{
@@ -1495,7 +1495,7 @@ func AttributePlanModifyNumber(ctx context.Context, attribute fwxschema.Attribut
14951495

14961496
planModifier.PlanModifyNumber(ctx, planModifyReq, planModifyResp)
14971497

1498-
logging.FrameworkDebug(
1498+
logging.FrameworkTrace(
14991499
ctx,
15001500
"Called provider defined planmodifier.Number",
15011501
map[string]interface{}{
@@ -1645,7 +1645,7 @@ func AttributePlanModifyObject(ctx context.Context, attribute fwxschema.Attribut
16451645
Private: resp.Private,
16461646
}
16471647

1648-
logging.FrameworkDebug(
1648+
logging.FrameworkTrace(
16491649
ctx,
16501650
"Calling provider defined planmodifier.Object",
16511651
map[string]interface{}{
@@ -1655,7 +1655,7 @@ func AttributePlanModifyObject(ctx context.Context, attribute fwxschema.Attribut
16551655

16561656
planModifier.PlanModifyObject(ctx, planModifyReq, planModifyResp)
16571657

1658-
logging.FrameworkDebug(
1658+
logging.FrameworkTrace(
16591659
ctx,
16601660
"Called provider defined planmodifier.Object",
16611661
map[string]interface{}{
@@ -1805,7 +1805,7 @@ func AttributePlanModifySet(ctx context.Context, attribute fwxschema.AttributeWi
18051805
Private: resp.Private,
18061806
}
18071807

1808-
logging.FrameworkDebug(
1808+
logging.FrameworkTrace(
18091809
ctx,
18101810
"Calling provider defined planmodifier.Set",
18111811
map[string]interface{}{
@@ -1815,7 +1815,7 @@ func AttributePlanModifySet(ctx context.Context, attribute fwxschema.AttributeWi
18151815

18161816
planModifier.PlanModifySet(ctx, planModifyReq, planModifyResp)
18171817

1818-
logging.FrameworkDebug(
1818+
logging.FrameworkTrace(
18191819
ctx,
18201820
"Called provider defined planmodifier.Set",
18211821
map[string]interface{}{
@@ -1965,7 +1965,7 @@ func AttributePlanModifyString(ctx context.Context, attribute fwxschema.Attribut
19651965
Private: resp.Private,
19661966
}
19671967

1968-
logging.FrameworkDebug(
1968+
logging.FrameworkTrace(
19691969
ctx,
19701970
"Calling provider defined planmodifier.String",
19711971
map[string]interface{}{
@@ -1975,7 +1975,7 @@ func AttributePlanModifyString(ctx context.Context, attribute fwxschema.Attribut
19751975

19761976
planModifier.PlanModifyString(ctx, planModifyReq, planModifyResp)
19771977

1978-
logging.FrameworkDebug(
1978+
logging.FrameworkTrace(
19791979
ctx,
19801980
"Called provider defined planmodifier.String",
19811981
map[string]interface{}{
@@ -2024,7 +2024,7 @@ func NestedAttributeObjectPlanModify(ctx context.Context, o fwschema.NestedAttri
20242024
Private: resp.Private,
20252025
}
20262026

2027-
logging.FrameworkDebug(
2027+
logging.FrameworkTrace(
20282028
ctx,
20292029
"Calling provider defined planmodifier.Object",
20302030
map[string]interface{}{
@@ -2034,7 +2034,7 @@ func NestedAttributeObjectPlanModify(ctx context.Context, o fwschema.NestedAttri
20342034

20352035
objectPlanModifier.PlanModifyObject(ctx, req, planModifyResp)
20362036

2037-
logging.FrameworkDebug(
2037+
logging.FrameworkTrace(
20382038
ctx,
20392039
"Called provider defined planmodifier.Object",
20402040
map[string]interface{}{

0 commit comments

Comments
 (0)