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

@ -184,6 +184,9 @@ func (r *barResource) Create(ctx context.Context, req resource.CreateRequest, re
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
region := model.Region.ValueString() // not needed for global APIs
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -203,6 +206,8 @@ func (r *barResource) Create(ctx context.Context, req resource.CreateRequest, re
return
}
ctx = core.LogResponse(ctx)
// only in case the create bar API call is asynchronous (Make sure to include *ALL* fields which are part of the
// internal terraform resource id! And please include the comment below in your code):
// Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
@ -244,6 +249,9 @@ func (r *barResource) Read(ctx context.Context, req resource.ReadRequest, resp *
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
barId := model.BarId.ValueString()
@ -257,6 +265,8 @@ func (r *barResource) Read(ctx context.Context, req resource.ReadRequest, resp *
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(barResp, &model)
if err != nil {
@ -285,6 +295,9 @@ func (r *barResource) Delete(ctx context.Context, req resource.DeleteRequest, re
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
region := model.Region.ValueString()
barId := model.BarId.ValueString()
@ -298,6 +311,8 @@ func (r *barResource) Delete(ctx context.Context, req resource.DeleteRequest, re
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting bar", fmt.Sprintf("Calling API: %v", err))
}
ctx = core.LogResponse(ctx)
// only in case the bar delete API endpoint is asynchronous: use a wait handler to wait for the delete operation to complete
_, err = wait.DeleteBarWaitHandler(ctx, r.client, projectId, region, barId).WaitWithContext(ctx)
if err != nil {