Skip to content

Commit

Permalink
Marker Check for Auto HTTP Monkey PAtching
Browse files Browse the repository at this point in the history
The monkey patching assumes a marker is present but this may not always
be the case. For example, if the profiler plugin is loaded after the
trace plugin, then the profiler won't be provided an active marker. This
removes marker removal and makes the monkey patching defensive about the
presence of markers.
  • Loading branch information
kolanos committed Jun 25, 2019
1 parent 5b3e0b9 commit 3b45450
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 6 additions & 0 deletions iopipe/contrib/trace/auto_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def patch_requests_session_send(context, http_filter, http_headers):
return

def send(self, *args, **kwargs):
if not hasattr(context, "iopipe") or not hasattr(context.iopipe, "mark"):
return original_requests_session_send(self, *args, **kwargs)
id = ensure_utf8(str(uuid.uuid4()))
with context.iopipe.mark(id):
response = original_requests_session_send(self, *args, **kwargs)
Expand All @@ -96,6 +98,8 @@ def patch_botocore_session_send(context, http_filter, http_headers):
return

def send(self, *args, **kwargs):
if not hasattr(context, "iopipe") or not hasattr(context.iopipe, "mark"):
return original_botocore_session_send(self, *args, **kwargs)
id = str(uuid.uuid4())
with context.iopipe.mark(id):
response = original_botocore_session_send(self, *args, **kwargs)
Expand All @@ -122,6 +126,8 @@ def patch_botocore_vendored_session_send(context, http_filter, http_headers):
return

def send(self, *args, **kwargs):
if not hasattr(context, "iopipe") or not hasattr(context.iopipe, "mark"):
return original_botocore_vendored_session_send(self, *args, **kwargs)
id = str(uuid.uuid4())
with context.iopipe.mark(id):
response = original_botocore_vendored_session_send(self, *args, **kwargs)
Expand Down
4 changes: 1 addition & 3 deletions iopipe/contrib/trace/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ def post_setup(self, iopipe):

def pre_invoke(self, event, context):
self.timeline = Timeline()
context.iopipe.register("mark", Marker(self.timeline, context))
context.iopipe.register("mark", Marker(self.timeline, context), force=True)

if self.auto_http is True:
patch_http_requests(context, self.http_filter, self.http_headers)

def post_invoke(self, event, context):
context.iopipe.unregister("mark")

if self.auto_http is True:
restore_http_requests()

Expand Down

0 comments on commit 3b45450

Please sign in to comment.