From 5b9b2c1a92fad1883ab7e2f41925cc857f9b4ac0 Mon Sep 17 00:00:00 2001 From: Quinn Milionis Date: Fri, 21 Mar 2025 15:06:18 -0700 Subject: [PATCH] derive operation from active spans --- pyproject.toml | 2 +- scout_apm_logging/utils/operation_utils.py | 2 +- tests/unit/test_handler.py | 4 ++-- tests/unit/test_operation_utils.py | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 564b2f4..4569385 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "scout-apm-logging" -version = "1.0.1" +version = "1.0.2" description = "Scout APM Python Logging Agent" authors = ["Scout "] maintainers = ["Quinn Milionis "] diff --git a/scout_apm_logging/utils/operation_utils.py b/scout_apm_logging/utils/operation_utils.py index 5379bb0..f7e3e4f 100644 --- a/scout_apm_logging/utils/operation_utils.py +++ b/scout_apm_logging/utils/operation_utils.py @@ -39,7 +39,7 @@ def extract_operation(operation: str) -> Optional[OperationDetail]: return extract_operation(operation) # Fall back to checking spans - spans = getattr(record, "complete_spans", None) or [] + spans = getattr(record, "active_spans", None) or [] for span in reversed(spans): result = extract_operation(span.operation) if result: diff --git a/tests/unit/test_handler.py b/tests/unit/test_handler.py index 5dbd715..c745453 100644 --- a/tests/unit/test_handler.py +++ b/tests/unit/test_handler.py @@ -40,7 +40,7 @@ def test_emit_with_scout_request(mock_tracked_request, otel_scout_handler): mock_request.end_time.isoformat.return_value = "2024-03-06T12:00:01" mock_request.tags = {"key": "value"} mock_request.operation = None - mock_request.complete_spans = [ + mock_request.active_spans = [ Span(mock_request.id, "Middleware"), Span(mock_request.id, "Controller/foobar"), ] @@ -75,7 +75,7 @@ def test_emit_when_scout_request_contains_operation( mock_request.start_time.isoformat.return_value = "2024-03-06T12:00:00" mock_request.end_time.isoformat.return_value = "2024-03-06T12:00:01" mock_request.tags = {"key": "value"} - mock_request.complete_spans = [ + mock_request.active_spans = [ Span(mock_request.id, "Middleware"), ] mock_request.operation = MagicMock().return_value = "Controller/foobar" diff --git a/tests/unit/test_operation_utils.py b/tests/unit/test_operation_utils.py index 358c70c..067ca6f 100644 --- a/tests/unit/test_operation_utils.py +++ b/tests/unit/test_operation_utils.py @@ -15,7 +15,7 @@ class MockSpan: @dataclass class MockTrackedRequest: operation: Optional[str] = None - complete_spans: Optional[List[MockSpan]] = None + active_spans: Optional[List[MockSpan]] = None def test_operation_detail_entrypoint_attribute(): @@ -37,7 +37,7 @@ def test_get_operation_detail_from_spans(): MockSpan(operation="Job/TestJob"), MockSpan(operation="Controller/TestController"), ] - record = MockTrackedRequest(complete_spans=spans) + record = MockTrackedRequest(active_spans=spans) result = get_operation_detail(record) assert result == OperationDetail( name="TestController", type=OperationType.CONTROLLER @@ -63,7 +63,7 @@ def test_get_operation_detail_no_operation_or_spans(): def test_get_operation_detail_empty_spans(): - record = MockTrackedRequest(complete_spans=[]) + record = MockTrackedRequest(active_spans=[]) result = get_operation_detail(record) assert result is None @@ -73,7 +73,7 @@ def test_get_operation_detail_spans_no_match(): MockSpan(operation="Other/Operation1"), MockSpan(operation="Other/Operation2"), ] - record = MockTrackedRequest(complete_spans=spans) + record = MockTrackedRequest(active_spans=spans) result = get_operation_detail(record) assert result is None @@ -81,7 +81,7 @@ def test_get_operation_detail_spans_no_match(): def test_get_operation_detail_operation_priority(): spans = [MockSpan(operation="Job/TestJob")] record = MockTrackedRequest( - operation="Controller/TestController", complete_spans=spans + operation="Controller/TestController", active_spans=spans ) result = get_operation_detail(record) assert result == OperationDetail(