Skip to content

Commit 0d29aa4

Browse files
committed
Add back processing of response status & headers
1 parent e5c2cff commit 0d29aa4

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

newrelic/api/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def __init__(self, application, enabled=None, source=None):
265265
# 32-digit random hex. Padded with zeros in the front.
266266
self._trace_id = trace_id
267267

268-
# This may be overridden by processing an inbound CAT header
268+
# This may be overridden by processing an inbound DT header
269269
self.parent_type = None
270270
self.parent_span = None
271271
self.trusted_parent_span = None

newrelic/api/web_transaction.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,8 @@ def _process_context_headers(self):
302302
self.accept_distributed_trace_headers(self._request_headers)
303303

304304
def process_response(self, status_code, response_headers):
305-
"""Processes response status and headers, extracting any
306-
details required and returning a set of additional headers
307-
to merge into that being returned for the web transaction.
308-
305+
"""
306+
Processes response status and headers; extracting any details required.
309307
"""
310308

311309
if not self.enabled:
@@ -325,16 +323,9 @@ def process_response(self, status_code, response_headers):
325323

326324
try:
327325
self._response_code = int(status_code)
328-
329-
# If response code is 304 do not insert CAT headers. See:
330-
# https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
331-
if self._response_code == 304:
332-
return
333326
except Exception:
334327
pass
335328

336-
return
337-
338329
def _update_agent_attributes(self):
339330
if "accept" in self._request_headers:
340331
self._add_agent_attribute("request.headers.accept", self._request_headers["accept"])

newrelic/hooks/external_httpx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def sync_send_wrapper(wrapped, instance, args, kwargs):
7777
request._nr_trace = tracer
7878
outgoing_headers = tracer.generate_request_headers(tracer.transaction)
7979
for header_name, header_value in outgoing_headers:
80-
# User headers should override our CAT headers
80+
# User headers should override our DT headers
8181
if header_name not in request.headers:
8282
request.headers[header_name] = header_value
8383

@@ -92,7 +92,7 @@ async def async_send_wrapper(wrapped, instance, args, kwargs):
9292
request._nr_trace = tracer
9393
outgoing_headers = tracer.generate_request_headers(tracer.transaction)
9494
for header_name, header_value in outgoing_headers:
95-
# User headers should override our CAT headers
95+
# User headers should override our DT headers
9696
if header_name not in request.headers:
9797
request.headers[header_name] = header_value
9898

newrelic/hooks/framework_aiohttp.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ def _is_expected(exc, value, tb):
5959
return _is_expected
6060

6161

62-
def _nr_process_response(response, transaction):
63-
transaction.process_response(response.status, response.headers)
64-
65-
6662
@function_wrapper
6763
def _nr_aiohttp_view_wrapper_(wrapped, instance, args, kwargs):
6864
transaction = current_transaction()
@@ -240,8 +236,23 @@ def _nr_aiohttp_request_wrapper_(wrapped, instance, args, kwargs):
240236

241237
method, url = _bind_request(*args, **kwargs)
242238
trace = ExternalTrace("aiohttp", str(url), method)
243-
with trace:
244-
return wrapped(*args, **kwargs)
239+
240+
async def _coro():
241+
try:
242+
response = await wrapped(*args, **kwargs)
243+
244+
try:
245+
trace.process_response(status_code=response.status)
246+
except:
247+
pass
248+
249+
return response
250+
except Exception:
251+
notice_error()
252+
253+
raise
254+
255+
return async_wrapper(wrapped)(_coro, trace)()
245256

246257

247258
def instrument_aiohttp_client(module):
@@ -303,13 +314,13 @@ async def _coro(*_args, **_kwargs):
303314
try:
304315
response = await coro
305316
except _web.HTTPException as e:
306-
_nr_process_response(e, transaction)
317+
transaction.process_response(e.status, e.headers)
307318
raise
308319
except Exception:
309320
transaction.process_response(500, ())
310321
raise
311322

312-
_nr_process_response(response, transaction)
323+
transaction.process_response(response.status, response.headers)
313324
return response
314325

315326
_coro = web_transaction(

0 commit comments

Comments
 (0)