Skip to content
Draft
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
3 changes: 2 additions & 1 deletion elasticapm/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def get_name_from_func(func: FunctionType) -> str:


def build_name_with_http_method_prefix(name, request):
return " ".join((request.method, name)) if name else name
name = name or "unknown route"
return "{} {}".format(request.method, name) if hasattr(request, "method") else name


def is_master_process() -> bool:
Expand Down
17 changes: 17 additions & 0 deletions tests/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import elasticapm.utils
from elasticapm.conf import constants
from elasticapm.utils import (
build_name_with_http_method_prefix,
get_name_from_func,
get_url_dict,
getfqdn,
Expand Down Expand Up @@ -263,3 +264,19 @@ def test_getfqdn(invalidate_fqdn_cache):
def test_getfqdn_caches(invalidate_fqdn_cache):
elasticapm.utils.fqdn = "foo"
assert getfqdn() == "foo"


class Request:
method: "str" = "GET"


@pytest.mark.parametrize(
"http_request,name,expected",
[
("", None, "unknown route"),
(Request, None, "GET unknown route"),
(Request, "/foo", "GET /foo"),
],
)
def test_build_name_with_http_method_prefix(http_request, name, expected):
assert build_name_with_http_method_prefix(name, http_request) == expected
Loading