feat: add logging for trace id (#1061)

relates to STACKITTPR-290
This commit is contained in:
Marcel Jacek 2025-11-27 11:06:18 +01:00 committed by GitHub
parent d1e12fcf64
commit 24b7387db9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
140 changed files with 1597 additions and 7 deletions

View file

@ -385,6 +385,9 @@ func (r *loadBalancerDataSource) Read(ctx context.Context, req datasource.ReadRe
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
name := model.Name.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
@ -408,6 +411,8 @@ func (r *loadBalancerDataSource) Read(ctx context.Context, req datasource.ReadRe
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(ctx, lbResp, &model, region)
if err != nil {

View file

@ -8,7 +8,6 @@ import (
"time"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
loadbalancerUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/loadbalancer/utils"
"github.com/google/uuid"
@ -750,6 +749,9 @@ func (r *loadBalancerResource) Create(ctx context.Context, req resource.CreateRe
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
region := model.Region.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -769,6 +771,8 @@ func (r *loadBalancerResource) Create(ctx context.Context, req resource.CreateRe
return
}
ctx = core.LogResponse(ctx)
waitResp, err := wait.CreateLoadBalancerWaitHandler(ctx, r.client, projectId, region, *createResp.Name).SetTimeout(90 * time.Minute).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating load balancer", fmt.Sprintf("Load balancer creation waiting: %v", err))
@ -800,6 +804,9 @@ func (r *loadBalancerResource) Read(ctx context.Context, req resource.ReadReques
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
name := model.Name.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
@ -819,6 +826,8 @@ func (r *loadBalancerResource) Read(ctx context.Context, req resource.ReadReques
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(ctx, lbResp, &model, region)
if err != nil {
@ -844,6 +853,9 @@ func (r *loadBalancerResource) Update(ctx context.Context, req resource.UpdateRe
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
name := model.Name.ValueString()
region := model.Region.ValueString()
@ -875,6 +887,8 @@ func (r *loadBalancerResource) Update(ctx context.Context, req resource.UpdateRe
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating load balancer", fmt.Sprintf("Calling API for target pool: %v", err))
return
}
ctx = core.LogResponse(ctx)
}
ctx = tflog.SetField(ctx, "target_pool_name", nil)
@ -910,6 +924,9 @@ func (r *loadBalancerResource) Delete(ctx context.Context, req resource.DeleteRe
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
name := model.Name.ValueString()
region := model.Region.ValueString()
@ -924,6 +941,8 @@ func (r *loadBalancerResource) Delete(ctx context.Context, req resource.DeleteRe
return
}
ctx = core.LogResponse(ctx)
_, err = wait.DeleteLoadBalancerWaitHandler(ctx, r.client, projectId, region, name).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting load balancer", fmt.Sprintf("Load balancer deleting waiting: %v", err))

View file

@ -188,6 +188,9 @@ func (r *observabilityCredentialResource) Create(ctx context.Context, req resour
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
region := model.Region.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -206,6 +209,9 @@ func (r *observabilityCredentialResource) Create(ctx context.Context, req resour
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating observability credential", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
ctx = tflog.SetField(ctx, "credentials_ref", createResp.Credential.CredentialsRef)
// Map response body to schema
@ -233,6 +239,9 @@ func (r *observabilityCredentialResource) Read(ctx context.Context, req resource
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsRef := model.CredentialsRef.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
@ -252,6 +261,8 @@ func (r *observabilityCredentialResource) Read(ctx context.Context, req resource
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(credResp.Credential, &model, region)
if err != nil {
@ -281,6 +292,9 @@ func (r *observabilityCredentialResource) Delete(ctx context.Context, req resour
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsRef := model.CredentialsRef.ValueString()
region := model.Region.ValueString()
@ -295,6 +309,8 @@ func (r *observabilityCredentialResource) Delete(ctx context.Context, req resour
return
}
ctx = core.LogResponse(ctx)
tflog.Info(ctx, "Load balancer observability credential deleted")
}