From 9734c12bda4acf13ab1cfc6bd073aa5d0ebce17d Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 12 Apr 2022 13:57:05 -0400 Subject: [PATCH] internal/logging: Add missing AdditionalLocationOffset for protocol logging (#179) Previously (note `@caller`): ``` 2022-04-12T11:11:25.684-0400 [TRACE] provider.terraform-provider-aws: Received request: @caller=/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.8.0/internal/logging/protocol.go:21 @module=sdk.proto tf_rpc=GetProviderSchema tf_proto_version=5.2 tf_provider_addr=provider tf_req_id=0c818104-0f9d-2bb3-1fa5-998a35ecae3e timestamp=2022-04-12T11:11:25.684-0400 2022-04-12T11:11:25.684-0400 [TRACE] provider.terraform-provider-aws: Calling downstream: tf_rpc=GetProviderSchema @caller=/Users/bflad/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.8.0/internal/logging/protocol.go:21 @module=sdk.proto tf_provider_addr=provider tf_req_id=0c818104-0f9d-2bb3-1fa5-998a35ecae3e tf_proto_version=5.2 timestamp=2022-04-12T11:11:25.684-0400 ``` Now: ``` 2022-04-12T11:32:32.867-0400 [TRACE] provider.terraform-provider-aws: Received request: @module=sdk.proto tf_req_id=89b3ee71-db56-42cb-75ce-3cfd6cd50589 tf_rpc=GetProviderSchema @caller=/Users/bflad/src/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:490 tf_proto_version=5.2 tf_provider_addr=provider timestamp=2022-04-12T11:32:32.867-0400 2022-04-12T11:32:32.867-0400 [TRACE] provider.terraform-provider-aws: Calling downstream: @caller=/Users/bflad/src/github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server/server.go:497 tf_proto_version=5.2 tf_req_id=89b3ee71-db56-42cb-75ce-3cfd6cd50589 tf_rpc=GetProviderSchema @module=sdk.proto tf_provider_addr=provider timestamp=2022-04-12T11:32:32.867-0400 ``` --- .changelog/179.txt | 7 +++++++ internal/logging/context.go | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 .changelog/179.txt diff --git a/.changelog/179.txt b/.changelog/179.txt new file mode 100644 index 000000000..1096af638 --- /dev/null +++ b/.changelog/179.txt @@ -0,0 +1,7 @@ +```release-note:bug +tfprotov5/tf5server: Ensured `@caller` in protocol logging entries accurately reflected calling code location +``` + +```release-note:bug +tfprotov6/tf6server: Ensured `@caller` in protocol logging entries accurately reflected calling code location +``` diff --git a/internal/logging/context.go b/internal/logging/context.go index 3407b4a6e..a35258a8e 100644 --- a/internal/logging/context.go +++ b/internal/logging/context.go @@ -23,6 +23,8 @@ func InitContext(ctx context.Context, sdkOpts tfsdklog.Options, providerOpts tfl tfsdklog.WithLevelFromEnv(EnvTfLogSdk), }, sdkOpts...)...) ctx = tfsdklog.NewSubsystem(ctx, SubsystemProto, append(tfsdklog.Options{ + // All calls are through the Protocol* helper functions + tfsdklog.WithAdditionalLocationOffset(1), tfsdklog.WithLevelFromEnv(EnvTfLogSdkProto), }, sdkOpts...)...) ctx = tfsdklog.NewRootProviderLogger(ctx, providerOpts...)