From 12dc9f6100341a2f94fd11f331c9f8796a1d3370 Mon Sep 17 00:00:00 2001 From: Vishwak Thatikonda Date: Sat, 8 Aug 2026 00:29:43 -0700 Subject: [PATCH] fix(tracer): declare in_subsegment_async as an async context manager BaseProvider.in_subsegment_async was decorated with @contextmanager and annotated to return Generator[BaseSegment, None, None], declaring a synchronous context manager. It is entered with async with by Tracer._decorate_async_function, by the documented escape hatch for concurrent async functions, and by the default X-Ray provider. Remove the decorator and annotate the return type as AbstractAsyncContextManager[BaseSegment] so correct code type checks without a cast. No runtime change, the abstract method body is only a docstring. Closes #8365 --- aws_lambda_powertools/tracing/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws_lambda_powertools/tracing/base.py b/aws_lambda_powertools/tracing/base.py index 8469c075222..a448126eb88 100644 --- a/aws_lambda_powertools/tracing/base.py +++ b/aws_lambda_powertools/tracing/base.py @@ -14,6 +14,7 @@ import numbers import traceback from collections.abc import Generator, Sequence + from contextlib import AbstractAsyncContextManager class BaseSegment(abc.ABC): @@ -99,8 +100,7 @@ def in_subsegment(self, name=None, **kwargs) -> Generator[BaseSegment, None, Non """ @abc.abstractmethod - @contextmanager - def in_subsegment_async(self, name=None, **kwargs) -> Generator[BaseSegment, None, None]: + def in_subsegment_async(self, name=None, **kwargs) -> AbstractAsyncContextManager[BaseSegment]: """Return a subsegment async context manger. Parameters