Skip to content

chore(maintenance): add powertools to user-agent in SDK clients #1567

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

Merged
merged 17 commits into from
Jul 3, 2023
Merged

chore(maintenance): add powertools to user-agent in SDK clients #1567

merged 17 commits into from
Jul 3, 2023

Conversation

am29d
Copy link
Contributor

@am29d am29d commented Jun 29, 2023

Description of your changes

In this PR we introduce our custom middleware that can be added to any middleware stack of AWS SDK v3 clients. We decided to use middleware instead of customUserAgent options, because we might get SDK client from the user. Because config field of the client is readonly, we can't add change it, after the client has been initialised.

Any feature using an SDK client can call like this:

const ddbClient = new DynamoDBClient(options);

addUserAgentMiddleware(ddbClient, 'my-feature);

this will modify the user-agent field by appending PT/my-feature/1.10.0 PTEnv/NA at the end of the value.

I was about to add the new functionality to idempotency, but we will do it in a separate PR. Meanwhile, I have removed the singleton for the client in the DynamoDBPersistenceLayer.ts, similar how we use it parameters utility.

Related issues, RFCs

Issue number: closes #1533

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@am29d am29d requested a review from a team June 29, 2023 12:36
@boring-cyborg boring-cyborg bot added commons This item relates to the Commons Utility idempotency This item relates to the Idempotency Utility dependencies Changes that touch dependencies, e.g. Dependabot, etc. tests PRs that add or change tests labels Jun 29, 2023
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Jun 29, 2023
@am29d am29d requested a review from dreamorosi June 29, 2023 12:37
@pull-request-size pull-request-size bot added size/M PR between 30-99 LOC and removed size/L PRs between 100-499 LOC labels Jun 29, 2023
@pull-request-size pull-request-size bot added size/L PRs between 100-499 LOC and removed size/M PR between 30-99 LOC labels Jun 29, 2023
@am29d
Copy link
Contributor Author

am29d commented Jul 3, 2023

  • Fixed tests
  • added try/catch so we don't block user code if adding user agent fails
  • added parametrised tests for each client we use in our utilities

@am29d am29d requested a review from dreamorosi July 3, 2023 12:16
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

I have run the integration tests on this branch and they are passing.

},
};

describe('Given a client of instance: ', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean, I like it

@dreamorosi dreamorosi linked an issue Jul 3, 2023 that may be closed by this pull request
2 tasks
@dreamorosi dreamorosi merged commit f934757 into aws-powertools:main Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commons This item relates to the Commons Utility dependencies Changes that touch dependencies, e.g. Dependabot, etc. idempotency This item relates to the Idempotency Utility size/L PRs between 100-499 LOC tests PRs that add or change tests
Projects
None yet
2 participants