Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions skywalking/plugins/sw_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ def _sw_request(this: Session, method, url,
for item in carrier:
headers[item.key] = item.val

span.tag(Tag(key=tags.HttpMethod, val=method.upper()))
span.tag(Tag(key=tags.HttpUrl, val=url))

res = _request(this, method, url, params, data, headers, cookies, files, auth, timeout,
allow_redirects,
proxies,
hooks, stream, verify, cert, json)

span.tag(Tag(key=tags.HttpMethod, val=method.upper()))
span.tag(Tag(key=tags.HttpUrl, val=url))
span.tag(Tag(key=tags.HttpStatus, val=res.status_code))
if res.status_code >= 400:
span.error_occurred = True
Expand Down
5 changes: 3 additions & 2 deletions skywalking/plugins/sw_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ def _sw_request(this: RequestMethods, method, url, fields=None, headers=None, **
for item in carrier:
headers[item.key] = item.val

res = _request(this, method, url, fields=fields, headers=headers, **urlopen_kw)

span.tag(Tag(key=tags.HttpMethod, val=method.upper()))
span.tag(Tag(key=tags.HttpUrl, val=url))

res = _request(this, method, url, fields=fields, headers=headers, **urlopen_kw)

span.tag(Tag(key=tags.HttpStatus, val=res.status))
if res.status >= 400:
span.error_occurred = True
Expand Down
16 changes: 12 additions & 4 deletions skywalking/plugins/sw_urllib_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

def install():
from urllib.request import OpenerDirector
from urllib.error import HTTPError

_open = OpenerDirector.open

Expand All @@ -38,15 +39,22 @@ def _sw_open(this: OpenerDirector, fullurl, data, timeout):

context = get_context()
carrier = Carrier()
with context.new_exit_span(op=fullurl.selector or '/', peer=fullurl.host, carrier=carrier) as span:
url = fullurl.selector.split("?")[0] if fullurl.selector else '/'
with context.new_exit_span(op=url, peer=fullurl.host, carrier=carrier) as span:
span.layer = Layer.Http
span.component = Component.General

[fullurl.add_header(item.key, item.val) for item in carrier]

res = _open(this, fullurl, data, timeout)
span.tag(Tag(key=tags.HttpMethod, val=fullurl.get_method()))
span.tag(Tag(key=tags.HttpUrl, val=fullurl.full_url))
try:
res = _open(this, fullurl, data, timeout)
except HTTPError as e:
span.tag(Tag(key=tags.HttpStatus, val=e.code))
raise
finally: # we do this here because it may change in _open()
span.tag(Tag(key=tags.HttpMethod, val=fullurl.get_method()))
span.tag(Tag(key=tags.HttpUrl, val=fullurl.full_url))

span.tag(Tag(key=tags.HttpStatus, val=res.code))
if res.code >= 400:
span.error_occurred = True
Expand Down