Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions newrelic/api/web_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,27 @@ def _parse_time_stamp(time_stamp):
TRUE_VALUES = {"on", "true", "1"}
FALSE_VALUES = {"off", "false", "0"}

DEPRECATED_ENVIRON_SETTINGS = (
"newrelic.set_background_task",
"newrelic.suppress_apdex_metric",
"newrelic.suppress_transaction_trace",
"newrelic.capture_request_params",
"newrelic.disable_browser_autorum",
)


def _lookup_environ_setting(environ, name, default=False):
if name not in environ:
return default

# Check for deprecated WSGI environ dictionary setting
if name in DEPRECATED_ENVIRON_SETTINGS:
warnings.warn(
f"Environ setting '{name}' is deprecated and will be removed in a future release.",
DeprecationWarning,
stacklevel=2,
)

flag = environ[name]

if isinstance(flag, str):
Expand Down
18 changes: 16 additions & 2 deletions tests/external_httplib/test_urllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys

import pytest

try:
import urllib.request as urllib
except:
except ImportError:
import urllib

from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers
Expand All @@ -29,6 +29,14 @@

from newrelic.api.background_task import background_task

# Since Python 3.3, `urllib.URLopener()` has been deprecated in favor of
# `urllib.request.urlopen`. In Python 3.14, `urllib.URLopener()` will be
# removed. `urllib.request.urlopen` corresponds to the old `urllib2.urlopen`

SKIP_IF_PYTHON_3_14_OR_ABOVE = pytest.mark.skipif(
sys.version_info[0:2] >= (3, 14), reason="urllib.URLopener() is removed in Python 3.14 and above"
)


@pytest.fixture(scope="session")
def metrics(server):
Expand All @@ -44,6 +52,7 @@ def metrics(server):
return scoped, rollup


@SKIP_IF_PYTHON_3_14_OR_ABOVE
def test_urlopener_http_request(server, metrics):
@validate_transaction_metrics(
"test_urllib:test_urlopener_http_request",
Expand All @@ -59,6 +68,7 @@ def _test():
_test()


@SKIP_IF_PYTHON_3_14_OR_ABOVE
def test_urlopener_https_request(server, metrics):
@validate_transaction_metrics(
"test_urllib:test_urlopener_https_request",
Expand All @@ -77,6 +87,7 @@ def _test():
_test()


@SKIP_IF_PYTHON_3_14_OR_ABOVE
def test_urlopener_http_request_with_port(server):
scoped = [(f"External/localhost:{server.port}/urllib/", 1)]

Expand Down Expand Up @@ -110,6 +121,7 @@ def _test():
]


@SKIP_IF_PYTHON_3_14_OR_ABOVE
@validate_transaction_metrics(
"test_urllib:test_urlopener_file_request",
scoped_metrics=_test_urlopener_file_request_scoped_metrics,
Expand All @@ -123,6 +135,7 @@ def test_urlopener_file_request():
opener.open(file_uri)


@SKIP_IF_PYTHON_3_14_OR_ABOVE
@background_task()
@cache_outgoing_headers
@validate_cross_process_headers
Expand All @@ -131,6 +144,7 @@ def test_urlopener_cross_process_request(server):
opener.open(f"http://localhost:{server.port}/")


@SKIP_IF_PYTHON_3_14_OR_ABOVE
@cat_enabled
def test_urlopener_cross_process_response(server):
_test_urlopener_cross_process_response_scoped_metrics = [
Expand Down
1 change: 0 additions & 1 deletion tests/external_httplib/test_urllib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import urllib.request as urllib2

import pytest
Expand Down