Skip to content

Commit 84d71d0

Browse files
committed
internal/logging: Ensure @caller in SDK subsystem logging entries accurately reflects calling code location
Reference: hashicorp/terraform-plugin-go#179 Previously: ``` 2022-04-12T11:11:26.086-0400 [TRACE] provider.terraform-provider-aws: Found data source type: @caller=/Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/internal/logging/helper_schema.go:21 @module=sdk.helper_schema tf_data_source_type=aws_connect_bot_association timestamp=2022-04-12T11:11:25.917-0400 2022-04-12T11:11:26.086-0400 [TRACE] provider.terraform-provider-aws: Found data source type: @caller=/Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/internal/logging/helper_schema.go:21 @module=sdk.helper_schema tf_data_source_type=aws_datapipeline_pipeline timestamp=2022-04-12T11:11:25.917-0400 ``` Now: ``` 2022-04-12T14:54:22.571-0400 [TRACE] provider.terraform-provider-aws: Found data source type: @module=sdk.helper_schema tf_data_source_type=aws_connect_bot_association @caller=/Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/grpc_provider.go:95 timestamp=2022-04-12T14:54:22.571-0400 2022-04-12T14:54:22.574-0400 [TRACE] provider.terraform-provider-aws: Found data source type: @module=sdk.helper_schema tf_data_source_type=aws_datapipeline_pipeline @caller=/Users/bflad/src/github.com/hashicorp/terraform-plugin-sdk/helper/schema/grpc_provider.go:95 timestamp=2022-04-12T14:54:22.574-0400 ```
1 parent 3d0fec0 commit 84d71d0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

.changelog/pending.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:bug
2+
helper/resource: Ensured `@caller` in SDK logging entries accurately reflected calling code location
3+
```
4+
5+
```release-note:bug
6+
helper/schema: Ensured `@caller` in SDK logging entries accurately reflected calling code location
7+
```

internal/logging/context.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import (
1313
// already have the root SDK logger and root provider logger setup from
1414
// terraform-plugin-go tf5server RPC handlers.
1515
func InitContext(ctx context.Context) context.Context {
16-
ctx = tfsdklog.NewSubsystem(ctx, SubsystemHelperSchema, tfsdklog.WithLevelFromEnv(EnvTfLogSdkHelperSchema))
16+
ctx = tfsdklog.NewSubsystem(ctx, SubsystemHelperSchema, tfsdklog.Options{
17+
// All calls are through the HelperSchema* helper functions
18+
tfsdklog.WithAdditionalLocationOffset(1),
19+
tfsdklog.WithLevelFromEnv(EnvTfLogSdkHelperSchema),
20+
}...)
1721

1822
return ctx
1923
}
@@ -30,7 +34,11 @@ func InitTestContext(ctx context.Context, t testing.T) context.Context {
3034

3135
ctx = tfsdklog.RegisterTestSink(ctx, t)
3236
ctx = tfsdklog.NewRootSDKLogger(ctx, tfsdklog.WithLevelFromEnv(EnvTfLogSdk))
33-
ctx = tfsdklog.NewSubsystem(ctx, SubsystemHelperResource, tfsdklog.WithLevelFromEnv(EnvTfLogSdkHelperResource))
37+
ctx = tfsdklog.NewSubsystem(ctx, SubsystemHelperResource, tfsdklog.Options{
38+
// All calls are through the HelperResource* helper functions
39+
tfsdklog.WithAdditionalLocationOffset(1),
40+
tfsdklog.WithLevelFromEnv(EnvTfLogSdkHelperResource),
41+
}...)
3442
ctx = TestNameContext(ctx, t.Name())
3543

3644
return ctx

0 commit comments

Comments
 (0)