Skip to content

Commit 5d6de1a

Browse files
committed
use urllib to extract the path
1 parent 39939c9 commit 5d6de1a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

ddtrace/_trace/processor/resource_renaming.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import re
22
from typing import List
33
from typing import Optional
4+
from urllib.parse import urlparse
45

56
from ddtrace._trace.processor import SpanProcessor
67
from ddtrace.ext import SpanTypes
78
from ddtrace.ext import http
9+
from ddtrace.internal.logger import get_logger
810
from ddtrace.settings._config import config
911

1012

13+
log = get_logger(__name__)
14+
15+
1116
class ResourceRenamingProcessor(SpanProcessor):
1217
def __init__(self):
13-
self._URL_PATH_EXTRACTION_RE = re.compile(
14-
r"^(?P<protocol>[a-z]+://(?P<host>[^?/]+))?(?P<path>/[^?]*)(?P<query>(\?).*)?$"
15-
)
16-
1718
self._INT_RE = re.compile(r"^[1-9][0-9]+$")
1819
self._INT_ID_RE = re.compile(r"^(?=.*[0-9].*)[0-9._-]{3,}$")
1920
self._HEX_RE = re.compile(r"^(?=.*[0-9].*)[A-Fa-f0-9]{6,}$")
@@ -39,10 +40,12 @@ def _compute_simplified_endpoint(self, url: Optional[str]) -> str:
3940
if not url:
4041
return "/"
4142

42-
match = self._URL_PATH_EXTRACTION_RE.match(url)
43-
if not match:
43+
try:
44+
parsed_url = urlparse(url)
45+
except ValueError as e:
46+
log.error("Failed to parse http.url tag when processing span for resource renaming: %s", e)
4447
return "/"
45-
path = match.group("path")
48+
path = parsed_url.path
4649
if not path or path == "/":
4750
return "/"
4851

0 commit comments

Comments
 (0)