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

@ -179,6 +179,8 @@ func (r *serviceAccountTokenResource) Create(ctx context.Context, req resource.C
return
}
ctx = core.InitProviderContext(ctx)
// Set logging context with the project ID and service account email.
projectId := model.ProjectId.ValueString()
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
@ -194,12 +196,13 @@ func (r *serviceAccountTokenResource) Create(ctx context.Context, req resource.C
// Initialize the API request with the required parameters.
serviceAccountAccessTokenResp, err := r.client.CreateAccessToken(ctx, projectId, serviceAccountEmail).CreateAccessTokenPayload(*payload).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Failed to create service account access token", fmt.Sprintf("API call error: %v", err))
return
}
ctx = core.LogResponse(ctx)
// Map the response to the resource schema.
err = mapCreateResponse(serviceAccountAccessTokenResp, &model)
if err != nil {
@ -227,6 +230,8 @@ func (r *serviceAccountTokenResource) Read(ctx context.Context, req resource.Rea
return
}
ctx = core.InitProviderContext(ctx)
// Extract the project ID and serviceAccountEmail for the service account.
projectId := model.ProjectId.ValueString()
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
@ -245,6 +250,8 @@ func (r *serviceAccountTokenResource) Read(ctx context.Context, req resource.Rea
return
}
ctx = core.LogResponse(ctx)
// Iterate over the list of service account tokens to find the one that matches the ID from the state.
saTokens := *listSaTokensResp.Items
for i := range saTokens {
@ -296,6 +303,8 @@ func (r *serviceAccountTokenResource) Delete(ctx context.Context, req resource.D
return
}
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
serviceAccountEmail := model.ServiceAccountEmail.ValueString()
accessTokenId := model.AccessTokenId.ValueString()
@ -309,6 +318,9 @@ func (r *serviceAccountTokenResource) Delete(ctx context.Context, req resource.D
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting service account token", fmt.Sprintf("Calling API: %v", err))
return
}
ctx = core.LogResponse(ctx)
tflog.Info(ctx, "Service account token deleted")
}