-
Notifications
You must be signed in to change notification settings - Fork 418
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
fix(starlette): fixes duplication due to changes path
behavior w/latest starlette versions
#8577
Conversation
root_path
and path
behavior with latest starlette versionspath
behavior w/latest starlette versions
Datadog ReportBranch report: ✅ 0 Failed, 171709 Passed, 1037 Skipped, 11m 7.1s Wall Time |
@@ -85,6 +85,17 @@ def span_from_scope(scope: Mapping[str, Any]) -> Optional[Span]: | |||
return scope.get("datadog", {}).get("request_spans", [None])[0] | |||
|
|||
|
|||
def _extract_full_path(raw_path, root_path, path): | |||
if root_path and raw_path and raw_path.startswith(root_path.encode()): | |||
raw = raw_path.split(b"?")[0] if b"?" in raw_path else raw_path |
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.
Is the raw path guaranteed to be a byte string? Can we use urlparse
here? Removing the query args using the ?
seems a bit brittle
if raw.decode() != check_path: | ||
return path | ||
|
||
return root_path + path |
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.
return root_path + path | |
return check_path |
@@ -85,6 +85,17 @@ def span_from_scope(scope: Mapping[str, Any]) -> Optional[Span]: | |||
return scope.get("datadog", {}).get("request_spans", [None])[0] | |||
|
|||
|
|||
def _extract_full_path(raw_path, root_path, path): |
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.
Can we include a doc string describing the new behavior?
"36": parse_version(sys.version) < (3, 7), # 3.6 has an extra request | ||
"rest": parse_version(sys.version) >= (3, 7), | ||
"old": starlette_version < (0, 20, 0), # below 0.20 has an extra request due to python 3.6 support | ||
"new": starlette_version >= (0, 20, 0), |
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.
There seems to be two changes here:
- Updating the riofile to run starlette tests with
<v.20.0
- Fixing a bug in how asgi middlewares set the http.url tag
Can we split up these changes?
Also would it be possible to avoid running snapshot tests on older versions of starlette? I think we have sufficient test coverage already.
@@ -542,8 +540,8 @@ def test_background_task(snapshot_client_with_tracer, tracer, test_spans): | |||
) | |||
@pytest.mark.snapshot( | |||
variants={ | |||
"36": parse_version(sys.version) < (3, 7), # 3.6 has an extra request | |||
"rest": parse_version(sys.version) >= (3, 7), | |||
"old": starlette_version < (0, 20, 0), # below 0.20 has an extra request due to python 3.6 support |
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.
Can we expand on this comment. It is not immediately clear why starlette_version<0.20
needs a unique snapshot file.
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.
We will also need a release note for the asgi changes
root_path
now contains duplicated info of the mounted path found inpath
forstarlette
> v0.34.Previously, there was no duplication when mounting applications on
starlette
. Logic is now implemented in the asgi TraceMiddleware to check theroot_path
andpath
vs theraw_path
to determine duplication.Checklist
changelog/no-changelog
is set@DataDog/apm-tees
.@DataDog/security-design-and-guidance
.Reviewer Checklist