Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update datastore_trace wrapper to take instance info #883

Merged
Show file tree
Hide file tree
Changes from 3 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
89 changes: 89 additions & 0 deletions tests/agent_features/test_datastore_trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 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.validators.validate_datastore_trace_inputs import (
validate_datastore_trace_inputs,
)

from newrelic.api.background_task import background_task
from newrelic.api.datastore_trace import DatastoreTrace, DatastoreTraceWrapper


@validate_datastore_trace_inputs(
operation="test_operation",
target="test_target",
host="test_host",
port_path_or_id="test_port",
database_name="test_db_name",
)
@background_task()
def test_dt_trace_all_args():
with DatastoreTrace(
product="Agent Features",
target="test_target",
operation="test_operation",
host="test_host",
port_path_or_id="test_port",
database_name="test_db_name",
):
pass


@validate_datastore_trace_inputs(operation=None, target=None, host=None, port_path_or_id=None, database_name=None)
@background_task()
def test_dt_trace_empty():
with DatastoreTrace(product=None, target=None, operation=None):
pass


@background_task()
def test_dt_trace_callable_args():
def product_callable():
return "Agent Features"

def target_callable():
return "test_target"

def operation_callable():
return "test_operation"

def host_callable():
return "test_host"

def port_path_id_callable():
return "test_port"

def db_name_callable():
return "test_db_name"

@validate_datastore_trace_inputs(
operation="test_operation",
target="test_target",
host="test_host",
port_path_or_id="test_port",
database_name="test_db_name",
)
def _test():
pass

wrapped_fn = DatastoreTraceWrapper(
_test,
product=product_callable,
target=target_callable,
operation=operation_callable,
host=host_callable,
port_path_or_id=port_path_id_callable,
database_name=db_name_callable,
)
wrapped_fn()
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""


def validate_datastore_trace_inputs(operation=None, target=None):
def validate_datastore_trace_inputs(operation=None, target=None, host=None, port_path_or_id=None, database_name=None):
@transient_function_wrapper("newrelic.api.datastore_trace", "DatastoreTrace.__init__")
@catch_background_exceptions
def _validate_datastore_trace_inputs(wrapped, instance, args, kwargs):
Expand All @@ -44,6 +44,18 @@ def _bind_params(product, target, operation, host=None, port_path_or_id=None, da
assert captured_target == target, "%s didn't match expected %s" % (captured_target, target)
if operation is not None:
assert captured_operation == operation, "%s didn't match expected %s" % (captured_operation, operation)
if host is not None:
assert host == host, "%s didn't match expected %s" % (captured_host, host)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert host == host, "%s didn't match expected %s" % (captured_host, host)
assert captured_host == host, "%s didn't match expected %s" % (captured_host, host)

if port_path_or_id is not None:
assert captured_port_path_or_id == port_path_or_id, "%s didn't match expected %s" % (
captured_port_path_or_id,
port_path_or_id,
)
if database_name is not None:
assert captured_database_name == database_name, "%s didn't match expected %s" % (
captured_database_name,
database_name,
)

return wrapped(*args, **kwargs)

Expand Down