Commit 930a517
authored
Implement protocol data logging (#135)
Reference: #107
Refactors `tf5server` and `tf6server` log handling into shared internal/logging package to prevent additional code duplication.
To enable protocol data handling, utilizes the `TF_LOG_SDK_PROTO_DATA_DIR` environment variable to enable writing individual data field files to disk. In the future, this may need to be offered as a server configuration so it can work better in conjunction with testing frameworks (e.g. `t.TempDir()`), but there should not be too much preventing that as a later enhancement as necessary.
Without `TF_LOG_SDK_PROTO_DATA_DIR` set (once):
```text
2022-01-06T16:04:54.787-0500 [TRACE] provider.terraform-provider-framework: Skipping protocol data file writing because no data directory is set. Use the TF_LOG_SDK_PROTO_DATA_DIR environment variable to enable this functionality.: tf_req_id=105b9e19-be94-411d-2f52-ca84c14f951e tf_resource_type=framework_optional_types tf_rpc=ValidateResourceConfig @caller=/Users/bflad/src/github.com/hashicorp/terraform-plugin-go/internal/logging/protocol.go:21 @module=sdk.proto EXTRA_VALUE_AT_END=<nil> tf_provider_addr=registry.terraform.io/bflad/framework tf_proto_version=6 timestamp=2022-01-06T16:04:54.786-0500
```
With `TF_LOG_SDK_PROTO_DATA_DIR` set (per `DynamicValue` field):
```text
2022-01-06T16:06:36.079-0500 [TRACE] provider.terraform-provider-framework: Writing protocol data file: EXTRA_VALUE_AT_END=[tf_proto_data_file, 1641503196_ValidateResourceConfig_Request_Config.msgpack] tf_rpc=ValidateResourceConfig @module=sdk.proto tf_proto_version=6 tf_provider_addr=registry.terraform.io/bflad/framework tf_req_id=9084bc21-f6d1-bcc8-b916-fe75595375d2 tf_resource_type=framework_optional_types @caller=/Users/bflad/src/github.com/hashicorp/terraform-plugin-go/internal/logging/protocol.go:21 timestamp=2022-01-06T16:06:36.079-0500
```
Viewing example MessagePack file contents:
```console
$ go install github.com/nokute78/msgpack-microscope/cmd/msgpack2json@latest
$ msgpack2json 1641503196_PlanResourceChange_Request_Config.msgpack | jq .
{
"format": "fixmap",
"header": "0x85",
"length": 5,
"raw": "0x85a26964c0b36f7074696f6e616c5f74797065735f626f6f6cc0b66f7074696f6e616c5f74797065735f666c6f61743634c0b46f7074696f6e616c5f74797065735f696e743634c0b56f7074696f6e616c5f74797065735f737472696e67c0",
"value": [
{
"key": {
"format": "fixstr",
"header": "0xa2",
"raw": "0xa26964",
"value": "id"
},
"value": {
"format": "nil",
"header": "0xc0",
"raw": "0xc0",
"value": null
}
},
{
"key": {
"format": "fixstr",
"header": "0xb3",
"raw": "0xb36f7074696f6e616c5f74797065735f626f6f6c",
"value": "optional_types_bool"
},
"value": {
"format": "nil",
"header": "0xc0",
"raw": "0xc0",
"value": null
}
},
{
"key": {
"format": "fixstr",
"header": "0xb6",
"raw": "0xb66f7074696f6e616c5f74797065735f666c6f61743634",
"value": "optional_types_float64"
},
"value": {
"format": "nil",
"header": "0xc0",
"raw": "0xc0",
"value": null
}
},
{
"key": {
"format": "fixstr",
"header": "0xb4",
"raw": "0xb46f7074696f6e616c5f74797065735f696e743634",
"value": "optional_types_int64"
},
"value": {
"format": "nil",
"header": "0xc0",
"raw": "0xc0",
"value": null
}
},
{
"key": {
"format": "fixstr",
"header": "0xb5",
"raw": "0xb56f7074696f6e616c5f74797065735f737472696e67",
"value": "optional_types_string"
},
"value": {
"format": "nil",
"header": "0xc0",
"raw": "0xc0",
"value": null
}
}
]
}
```1 parent 5ad95e8 commit 930a517
File tree
12 files changed
+730
-368
lines changed- .changelog
- internal/logging
- tfprotov5/tf5server
- tfprotov6/tf6server
12 files changed
+730
-368
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
122 | 126 | | |
123 | 127 | | |
124 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
0 commit comments