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

@ -190,6 +190,9 @@ func (d *scrapeConfigDataSource) Read(ctx context.Context, req datasource.ReadRe
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
scName := model.Name.ValueString()
@ -210,6 +213,8 @@ func (d *scrapeConfigDataSource) Read(ctx context.Context, req datasource.ReadRe
return
}
ctx = core.LogResponse(ctx)
err = mapFields(ctx, scResp.Data, &model)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Mapping fields", err.Error())

View file

@ -305,6 +305,8 @@ func (r *scrapeConfigResource) Create(ctx context.Context, req resource.CreateRe
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
scName := model.Name.ValueString()
@ -347,6 +349,9 @@ func (r *scrapeConfigResource) Create(ctx context.Context, req resource.CreateRe
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating scrape config", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
_, err = wait.CreateScrapeConfigWaitHandler(ctx, r.client, instanceId, scName, projectId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating scrape config", fmt.Sprintf("Scrape config creation waiting: %v", err))
@ -379,6 +384,9 @@ func (r *scrapeConfigResource) Read(ctx context.Context, req resource.ReadReques
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
scName := model.Name.ValueString()
@ -394,6 +402,8 @@ func (r *scrapeConfigResource) Read(ctx context.Context, req resource.ReadReques
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(ctx, scResp.Data, &model)
if err != nil {
@ -418,6 +428,9 @@ func (r *scrapeConfigResource) Update(ctx context.Context, req resource.UpdateRe
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
scName := model.Name.ValueString()
@ -460,6 +473,9 @@ func (r *scrapeConfigResource) Update(ctx context.Context, req resource.UpdateRe
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating scrape config", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
// We do not have an update status provided by the observability scrape config api, so we cannot use a waiter here, hence a simple sleep is used.
time.Sleep(15 * time.Second)
@ -492,6 +508,8 @@ func (r *scrapeConfigResource) Delete(ctx context.Context, req resource.DeleteRe
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
scName := model.Name.ValueString()
@ -502,6 +520,9 @@ func (r *scrapeConfigResource) Delete(ctx context.Context, req resource.DeleteRe
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting scrape config", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
_, err = wait.DeleteScrapeConfigWaitHandler(ctx, r.client, instanceId, scName, projectId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting scrape config", fmt.Sprintf("Scrape config deletion waiting: %v", err))