Skip to content

Commit

Permalink
internal/logging: Ensure @caller in SDK subsystem logging entries a…
Browse files Browse the repository at this point in the history
…ccurately reflects calling code location (#939)

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
```
  • Loading branch information
bflad committed Apr 14, 2022
1 parent b8263cd commit ea02348
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changelog/939.txt
@@ -0,0 +1,7 @@
```release-note:bug
helper/resource: Ensured `@caller` in SDK logging entries accurately reflected calling code location
```

```release-note:bug
helper/schema: Ensured `@caller` in SDK logging entries accurately reflected calling code location
```
12 changes: 10 additions & 2 deletions internal/logging/context.go
Expand Up @@ -13,7 +13,11 @@ import (
// already have the root SDK logger and root provider logger setup from
// terraform-plugin-go tf5server RPC handlers.
func InitContext(ctx context.Context) context.Context {
ctx = tfsdklog.NewSubsystem(ctx, SubsystemHelperSchema, tfsdklog.WithLevelFromEnv(EnvTfLogSdkHelperSchema))
ctx = tfsdklog.NewSubsystem(ctx, SubsystemHelperSchema,
// All calls are through the HelperSchema* helper functions
tfsdklog.WithAdditionalLocationOffset(1),
tfsdklog.WithLevelFromEnv(EnvTfLogSdkHelperSchema),
)

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

ctx = tfsdklog.RegisterTestSink(ctx, t)
ctx = tfsdklog.NewRootSDKLogger(ctx, tfsdklog.WithLevelFromEnv(EnvTfLogSdk))
ctx = tfsdklog.NewSubsystem(ctx, SubsystemHelperResource, tfsdklog.WithLevelFromEnv(EnvTfLogSdkHelperResource))
ctx = tfsdklog.NewSubsystem(ctx, SubsystemHelperResource,
// All calls are through the HelperResource* helper functions
tfsdklog.WithAdditionalLocationOffset(1),
tfsdklog.WithLevelFromEnv(EnvTfLogSdkHelperResource),
)
ctx = TestNameContext(ctx, t.Name())

return ctx
Expand Down

0 comments on commit ea02348

Please sign in to comment.