Skip to content

Commit f53ab2a

Browse files
authored
add operation to TrackedRequest (#796)
* add operation to TrackedRequest * add sqlalachemy tracked_request operation set and tests * add additional tests for new tracked_request property * bump minor version * stop setting tracked_request operation for sqlalchemy * Update changelog * bump macos runner version
1 parent 9c1ecfe commit f53ab2a

13 files changed

Lines changed: 45 additions & 13 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353

5454
build_macos_wheels:
5555
name: Build macos wheels (cross-compiles arm64)
56-
runs-on: macos-11
56+
runs-on: macos-13
5757
steps:
5858
- uses: actions/checkout@v3
5959

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Pending
44

5+
## [3.2.0] 2024-09-12
6+
### Added
7+
- "Operation" attribute added to TrackedRequest class to better support development of [scout_apm_python_logging](https://github.com/scoutapp/scout_apm_python_logging)
8+
59
## [3.1.0] 2023-12-18
610
### Added
711
- Updates Core Agent to v1.5.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
setup(
3535
name="scout_apm",
36-
version="3.1.0",
36+
version="3.2.0",
3737
description="Scout Application Performance Monitoring Agent",
3838
long_description=long_description,
3939
long_description_content_type="text/markdown",

src/scout_apm/async_/starlette.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def grab_extra_data():
4040
endpoint.__module__,
4141
endpoint.__qualname__,
4242
)
43+
tracked_request.operation = controller_span.operation
4344
else:
4445
# Mark the request as not real
4546
tracked_request.is_real_request = False
@@ -90,11 +91,11 @@ async def wrapped_background_call(wrapped, instance, args, kwargs):
9091
tracked_request = TrackedRequest.instance()
9192
tracked_request.is_real_request = True
9293

93-
with tracked_request.span(
94-
operation="Job/{}.{}".format(
95-
instance.func.__module__, instance.func.__qualname__
96-
)
97-
):
94+
operation = "Job/{}.{}".format(
95+
instance.func.__module__, instance.func.__qualname__
96+
)
97+
tracked_request.operation = operation
98+
with tracked_request.span(operation=operation):
9899
return await wrapped(*args, **kwargs)
99100

100101
BackgroundTask.__call__ = wrapped_background_call(BackgroundTask.__call__)

src/scout_apm/bottle.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ def wrap_callback(wrapped, instance, args, kwargs):
7171
"x-request-start", ""
7272
)
7373
track_request_queue_time(queue_time, tracked_request)
74+
operation = "Controller{}".format(controller_name)
7475

75-
with tracked_request.span(
76-
operation="Controller{}".format(controller_name), should_capture_backtrace=False
77-
):
76+
with tracked_request.span(operation=operation):
77+
tracked_request.operation = operation
7878
try:
7979
value = wrapped(*args, **kwargs)
8080
except Exception:

src/scout_apm/core/tracked_request.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TrackedRequest(object):
3535
"n_plus_one_tracker",
3636
"hit_max",
3737
"sent",
38+
"operation",
3839
)
3940

4041
# Stop adding new spans at this point, to avoid exhausting memory
@@ -58,6 +59,7 @@ def __init__(self):
5859
self.n_plus_one_tracker = NPlusOneTracker()
5960
self.hit_max = False
6061
self.sent = False
62+
self.operation = None
6163
logger.debug("Starting request: %s", self.request_id)
6264

6365
def __repr__(self):

src/scout_apm/django/middleware.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):
122122
span = tracked_request.current_span()
123123
if span is not None:
124124
span.operation = get_controller_name(request)
125+
tracked_request.operation = span.operation
125126

126127
def process_exception(self, request, exception):
127128
"""

src/scout_apm/falcon.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def process_resource(self, req, resp, resource, params):
106106
span = tracked_request.start_span(
107107
operation=operation, should_capture_backtrace=False
108108
)
109+
tracked_request.operation = operation
109110
req.context.scout_resource_span = span
110111

111112
def _name_operation(self, req, responder, resource):

src/scout_apm/flask/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def wrapped_full_dispatch_request(self, wrapped, instance, args, kwargs):
4747

4848
tracked_request = TrackedRequest.instance()
4949
tracked_request.is_real_request = True
50+
tracked_request.operation = operation
5051
request._scout_tracked_request = tracked_request
5152

5253
werkzeug_track_request_data(request, tracked_request)

tests/integration/test_bottle.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def app_with_scout(config=None, catchall=False):
3232
# Disable running the agent.
3333
config["scout.core_agent_launch"] = False
3434

35-
app = Bottle(catchall=catchall)
35+
app = Bottle()
36+
app.config["catchall"] = catchall
3637

3738
@app.route("/")
3839
def home():
@@ -169,6 +170,7 @@ def test_hello(tracked_requests):
169170
assert len(tracked_request.complete_spans) == 1
170171
span = tracked_request.complete_spans[0]
171172
assert span.operation == "Controller/hello/"
173+
assert tracked_request.operation == "Controller/hello/"
172174

173175

174176
def test_not_found(tracked_requests):
@@ -190,6 +192,7 @@ def test_server_error(tracked_requests):
190192
assert len(tracked_request.complete_spans) == 1
191193
span = tracked_requests[0].complete_spans[0]
192194
assert span.operation == "Controller/crash/"
195+
assert tracked_request.operation == "Controller/crash/"
193196

194197

195198
def test_return_error(tracked_requests):
@@ -203,6 +206,7 @@ def test_return_error(tracked_requests):
203206
assert len(tracked_request.complete_spans) == 1
204207
span = tracked_requests[0].complete_spans[0]
205208
assert span.operation == "Controller/return-error/"
209+
assert tracked_request.operation == "Controller/return-error/"
206210

207211

208212
def test_named(tracked_requests):

0 commit comments

Comments
 (0)