Skip to content

Commit

Permalink
Merge branch 'main' into add-oltp-protocol-class
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jun 2, 2023
2 parents da5ae7d + c2d4629 commit 5143afc
Show file tree
Hide file tree
Showing 17 changed files with 515 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-python-matrix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ runs:
shell: bash
run: |
python3.10 -m pip install -U pip
python3.10 -m pip install -U wheel setuptools 'tox<4' 'virtualenv<20.22.0'
python3.10 -m pip install -U wheel setuptools tox 'virtualenv<20.22.0'
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ jobs:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-python-matrix

- name: Install odbc driver for postgresql
run: |
sudo apt-get update
sudo sudo apt-get install odbc-postgresql
sudo sed -i 's/Driver=psqlodbca.so/Driver=\/usr\/lib\/x86_64-linux-gnu\/odbc\/psqlodbca.so/g' /etc/odbcinst.ini
sudo sed -i 's/Driver=psqlodbcw.so/Driver=\/usr\/lib\/x86_64-linux-gnu\/odbc\/psqlodbcw.so/g' /etc/odbcinst.ini
sudo sed -i 's/Setup=libodbcpsqlS.so/Setup=\/usr\/lib\/x86_64-linux-gnu\/odbc\/libodbcpsqlS.so/g' /etc/odbcinst.ini
- name: Get Environments
id: get-envs
run: |
Expand Down
21 changes: 21 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ignore:
- "newrelic/packages/**/*"
- "newrelic/packages/*"
- "newrelic/hooks/adapter_meinheld.py"
- "newrelic/hooks/adapter_flup.py"
- "newrelic/hooks/component_piston.py"
- "newrelic/hooks/datastore_pyelasticsearch.py"
- "newrelic/hooks/external_pywapi.py"
- "newrelic/hooks/external_dropbox.py"
- "newrelic/hooks/external_facepy.py"
- "newrelic/hooks/external_xmlrpclib.py"
- "newrelic/hooks/framework_pylons.py"
- "newrelic/hooks/framework_web2py.py"
- "newrelic/hooks/middleware_weberror.py"
- "newrelic/hooks/framework_webpy.py"
- "newrelic/hooks/database_oursql.py"
- "newrelic/hooks/database_psycopg2ct.py"
- "newrelic/hooks/datastore_umemcache.py"
# Temporarily disable kafka
- "newrelic/hooks/messagebroker_kafkapython.py"
- "newrelic/hooks/messagebroker_confluentkafka.py"
17 changes: 8 additions & 9 deletions newrelic/hooks/adapter_waitress.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import newrelic.api.wsgi_application
import newrelic.api.in_function
from newrelic.api.in_function import wrap_in_function
from newrelic.api.wsgi_application import WSGIApplicationWrapper
from newrelic.common.package_version_utils import get_package_version

def instrument_waitress_server(module):

def wrap_wsgi_application_entry_point(server, application,
*args, **kwargs):
application = newrelic.api.wsgi_application.WSGIApplicationWrapper(
application)
def instrument_waitress_server(module):
def wrap_wsgi_application_entry_point(server, application, *args, **kwargs):
dispatcher_details = ("Waitress", get_package_version("waitress"))
application = WSGIApplicationWrapper(application, dispatcher=dispatcher_details)
args = [server, application] + list(args)
return (args, kwargs)

newrelic.api.in_function.wrap_in_function(module,
'WSGIServer.__init__', wrap_wsgi_application_entry_point)
wrap_in_function(module, "WSGIServer.__init__", wrap_wsgi_application_entry_point)
54 changes: 54 additions & 0 deletions tests/adapter_waitress/_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from threading import Thread
from time import sleep

from testing_support.sample_applications import (
raise_exception_application,
raise_exception_finalize,
raise_exception_response,
simple_app_raw,
)
from testing_support.util import get_open_port


def sample_application(environ, start_response):
path_info = environ.get("PATH_INFO")

if path_info.startswith("/raise-exception-application"):
return raise_exception_application(environ, start_response)
elif path_info.startswith("/raise-exception-response"):
return raise_exception_response(environ, start_response)
elif path_info.startswith("/raise-exception-finalize"):
return raise_exception_finalize(environ, start_response)

return simple_app_raw(environ, start_response)


def setup_application():
port = get_open_port()

def run_wsgi():
from waitress import serve

serve(sample_application, host="127.0.0.1", port=port)

wsgi_thread = Thread(target=run_wsgi)
wsgi_thread.daemon = True
wsgi_thread.start()

sleep(1)

return port
40 changes: 40 additions & 0 deletions tests/adapter_waitress/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
import webtest
from testing_support.fixtures import ( # noqa: F401; pylint: disable=W0611
collector_agent_registration_fixture,
collector_available_fixture,
)

_default_settings = {
"transaction_tracer.explain_threshold": 0.0,
"transaction_tracer.transaction_threshold": 0.0,
"transaction_tracer.stack_trace_threshold": 0.0,
"debug.log_data_collector_payloads": True,
"debug.record_transaction_failure": True,
}

collector_agent_registration = collector_agent_registration_fixture(
app_name="Python Agent Test (Waitress)", default_settings=_default_settings
)


@pytest.fixture(autouse=True, scope="session")
def target_application():
import _application

port = _application.setup_application()
return webtest.TestApp("http://localhost:%d" % port)
101 changes: 101 additions & 0 deletions tests/adapter_waitress/test_wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from testing_support.fixtures import (
override_application_settings,
raise_background_exceptions,
wait_for_background_threads,
)
from testing_support.validators.validate_transaction_errors import (
validate_transaction_errors,
)
from testing_support.validators.validate_transaction_metrics import (
validate_transaction_metrics,
)

from newrelic.common.package_version_utils import get_package_version

WAITRESS_VERSION = get_package_version("waitress")


@override_application_settings({"transaction_name.naming_scheme": "framework"})
def test_wsgi_application_index(target_application):
@validate_transaction_metrics(
"_application:sample_application",
custom_metrics=[
("Python/Dispatcher/Waitress/%s" % WAITRESS_VERSION, 1),
],
)
@raise_background_exceptions()
@wait_for_background_threads()
def _test():
response = target_application.get("/")
assert response.status == "200 OK"

_test()


@override_application_settings({"transaction_name.naming_scheme": "framework"})
def test_raise_exception_application(target_application):
@validate_transaction_errors(["builtins:RuntimeError"])
@validate_transaction_metrics(
"_application:sample_application",
custom_metrics=[
("Python/Dispatcher/Waitress/%s" % WAITRESS_VERSION, 1),
],
)
@raise_background_exceptions()
@wait_for_background_threads()
def _test():
response = target_application.get("/raise-exception-application/", status=500)
assert response.status == "500 Internal Server Error"

_test()


@override_application_settings({"transaction_name.naming_scheme": "framework"})
def test_raise_exception_response(target_application):
@validate_transaction_errors(["builtins:RuntimeError"])
@validate_transaction_metrics(
"_application:sample_application",
custom_metrics=[
("Python/Dispatcher/Waitress/%s" % WAITRESS_VERSION, 1),
],
)
@raise_background_exceptions()
@wait_for_background_threads()
def _test():
response = target_application.get("/raise-exception-response/", status=500)
assert response.status == "500 Internal Server Error"

_test()


@override_application_settings({"transaction_name.naming_scheme": "framework"})
def test_raise_exception_finalize(target_application):
@validate_transaction_errors(["builtins:RuntimeError"])
@validate_transaction_metrics(
"_application:sample_application",
custom_metrics=[
("Python/Dispatcher/Waitress/%s" % WAITRESS_VERSION, 1),
],
)
@raise_background_exceptions()
@wait_for_background_threads()
def _test():
response = target_application.get("/raise-exception-finalize/", status=500)
assert response.status == "500 Internal Server Error"

_test()
1 change: 1 addition & 0 deletions tests/datastore_aioredis/test_uninstrumented_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"channels",
"client_tracking_off",
"client_tracking_on",
"client_no_touch",
"close",
"closed",
"connection_pool",
Expand Down
33 changes: 33 additions & 0 deletions tests/datastore_pyodbc/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from testing_support.fixtures import ( # noqa: F401; pylint: disable=W0611
collector_agent_registration_fixture,
collector_available_fixture,
)

_default_settings = {
"transaction_tracer.explain_threshold": 0.0,
"transaction_tracer.transaction_threshold": 0.0,
"transaction_tracer.stack_trace_threshold": 0.0,
"debug.log_data_collector_payloads": True,
"debug.record_transaction_failure": True,
"debug.log_explain_plan_queries": True,
}

collector_agent_registration = collector_agent_registration_fixture(
app_name="Python Agent Test (datastore_pyodbc)",
default_settings=_default_settings,
linked_applications=["Python Agent Test (datastore)"],
)
Loading

0 comments on commit 5143afc

Please sign in to comment.