Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/logging: Ensure @caller in SDK subsystem logging entries accurately reflects calling code location #939

Merged
merged 4 commits into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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),
})
bflad marked this conversation as resolved.
Show resolved Hide resolved

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