Skip to content

(core): cdk migrate telemetry metadata is lost due to unassigned .concat() #37192

@Aaxhirrr

Description

@Aaxhirrr

Describe the bug

In packages/aws-cdk-lib/core/lib/private/metadata-resource.ts, the code attempts to append a migration-specific suffix to the telemetry analyticsString when the project is created via cdk migrate.

However, it uses the .concat() method on a string without assigning the result back to the variable. Since strings in JavaScript are immutable, the .concat() call returns a new string that is immediately discarded, leaving the original analyticsString unchanged. Consequently, telemetry for cdk migrate is never reported.

Expected Behavior

When the @aws-cdk/core:cdk-migrate context flag is set, the generated metadata should include the :cdk-migrate suffix (compressed and base64 encoded) so that AWS can track the usage of the migration tool.

Current Behavior

The code executes analyticsString.concat(...) but does not update the analyticsString variable. The returned metadata remains identical to a standard (non-migrated) project, causing a silent loss of telemetry.

Reproduction Steps

The bug is visible in this logic block:

// packages/aws-cdk-lib/core/lib/private/metadata-resource.ts

if (process.env.CDK_CONTEXT_JSON && JSON.parse(process.env.CDK_CONTEXT_JSON)['cdk-migrate']) {
  const compressedAppInfoBuffer = zlib.gzipSync(Buffer.from('cdk-migrate'));
  const compressedAppInfo = compressedAppInfoBuffer.toString('base64');
  
  // BUG: Result is not assigned! 
  // Should be: analyticsString = analyticsString.concat(...)
  analyticsString.concat(':', compressedAppInfo); 
}

We can reproduce this behavior with a simple script:

let analyticsString = "v2:deflate64:base64data";
let suffix = ":compressed-migrate-tag";

// This mimics the bug in the CDK source
analyticsString.concat(suffix); 

console.log(analyticsString.includes(suffix)); // Output: false

Possible Solution

Change line 129 in metadata-resource.ts to assign the result or use string interpolation:

analyticsString += `:${compressedAppInfo}`;

Environment Information

  • AWS CDK Library version: 2.241.0
  • Node.js Version: v20.20.0
  • OS: Windows
  • Language: TypeScript

Other information

The failure to capture analytics for cdk migrate represents a significant loss of visibility into the adoption and performance of the migration tooling.

I have a reproduction script ready and can provide a PR to fix this if requested.

@pahud Would love your insights on this investigation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions