Repository: garyd203/xraysink (language: python)

Issue:
Upgrade to support latest aws-xray-sdk
* [x] Update standard version we test against to v2.12
* [x] See if there's anything new that means we can modify or deprecate our functionality
* [x] Check if https://github.com/aws/aws-xray-sdk-python/pull/340 solves the underlying problem, and create an issue for us to lean into that if it does. else mebbe push our better fix upstream if easy
* [ ] ~Write test to verify behaviour of core library in scenario where a xray trace does not exist~ -> See #105


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48d7ea2..9cc25c5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,10 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 
+## v1.7.0 (unreleased)
+
+Changed:
+* Test against `aws_xray_sdk` release up to v2.12.0
+* Test functionality in `AsyncContext` in `aws_xray_sdk`, including fix in v2.10.0
+
+
 ## v1.6.1 (2023-03-06)
 
 Changed:
-* Test support for python v3.11 and upgradesome dependencies. No code changes.
+* Test support for python v3.11 and upgrade some dependencies. No code changes.
 
 
 ## v1.6.0 (2022-05-18)


Test patch:
diff --git a/tests/test_asyncio_tasks.py b/tests/test_asyncio_tasks.py
index 014643d..6168177 100644
--- a/tests/test_asyncio_tasks.py
+++ b/tests/test_asyncio_tasks.py
@@ -3,17 +3,33 @@
 from asyncio import sleep
 
 import pytest
+from aws_xray_sdk.core.async_context import AsyncContext as CoreAsyncContext
+from aws_xray_sdk.version import VERSION as AWS_XRAY_SDK_VERSION_STRING
 
 from xraysink.context import AsyncContext
 
 pytestmark = pytest.mark.asyncio
 
+AWS_XRAY_SDK_VERSION = list(map(int, AWS_XRAY_SDK_VERSION_STRING.split(".")))
 
+BROKEN_SDK_VERSION = pytest.mark.xfail(
+    AWS_XRAY_SDK_VERSION[0] == 2 and AWS_XRAY_SDK_VERSION[1] < 10,
+    reason="aws_xray_sdk async context propagation prior to v2.10.0 was broken",
+)
+
+
+@pytest.mark.parametrize(
+    "context_class",
+    [
+        pytest.param(AsyncContext, id="xraysink"),
+        pytest.param(CoreAsyncContext, marks=[BROKEN_SDK_VERSION], id="aws_xray_sdk"),
+    ],
+)
 async def test_asyncio_task_subsegments_should_use_parent_task_segment_as_parent(
-    recorder,
+    recorder, context_class
 ):
     # Setup
-    recorder.configure(context=AsyncContext(use_task_factory=True))
+    recorder.configure(context=context_class(use_task_factory=True))
 
     async def do_task(name: str, sleep_time: float):
         # Emulate a remote call by starting a subsegment and blocking
@@ -65,9 +81,18 @@ async def broken_task(name: str):
     assert getattr(subsegments["errored-task"], "fault", False)
 
 
-async def test_asyncio_task_should_start_segment_when_none_present(recorder):
+@pytest.mark.parametrize(
+    "context_class",
+    [
+        pytest.param(AsyncContext, id="xraysink"),
+        pytest.param(CoreAsyncContext, marks=[BROKEN_SDK_VERSION], id="aws_xray_sdk"),
+    ],
+)
+async def test_asyncio_task_should_start_segment_when_none_present(
+    recorder, context_class
+):
     # Setup
-    recorder.configure(context=AsyncContext(use_task_factory=True))
+    recorder.configure(context=context_class(use_task_factory=True))
 
     async def do_task(a, b):
         async with recorder.in_segment_async():
@@ -86,9 +111,18 @@ async def do_task(a, b):
     assert getattr(segment, "fault", False) is False
 
 
-async def test_asyncio_task_should_start_segment_when_previous_segment_closed(recorder):
+@pytest.mark.parametrize(
+    "context_class",
+    [
+        pytest.param(AsyncContext, id="xraysink"),
+        pytest.param(CoreAsyncContext, marks=[BROKEN_SDK_VERSION], id="aws_xray_sdk"),
+    ],
+)
+async def test_asyncio_task_should_start_segment_when_previous_segment_closed(
+    recorder, context_class
+):
     # Setup
-    recorder.configure(context=AsyncContext(use_task_factory=True))
+    recorder.configure(context=context_class(use_task_factory=True))
 
     async def do_task(a, b):
         async with recorder.in_segment_async():