-
Notifications
You must be signed in to change notification settings - Fork 645
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 flask #828
Changes from 5 commits
72cabca
07e98be
389cc7e
6388b47
9927c0a
0907455
8f50cac
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 |
---|---|---|
|
@@ -176,15 +176,24 @@ def _before_request(): | |
return | ||
flask_request_environ = flask.request.environ | ||
span_name = get_default_span_name() | ||
token = context.attach( | ||
extract(flask_request_environ, getter=otel_wsgi.wsgi_getter) | ||
) | ||
|
||
token = ctx = span_kind = None | ||
|
||
if trace.get_current_span() is trace.INVALID_SPAN: | ||
ctx = extract(flask_request_environ, getter=otel_wsgi.wsgi_getter) | ||
token = context.attach(ctx) | ||
span_kind = trace.SpanKind.SERVER | ||
else: | ||
ctx = context.get_current() | ||
span_kind = trace.SpanKind.INTERNAL | ||
|
||
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. If span is found in current context, I believe you'll have to set the current context as the parent. Currently, 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. Done. 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. Oh yes you are correct. Either way is fine with me. |
||
span = tracer.start_span( | ||
span_name, | ||
kind=trace.SpanKind.SERVER, | ||
ctx, | ||
kind=span_kind, | ||
start_time=flask_request_environ.get(_ENVIRON_STARTTIME_KEY), | ||
) | ||
|
||
if request_hook: | ||
request_hook(span, flask_request_environ) | ||
|
||
|
@@ -229,7 +238,9 @@ def _teardown_request(exc): | |
activation.__exit__( | ||
type(exc), exc, getattr(exc, "__traceback__", None) | ||
) | ||
context.detach(flask.request.environ.get(_ENVIRON_TOKEN)) | ||
|
||
if flask.request.environ.get(_ENVIRON_TOKEN, None): | ||
context.detach(flask.request.environ.get(_ENVIRON_TOKEN)) | ||
|
||
return _teardown_request | ||
|
||
|
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.
Added this as
django.conf.urls.url()
is removed in django 4.0. leading to lint check failure (release notes).cc @lzchen