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

@ -136,6 +136,9 @@ func (d *recordSetDataSource) Read(ctx context.Context, req datasource.ReadReque
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
zoneId := model.ZoneId.ValueString()
recordSetId := model.RecordSetId.ValueString()
@ -157,6 +160,9 @@ func (d *recordSetDataSource) Read(ctx context.Context, req datasource.ReadReque
resp.State.RemoveResource(ctx)
return
}
ctx = core.LogResponse(ctx)
if recordSetResp != nil && recordSetResp.Rrset.State != nil && *recordSetResp.Rrset.State == dns.RECORDSETSTATE_DELETE_SUCCEEDED {
resp.State.RemoveResource(ctx)
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading record set", "Record set was deleted successfully")

View file

@ -200,6 +200,8 @@ func (r *recordSetResource) Create(ctx context.Context, req resource.CreateReque
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
zoneId := model.ZoneId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -218,6 +220,8 @@ func (r *recordSetResource) Create(ctx context.Context, req resource.CreateReque
return
}
ctx = core.LogResponse(ctx)
// Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
"project_id": projectId,
@ -257,6 +261,9 @@ func (r *recordSetResource) Read(ctx context.Context, req resource.ReadRequest,
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
zoneId := model.ZoneId.ValueString()
recordSetId := model.RecordSetId.ValueString()
@ -274,6 +281,8 @@ func (r *recordSetResource) Read(ctx context.Context, req resource.ReadRequest,
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(ctx, recordSetResp, &model)
if err != nil {
@ -300,6 +309,8 @@ func (r *recordSetResource) Update(ctx context.Context, req resource.UpdateReque
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
zoneId := model.ZoneId.ValueString()
recordSetId := model.RecordSetId.ValueString()
@ -319,6 +330,9 @@ func (r *recordSetResource) Update(ctx context.Context, req resource.UpdateReque
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating record set", err.Error())
return
}
ctx = core.LogResponse(ctx)
waitResp, err := wait.PartialUpdateRecordSetWaitHandler(ctx, r.client, projectId, zoneId, recordSetId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating record set", fmt.Sprintf("Instance update waiting: %v", err))
@ -348,6 +362,8 @@ func (r *recordSetResource) Delete(ctx context.Context, req resource.DeleteReque
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
zoneId := model.ZoneId.ValueString()
recordSetId := model.RecordSetId.ValueString()
@ -360,6 +376,9 @@ func (r *recordSetResource) Delete(ctx context.Context, req resource.DeleteReque
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting record set", fmt.Sprintf("Calling API: %v", err))
}
ctx = core.LogResponse(ctx)
_, err = wait.DeleteRecordSetWaitHandler(ctx, r.client, projectId, zoneId, recordSetId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting record set", fmt.Sprintf("Instance deletion waiting: %v", err))

View file

@ -179,6 +179,9 @@ func (d *zoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
zoneId := model.ZoneId.ValueString()
dnsName := model.DnsName.ValueString()
@ -205,6 +208,8 @@ func (d *zoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
resp.State.RemoveResource(ctx)
return
}
ctx = core.LogResponse(ctx)
} else {
listZoneResp, err := d.client.ListZones(ctx, projectId).
DnsNameEq(dnsName).
@ -224,6 +229,9 @@ func (d *zoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
resp.State.RemoveResource(ctx)
return
}
ctx = core.LogResponse(ctx)
if *listZoneResp.TotalItems != 1 {
utils.LogError(
ctx,

View file

@ -284,6 +284,8 @@ func (r *zoneResource) Create(ctx context.Context, req resource.CreateRequest, r
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -300,6 +302,8 @@ func (r *zoneResource) Create(ctx context.Context, req resource.CreateRequest, r
return
}
ctx = core.LogResponse(ctx)
// Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
zoneId := *createResp.Zone.Id
utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]interface{}{
@ -338,6 +342,9 @@ func (r *zoneResource) Read(ctx context.Context, req resource.ReadRequest, resp
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
zoneId := model.ZoneId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -348,6 +355,9 @@ func (r *zoneResource) Read(ctx context.Context, req resource.ReadRequest, resp
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading zone", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
if zoneResp != nil && zoneResp.Zone.State != nil && *zoneResp.Zone.State == dns.ZONESTATE_DELETE_SUCCEEDED {
resp.State.RemoveResource(ctx)
return
@ -377,6 +387,9 @@ func (r *zoneResource) Update(ctx context.Context, req resource.UpdateRequest, r
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
zoneId := model.ZoneId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -394,6 +407,9 @@ func (r *zoneResource) Update(ctx context.Context, req resource.UpdateRequest, r
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating zone", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
waitResp, err := wait.PartialUpdateZoneWaitHandler(ctx, r.client, projectId, zoneId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating zone", fmt.Sprintf("Zone update waiting: %v", err))
@ -423,6 +439,8 @@ func (r *zoneResource) Delete(ctx context.Context, req resource.DeleteRequest, r
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
zoneId := model.ZoneId.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
@ -434,6 +452,9 @@ func (r *zoneResource) Delete(ctx context.Context, req resource.DeleteRequest, r
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting zone", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
_, err = wait.DeleteZoneWaitHandler(ctx, r.client, projectId, zoneId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting zone", fmt.Sprintf("Zone deletion waiting: %v", err))