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

Fix Type Constructor Classes in Code Level Metrics #708

Merged
merged 8 commits into from Dec 7, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup-python-matrix/action.yml
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 virtualenv!=20.0.24
python3.10 -m pip install -U wheel setuptools 'tox<4' virtualenv!=20.0.24
2 changes: 1 addition & 1 deletion newrelic/core/code_level_metrics.py
Expand Up @@ -89,7 +89,7 @@ def extract_code_from_callable(func):
# Use inspect to get file and line number
file_path = inspect.getsourcefile(func)
line_number = inspect.getsourcelines(func)[1]
except TypeError:
except Exception:
pass

# Split function path to extract class name
Expand Down
41 changes: 38 additions & 3 deletions tests/agent_features/_test_code_level_metrics.py
Expand Up @@ -13,11 +13,12 @@
# limitations under the License.
import functools


def exercise_function():
return


class ExerciseClass():
class ExerciseClass(object):
def exercise_method(self):
return

Expand All @@ -30,12 +31,46 @@ def exercise_class_method(cls):
return


class ExerciseClassCallable():
class ExerciseClassCallable(object):
def __call__(self):
return


def exercise_method(self):
return


@staticmethod
def exercise_static_method():
return


@classmethod
def exercise_class_method(cls):
return


def __call__(self):
return


type_dict = {
"exercise_method": exercise_method,
"exercise_static_method": exercise_static_method,
"exercise_class_method": exercise_class_method,
"exercise_lambda": lambda: None,
}
callable_type_dict = type_dict.copy()
callable_type_dict["__call__"] = __call__

ExerciseTypeConstructor = type("ExerciseTypeConstructor", (object,), type_dict)
ExerciseTypeConstructorCallable = type("ExerciseTypeConstructorCallable", (object,), callable_type_dict)


CLASS_INSTANCE = ExerciseClass()
CLASS_INSTANCE_CALLABLE = ExerciseClassCallable()
TYPE_CONSTRUCTOR_CLASS_INSTANCE = ExerciseTypeConstructor()
TYPE_CONSTRUCTOR_CALLABLE_CLASS_INSTANCE = ExerciseTypeConstructorCallable()

exercise_lambda = lambda: None
exercise_lambda = lambda: None # noqa: E731
exercise_partial = functools.partial(exercise_function)