-
Notifications
You must be signed in to change notification settings - Fork 624
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
Conditionally create server spans for falcon #867
Changes from 7 commits
1a44fb7
c12c54c
721b15a
9c7847f
cae0057
b9b8efb
85659a6
95b76bf
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 |
---|---|---|
|
@@ -16,9 +16,12 @@ | |
|
||
from wrapt import ObjectProxy | ||
|
||
from opentelemetry import context, trace | ||
|
||
# pylint: disable=unused-import | ||
# pylint: disable=E0611 | ||
from opentelemetry.context import _SUPPRESS_INSTRUMENTATION_KEY # noqa: F401 | ||
from opentelemetry.propagate import extract | ||
from opentelemetry.trace import StatusCode | ||
|
||
|
||
|
@@ -67,3 +70,39 @@ def unwrap(obj, attr: str): | |
func = getattr(obj, attr, None) | ||
if func and isinstance(func, ObjectProxy) and hasattr(func, "__wrapped__"): | ||
setattr(obj, attr, func.__wrapped__) | ||
|
||
|
||
def start_internal_or_server_span( | ||
tracer, span_name, start_time, env, context_getter | ||
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.
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. changed to |
||
): | ||
"""Returns internal or server span along with the token which can be used by caller to reset context | ||
|
||
|
||
Args: | ||
tracer : tracer in use by given instrumentation library | ||
name (string): name of the span | ||
start_time : start time of the span | ||
env : object which contains values that are | ||
used to construct a Context. This object | ||
must be paired with an appropriate getter | ||
which understands how to extract a value from it. | ||
context_getter : an object which contains a get function that can retrieve zero | ||
or more values from the carrier and a keys function that can get all the keys | ||
from carrier. | ||
""" | ||
|
||
token = ctx = span_kind = None | ||
if trace.get_current_span() is trace.INVALID_SPAN: | ||
ctx = extract(env, getter=context_getter) | ||
token = context.attach(ctx) | ||
span_kind = trace.SpanKind.SERVER | ||
else: | ||
ctx = context.get_current() | ||
span_kind = trace.SpanKind.INTERNAL | ||
span = tracer.start_span( | ||
name=span_name, | ||
context=ctx, | ||
kind=span_kind, | ||
start_time=start_time, | ||
) | ||
return span, token |
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.
should be private function so prefix with
_
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.
done