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

@ -146,6 +146,8 @@ func (d *projectDataSource) Read(ctx context.Context, req datasource.ReadRequest
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -181,6 +183,8 @@ func (d *projectDataSource) Read(ctx context.Context, req datasource.ReadRequest
return
}
ctx = core.LogResponse(ctx)
err = mapProjectFields(ctx, projectResp, &model, &resp.State)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading project", fmt.Sprintf("Processing API response: %v", err))

View file

@ -196,6 +196,8 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest
return
}
ctx = core.InitProviderContext(ctx)
containerId := model.ContainerId.ValueString()
ctx = tflog.SetField(ctx, "project_container_id", containerId)
@ -211,6 +213,9 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating project", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
respContainerId := *createResp.ContainerId
// If the request has not been processed yet and the containerId doesn't exist,
@ -244,6 +249,9 @@ func (r *projectResource) Read(ctx context.Context, req resource.ReadRequest, re
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
containerId := model.ContainerId.ValueString()
ctx = tflog.SetField(ctx, "container_id", containerId)
@ -258,6 +266,8 @@ func (r *projectResource) Read(ctx context.Context, req resource.ReadRequest, re
return
}
ctx = core.LogResponse(ctx)
err = mapProjectFields(ctx, projectResp, &model.Model, &resp.State)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading project", fmt.Sprintf("Processing API response: %v", err))
@ -282,6 +292,9 @@ func (r *projectResource) Update(ctx context.Context, req resource.UpdateRequest
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
containerId := model.ContainerId.ValueString()
ctx = tflog.SetField(ctx, "container_id", containerId)
@ -298,6 +311,8 @@ func (r *projectResource) Update(ctx context.Context, req resource.UpdateRequest
return
}
ctx = core.LogResponse(ctx)
// Fetch updated project
projectResp, err := r.client.GetProject(ctx, containerId).Execute()
if err != nil {
@ -329,6 +344,8 @@ func (r *projectResource) Delete(ctx context.Context, req resource.DeleteRequest
return
}
ctx = core.InitProviderContext(ctx)
containerId := model.ContainerId.ValueString()
ctx = tflog.SetField(ctx, "container_id", containerId)
@ -339,6 +356,8 @@ func (r *projectResource) Delete(ctx context.Context, req resource.DeleteRequest
return
}
ctx = core.LogResponse(ctx)
_, err = wait.DeleteProjectWaitHandler(ctx, r.client, containerId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting project", fmt.Sprintf("Instance deletion waiting: %v", err))