Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-cdk-lib: Missing tags when synthesizing after bundling code with esbuild #26169

Closed
Nevon opened this issue Jun 29, 2023 · 4 comments · Fixed by #26181
Closed

aws-cdk-lib: Missing tags when synthesizing after bundling code with esbuild #26169

Nevon opened this issue Jun 29, 2023 · 4 comments · Fixed by #26181
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@Nevon
Copy link

Nevon commented Jun 29, 2023

Describe the bug

When using esbuild to bundle aws-cdk-lib, tags are no longer added to child nodes of a stack when using Tags.of(stack).add(...) since version 2.81.0 of aws-cdk-lib.

Expected Behavior

Tags.of(stack).add('TestTag', 'Value');

should apply the TestTag tag to all taggable child constructs of the stack, whether the code is being bundled or just transpiled.

Current Behavior

No tags are applied to any child constructs.

Reproduction Steps

See https://github.com/Nevon/aws-cdk-repro-26169 for a way to reproduce the issue. The repo creates an app and a stack, adds a few resources and then adds a tag to the stack, after which the template is synthesized. When running with ts-node the template has tags. When running after transpiling and bundling using esbuild, the template does not have any tags.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.80.1

Framework Version

No response

Node.js Version

v18.15.0

OS

Linux / Mac

Language

Typescript

Language Version

5.1.3

Other information

No response

@Nevon Nevon added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 29, 2023
@github-actions github-actions bot added the aws-cdk-lib Related to the aws-cdk-lib package label Jun 29, 2023
@Nevon Nevon changed the title aws-cdk-lib: Missing tags when synthesizing from within lambda aws-cdk-lib: Missing tags when synthesizing after bundling code with esbuild Jun 29, 2023
@Nevon
Copy link
Author

Nevon commented Jun 29, 2023

I think I figured out the issue, and I'm not sure if it should be considered a CDK bug or not. Bundling the code using the esbuild option --keep-names fixes the behavior. --keep-names makes it so that the bundler won't rename symbols in order to try to make the code smaller.

I believe this is the offending function, which was introduced in v2.81.0:

public static isTaggable(construct: any): construct is ITaggable {
const tags = (construct as any).tags;
return tags && typeof tags === 'object' && tags.constructor.name === 'TagManager';
}

It's comparing the constructor name to a static string to determine if the construct is taggable. I would assume this won't work if the bundler has renamed the class. In my case it's renamed to _TagManager. An alternative approach might be to add a static property to the class to check against, instead of the constructor name, or possibly to compare to TagManager.name instead of a static string, but I'll leave it up to the CDK maintainers to determine if this should be considered a bug or not.

@pahud
Copy link
Contributor

pahud commented Jun 29, 2023

Thank you for your detailed report. We will discuss with the team.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 29, 2023
rix0rrr added a commit that referenced this issue Jun 30, 2023
Caused by a check for `constructor.name` which `esbuild` may rename.
Replace with a checkable symbol.

Closes #26169.
@mergify mergify bot closed this as completed in #26181 Jul 3, 2023
mergify bot pushed a commit that referenced this issue Jul 3, 2023
Caused by a check for `constructor.name` which `esbuild` may rename. Replace with a checkable symbol.

Closes #26169.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Jul 3, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@Ranjith072
Copy link

Hi,
i am migrating from cdk 2.70.0 to 2.88.0 python version and the issue i have is the static method isTaggable has stopped working, with the error message as shown below. if i use isTaggableV2 it works but removes all the tags i had before.
Screenshot 2023-07-25 at 16 30 01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws-cdk-lib Related to the aws-cdk-lib package bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants