Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 12150e2

Browse files
committedMay 19, 2023
change back to use register in initializer
1 parent 60d188e commit 12150e2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
 

‎aws_lambda_powertools/shared/user_agent.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
EXEC_ENV: str = os.environ.get("AWS_EXECUTION_ENV", "NA")
1818
TARGET_SDK_EVENT: str = "request-created"
1919
FEATURE_PREFIX: str = "PT"
20-
HEADER_NO_OP: str = f"{FEATURE_PREFIX}/no-op/{powertools_version} PTEnv/{EXEC_ENV}"
20+
DEFAULT_FEATURE: str = "no-op"
21+
HEADER_NO_OP: str = f"{FEATURE_PREFIX}/{DEFAULT_FEATURE}/{powertools_version} PTEnv/{EXEC_ENV}"
2122

2223

2324
def _initializer_botocore_session(session):
2425
try:
25-
session.user_agent_extra = HEADER_NO_OP
26+
session.register(TARGET_SDK_EVENT, _create_feature_function(DEFAULT_FEATURE))
2627
except Exception:
2728
logger.debug("Can't add extra header User-Agent")
2829

@@ -37,7 +38,7 @@ def add_powertools_feature(request, **kwargs):
3738

3839
# This function is exclusive to client and resources objects created in Powertools
3940
# and must remove the no-op header, if present
40-
if HEADER_NO_OP in headers["User-Agent"]:
41+
if HEADER_NO_OP in headers["User-Agent"] and feature != DEFAULT_FEATURE:
4142
# Remove HEADER_NO_OP + space
4243
header_user_agent = header_user_agent.replace(f"{HEADER_NO_OP} ", "")
4344

0 commit comments

Comments
 (0)
Please sign in to comment.