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

@ -113,6 +113,9 @@ func (r *bucketDataSource) Read(ctx context.Context, req datasource.ReadRequest,
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
bucketName := model.Name.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
@ -137,6 +140,8 @@ func (r *bucketDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(bucketResp, &model, region)
if err != nil {

View file

@ -178,6 +178,9 @@ func (r *bucketResource) Create(ctx context.Context, req resource.CreateRequest,
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
bucketName := model.Name.ValueString()
region := model.Region.ValueString()
@ -200,6 +203,8 @@ func (r *bucketResource) Create(ctx context.Context, req resource.CreateRequest,
return
}
ctx = core.LogResponse(ctx)
waitResp, err := wait.CreateBucketWaitHandler(ctx, r.client, projectId, region, bucketName).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating bucket", fmt.Sprintf("Bucket creation waiting: %v", err))
@ -228,6 +233,9 @@ func (r *bucketResource) Read(ctx context.Context, req resource.ReadRequest, res
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
bucketName := model.Name.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
@ -247,6 +255,8 @@ func (r *bucketResource) Read(ctx context.Context, req resource.ReadRequest, res
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(bucketResp, &model, region)
if err != nil {
@ -277,6 +287,9 @@ func (r *bucketResource) Delete(ctx context.Context, req resource.DeleteRequest,
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
bucketName := model.Name.ValueString()
region := model.Region.ValueString()
@ -297,6 +310,9 @@ func (r *bucketResource) Delete(ctx context.Context, req resource.DeleteRequest,
}
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting bucket", fmt.Sprintf("Calling API: %v", err))
}
ctx = core.LogResponse(ctx)
_, err = wait.DeleteBucketWaitHandler(ctx, r.client, projectId, region, bucketName).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting bucket", fmt.Sprintf("Bucket deletion waiting: %v", err))

View file

@ -120,6 +120,8 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
credentialId := model.CredentialId.ValueString()
@ -145,6 +147,9 @@ func (r *credentialDataSource) Read(ctx context.Context, req datasource.ReadRequ
resp.State.RemoveResource(ctx)
return
}
ctx = core.LogResponse(ctx)
if credentialsGroupResp == nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Reading credentials", fmt.Sprintf("Response is nil: %v", err))
return

View file

@ -248,6 +248,9 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
region := model.Region.ValueString()
@ -275,6 +278,9 @@ func (r *credentialResource) Create(ctx context.Context, req resource.CreateRequ
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
if credentialResp.KeyId == nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating credential", "Got empty credential id")
return
@ -326,6 +332,8 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
credentialId := model.CredentialId.ValueString()
@ -341,6 +349,9 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credential", fmt.Sprintf("Finding credential: %v", err))
return
}
ctx = core.LogResponse(ctx)
if !found {
resp.State.RemoveResource(ctx)
return
@ -399,6 +410,8 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
credentialId := model.CredentialId.ValueString()
@ -415,6 +428,8 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err))
}
ctx = core.LogResponse(ctx)
tflog.Info(ctx, "ObjectStorage credential deleted")
}

View file

@ -111,6 +111,9 @@ func (r *credentialsGroupDataSource) Read(ctx context.Context, req datasource.Re
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
@ -124,6 +127,9 @@ func (r *credentialsGroupDataSource) Read(ctx context.Context, req datasource.Re
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credentials group", fmt.Sprintf("getting credential group from list of credentials groups: %v", err))
return
}
ctx = core.LogResponse(ctx)
if !found {
resp.State.RemoveResource(ctx)
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credentials group", fmt.Sprintf("Credentials group with ID %q does not exists in project %q", credentialsGroupId, projectId))

View file

@ -176,6 +176,9 @@ func (r *credentialsGroupResource) Create(ctx context.Context, req resource.Crea
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsGroupName := model.Name.ValueString()
region := model.Region.ValueString()
@ -202,6 +205,8 @@ func (r *credentialsGroupResource) Create(ctx context.Context, req resource.Crea
return
}
ctx = core.LogResponse(ctx)
// Map response body to schema
err = mapFields(got, &model, region)
if err != nil {
@ -224,6 +229,9 @@ func (r *credentialsGroupResource) Read(ctx context.Context, req resource.ReadRe
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
region := r.providerData.GetRegionWithOverride(model.Region)
@ -237,6 +245,9 @@ func (r *credentialsGroupResource) Read(ctx context.Context, req resource.ReadRe
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading credentialsGroup", fmt.Sprintf("getting credential group from list of credentials groups: %v", err))
return
}
ctx = core.LogResponse(ctx)
if !found {
resp.State.RemoveResource(ctx)
return
@ -267,6 +278,9 @@ func (r *credentialsGroupResource) Delete(ctx context.Context, req resource.Dele
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
credentialsGroupId := model.CredentialsGroupId.ValueString()
region := model.Region.ValueString()
@ -281,6 +295,8 @@ func (r *credentialsGroupResource) Delete(ctx context.Context, req resource.Dele
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credentials group", fmt.Sprintf("Calling API: %v", err))
}
ctx = core.LogResponse(ctx)
tflog.Info(ctx, "ObjectStorage credentials group deleted")
}