diff --git a/.changelog/939.txt b/.changelog/939.txt new file mode 100644 index 00000000000..08c6a891774 --- /dev/null +++ b/.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 +``` diff --git a/internal/logging/context.go b/internal/logging/context.go index 7ab00a18217..7dc62b396ba 100644 --- a/internal/logging/context.go +++ b/internal/logging/context.go @@ -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 } @@ -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