-
Notifications
You must be signed in to change notification settings - Fork 535
Add Trace.wrap decorator #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
9bf2df8
c9c2bef
845eddc
9564ccb
f30c4e0
6fa5c74
78968d9
089021d
c73e1b3
44d4f72
8faed3b
ff0fbef
a582a89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
|
|
||
| import functools | ||
| import logging | ||
| import threading | ||
|
|
||
|
|
@@ -63,6 +63,20 @@ def configure(self, enabled=None, hostname=None, port=None, sampler=None): | |
| if sampler is not None: | ||
| self.sampler = sampler | ||
|
|
||
| def wrap(self, name=None, service=None, resource=None, span_type=None): | ||
| def wrap_decorator(func): | ||
| if name is None: | ||
| span_name = '{}.{}'.format(func.__module__, func.__name__) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (comment got buried so reposting): It's worth discussing whether we want to include the module name as well as the function name here. Including the module name is good because we can tell exactly which function is being traced. Including the module name is bad because we may get really long span names, and our interface doesn't display these well at this time. I'm learning towards including the module name.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i really want to nudge people towards short spans. |
||
| else: | ||
| span_name = name | ||
|
|
||
| @functools.wraps(func) | ||
| def func_wrapper(*args, **kwargs): | ||
| with self.trace(span_name, service=service, resource=resource, span_type=span_type): | ||
| func(*args, **kwargs) | ||
| return func_wrapper | ||
| return wrap_decorator | ||
|
|
||
| def trace(self, name, service=None, resource=None, span_type=None): | ||
| """Return a span that will trace an operation called `name`. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth discussing whether we want to include the module name as well as the function name here.
Including the module name is good because we can tell exactly which function is being traced.
Including the module name is bad because we may get really long span names, and our interface doesn't display these well at this time.
I'm learning towards including the module name.