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

@ -211,6 +211,9 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -232,6 +235,8 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
return
}
ctx = core.LogResponse(ctx)
err = mapFields(instanceResp, &model)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API payload: %v", err))

View file

@ -325,6 +325,9 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -356,6 +359,9 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
instanceId := *createResp.InstanceId
ctx = tflog.SetField(ctx, "instance_id", instanceId)
waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client, projectId, instanceId).WaitWithContext(ctx)
@ -388,6 +394,9 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -404,6 +413,8 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(instanceResp, &model)
if err != nil {
@ -435,6 +446,9 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -468,6 +482,9 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
waitResp, err := wait.PartialUpdateInstanceWaitHandler(ctx, r.client, projectId, instanceId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Instance update waiting: %v", err))
@ -498,6 +515,9 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -509,6 +529,9 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
_, err = wait.DeleteInstanceWaitHandler(ctx, r.client, projectId, instanceId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Instance deletion waiting: %v", err))