Skip to content

Commit 96ff4e8

Browse files
authored
Merge e5c2cff into e2d411c
2 parents e2d411c + e5c2cff commit 96ff4e8

File tree

66 files changed

+433
-3625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+433
-3625
lines changed

newrelic/api/cat_header_mixin.py

Lines changed: 0 additions & 129 deletions
This file was deleted.

newrelic/api/external_trace.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
import functools
1616

17-
from newrelic.api.cat_header_mixin import CatHeaderMixin
17+
from newrelic.api.header_mixin import HeaderMixin
1818
from newrelic.api.time_trace import TimeTrace, current_trace
1919
from newrelic.common.async_wrapper import async_wrapper as get_async_wrapper
2020
from newrelic.common.object_wrapper import FunctionWrapper, wrap_object
2121
from newrelic.core.external_node import ExternalNode
2222

2323

24-
class ExternalTrace(CatHeaderMixin, TimeTrace):
24+
class ExternalTrace(HeaderMixin, TimeTrace):
2525
def __init__(self, library, url, method=None, **kwargs):
2626
parent = kwargs.pop("parent", None)
2727
source = kwargs.pop("source", None)
@@ -38,9 +38,8 @@ def __init__(self, library, url, method=None, **kwargs):
3838
def __repr__(self):
3939
return f"<{self.__class__.__name__} object at 0x{id(self):x} { {'library': self.library, 'url': self.url, 'method': self.method} }>"
4040

41-
def process_response(self, status_code, headers):
41+
def process_response(self, status_code, headers=None):
4242
self._add_agent_attribute("http.statusCode", status_code)
43-
self.process_response_headers(headers)
4443

4544
def terminal_node(self):
4645
return True

newrelic/api/header_mixin.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2010 New Relic, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
# HeaderMixin assumes the mixin class also inherits from TimeTrace
17+
class HeaderMixin:
18+
synthetics_key = "X-NewRelic-Synthetics"
19+
synthetics_info_key = "X-NewRelic-Synthetics-Info"
20+
settings = None
21+
22+
def __enter__(self):
23+
result = super().__enter__()
24+
if result is self and self.transaction:
25+
self.settings = self.transaction.settings or None
26+
return result
27+
28+
@classmethod
29+
def generate_request_headers(cls, transaction):
30+
"""
31+
Return a list of NewRelic specific headers as tuples
32+
[(HEADER_NAME0, HEADER_VALUE0), (HEADER_NAME1, HEADER_VALUE1)]
33+
34+
"""
35+
36+
if transaction is None or transaction.settings is None:
37+
return []
38+
39+
settings = transaction.settings
40+
41+
nr_headers = []
42+
43+
if settings.distributed_tracing.enabled:
44+
transaction.insert_distributed_trace_headers(nr_headers)
45+
46+
if transaction.synthetics_header:
47+
nr_headers.append((cls.synthetics_key, transaction.synthetics_header))
48+
if transaction.synthetics_info_header:
49+
nr_headers.append((cls.synthetics_info_key, transaction.synthetics_info_header))
50+
51+
return nr_headers

newrelic/api/message_trace.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@
1414

1515
import functools
1616

17-
from newrelic.api.cat_header_mixin import CatHeaderMixin
17+
from newrelic.api.header_mixin import HeaderMixin
1818
from newrelic.api.time_trace import TimeTrace, current_trace
1919
from newrelic.common.async_wrapper import async_wrapper as get_async_wrapper
2020
from newrelic.common.object_wrapper import FunctionWrapper, wrap_object
2121
from newrelic.core.message_node import MessageNode
2222

2323

24-
class MessageTrace(CatHeaderMixin, TimeTrace):
25-
cat_id_key = "NewRelicID"
26-
cat_transaction_key = "NewRelicTransaction"
27-
cat_appdata_key = "NewRelicAppData"
28-
cat_synthetics_key = "NewRelicSynthetics"
29-
cat_synthetics_info_key = "NewRelicSyntheticsInfo"
24+
class MessageTrace(HeaderMixin, TimeTrace):
25+
synthetics_key = "NewRelicSynthetics"
26+
synthetics_info_key = "NewRelicSyntheticsInfo"
3027

3128
def __init__(self, library, operation, destination_type, destination_name, params=None, terminal=True, **kwargs):
3229
parent = kwargs.pop("parent", None)

newrelic/api/message_transaction.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from newrelic.api.application import Application, application_instance
1818
from newrelic.api.background_task import BackgroundTask
19-
from newrelic.api.message_trace import MessageTrace
2019
from newrelic.api.transaction import current_transaction
2120
from newrelic.common.async_proxy import TransactionContext, async_proxy
2221
from newrelic.common.object_wrapper import FunctionWrapper, wrap_object
@@ -47,10 +46,6 @@ def __init__(
4746
if headers is not None and self.settings is not None:
4847
if self.settings.distributed_tracing.enabled:
4948
self.accept_distributed_trace_headers(headers, transport_type=transport_type)
50-
elif self.settings.cross_application_tracer.enabled:
51-
self._process_incoming_cat_headers(
52-
headers.pop(MessageTrace.cat_id_key, None), headers.pop(MessageTrace.cat_transaction_key, None)
53-
)
5449

5550
self.routing_key = routing_key
5651
self.exchange_type = exchange_type

0 commit comments

Comments
 (0)