Skip to content

Commit 38d378f

Browse files
Skip non-HTTP schemes in urllib instrumentation
1 parent b694610 commit 38d378f

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

drift/instrumentation/urllib/instrumentation.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,18 @@ def patched_open(opener_self, fullurl, data=None, timeout=_GLOBAL_DEFAULT_TIMEOU
338338
if sdk.mode == TuskDriftMode.DISABLED:
339339
return original_open(opener_self, fullurl, data, timeout)
340340

341-
# Set calling_library_context to suppress socket instrumentation warnings
342-
# context_token = calling_library_context.set("urllib")
343-
try:
344-
# Extract URL for default response handler
345-
if isinstance(fullurl, str):
346-
url = fullurl
347-
else:
348-
url = fullurl.full_url
341+
# Extract URL early so we can check the scheme
342+
if isinstance(fullurl, str):
343+
url = fullurl
344+
else:
345+
url = fullurl.full_url
349346

347+
# Only instrument HTTP/HTTPS requests; pass through file://, data://, ftp://, etc.
348+
parsed = urlparse(url)
349+
if parsed.scheme not in ("http", "https"):
350+
return original_open(opener_self, fullurl, data, timeout)
351+
352+
try:
350353
def original_call():
351354
return original_open(opener_self, fullurl, data, timeout)
352355

0 commit comments

Comments
 (0)