Skip to content

Commit

Permalink
fix(cli): Don't send telemetry events if request body is larger than 8KB
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarm committed Nov 7, 2023
1 parent 67c624b commit 5a12c7b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/@cdktf/commons/src/checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const BASE_URL = `https://checkpoint-api.hashicorp.com/v1/`;

const VALID_STATUS_CODES = [200, 201];

const MAX_REQUEST_BODY_SIZE = 8192;

function homeDir() {
return process.env.CDKTF_HOME
? path.resolve(process.env.CDKTF_HOME)
Expand Down Expand Up @@ -183,6 +185,13 @@ export async function ReportRequest(reportParams: ReportParams): Promise<void> {

const postData = JSON.stringify(reportParams);

if (postData.length > MAX_REQUEST_BODY_SIZE) {
logger.warn(
`Skipped sending telemetry as the request body size was ${postData.length} bytes. The limit is ${MAX_REQUEST_BODY_SIZE} bytes`
);
return;
}

try {
await post(`${BASE_URL}telemetry/${reportParams.product}`, postData);
} catch (e: any) {
Expand Down

0 comments on commit 5a12c7b

Please sign in to comment.