Skip to content

Commit ef7c509

Browse files
committed
fix to pass test
1 parent 0cb8463 commit ef7c509

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

aws_lambda_powertools/tracing/provider/xray_tracer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from contextlib import contextmanager
3+
from contextlib import asynccontextmanager, contextmanager
44
from numbers import Number
55
from typing import Generator, Sequence
66

@@ -49,7 +49,7 @@ def trace(self, name: str) -> Generator[XraySpan, None, None]:
4949
with self.in_subsegment(name=name) as sub_segment:
5050
yield XraySpan(subsegment=sub_segment)
5151

52-
@contextmanager
52+
@asynccontextmanager
5353
async def trace_async(self, name: str) -> Generator[XraySpan, None, None]:
5454
async with self.in_subsegment_async(name=name) as sub_segment:
5555
yield XraySpan(subsegment=sub_segment)
@@ -61,6 +61,7 @@ def set_attribute(self, key: str, value: str | Number | bool, **kwargs) -> None:
6161
self.put_annotation(key=key, value=value)
6262

6363
def patch(self, modules: Sequence[str]) -> None:
64+
# defined in init
6465
pass
6566

6667
def patch_all(self) -> None:

aws_lambda_powertools/tracing/tracer.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ..shared.lazy_import import LazyLoader
1313
from ..shared.types import AnyCallableT
1414
from .base import BaseProvider, BaseSegment
15+
from .provider import xray_tracer
1516

1617
is_cold_start = True
1718
logger = logging.getLogger(__name__)
@@ -808,11 +809,8 @@ def _patch_xray_provider(self):
808809
# Due to Lazy Import, we need to activate `core` attrib via import
809810
# we also need to include `patch`, `patch_all` methods
810811
# to ensure patch calls are done via the provider
811-
from aws_xray_sdk.core import xray_recorder # type: ignore
812812

813-
provider = xray_recorder
814-
provider.patch = aws_xray_sdk.core.patch
815-
provider.patch_all = aws_xray_sdk.core.patch_all
813+
provider = xray_tracer.XrayProvider()
816814

817815
return provider
818816

@@ -827,7 +825,7 @@ def _disable_xray_trace_batching(self):
827825
aws_xray_sdk.core.xray_recorder.configure(streaming_threshold=0)
828826

829827
def _is_xray_provider(self):
830-
return "aws_xray_sdk" in self.provider.__module__
828+
return isinstance(self.provider, xray_tracer.XrayProvider)
831829

832830
def ignore_endpoint(self, hostname: Optional[str] = None, urls: Optional[List[str]] = None):
833831
"""If you want to ignore certain httplib requests you can do so based on the hostname or URL that is being

tests/unit/test_tracing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ def __init__(
3333
self.put_metadata_mock = put_metadata_mock or mocker.MagicMock()
3434
self.put_annotation_mock = put_annotation_mock or mocker.MagicMock()
3535
self.in_subsegment = in_subsegment or mocker.MagicMock()
36+
self.trace = self.in_subsegment
3637
self.patch_mock = patch_mock or mocker.MagicMock()
3738
self.disable_tracing_provider_mock = disable_tracing_provider_mock or mocker.MagicMock()
3839
self.in_subsegment_async = in_subsegment_async or mocker.MagicMock(spec=True)
40+
self.trace_async = self.in_subsegment_async
3941

4042
def put_metadata(self, *args, **kwargs):
4143
return self.put_metadata_mock(*args, **kwargs)

0 commit comments

Comments
 (0)