Skip to content

Commit

Permalink
Update ASGI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
macieyng committed Apr 16, 2023
1 parent d01c96f commit e67218a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,12 @@ def get_default_span_details(scope: dict) -> Tuple[str, dict]:
Returns:
a tuple of the span name, and any attributes to attach to the span.
"""
if scope.get("type") == "websocket":
return f"{scope.get('path', '').strip()}", {}
span_name = (
scope.get("path", "").strip()
or f"HTTP {scope.get('method', '').strip()}"
f"{scope.get('method', '').strip()} {scope.get('path', '').strip()}"
if scope.get("path", "").strip()
else f"{scope.get('method', '').strip()}"
)

return span_name, {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,25 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
self.assertEqual(len(span_list), 4)
expected = [
{
"name": "/ http receive",
"name": "GET / http receive",
"kind": trace_api.SpanKind.INTERNAL,
"attributes": {"type": "http.request"},
},
{
"name": "/ http send",
"name": "GET / http send",
"kind": trace_api.SpanKind.INTERNAL,
"attributes": {
SpanAttributes.HTTP_STATUS_CODE: 200,
"type": "http.response.start",
},
},
{
"name": "/ http send",
"name": "GET / http send",
"kind": trace_api.SpanKind.INTERNAL,
"attributes": {"type": "http.response.body"},
},
{
"name": "/",
"name": "GET /",
"kind": trace_api.SpanKind.SERVER,
"attributes": {
SpanAttributes.HTTP_METHOD: "GET",
Expand Down Expand Up @@ -231,7 +231,7 @@ def update_expected_span_name(expected):
entry["name"] = span_name
else:
entry["name"] = " ".join(
[span_name] + entry["name"].split(" ")[1:]
[span_name] + entry["name"].split(" ")[2:]
)
return expected

Expand Down Expand Up @@ -284,6 +284,7 @@ def update_expected_server(expected):
SpanAttributes.HTTP_URL: "http://0.0.0.0/",
}
)
# TODO:self possibly update span name to just method
return expected

self.scope["server"] = None
Expand Down Expand Up @@ -493,9 +494,9 @@ def update_expected_hook_results(expected):
for entry in expected:
if entry["kind"] == trace_api.SpanKind.SERVER:
entry["name"] = "name from server hook"
elif entry["name"] == "/ http receive":
elif entry["name"] == "GET / http receive":
entry["name"] = "name from client request hook"
elif entry["name"] == "/ http send":
elif entry["name"] == "GET / http send":
entry["attributes"].update({"attr-from-hook": "value"})
return expected

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _start_internal_or_server_span(
Args:
tracer : tracer in use by given instrumentation library
name (string): name of the span
span_name (string): name of the span
start_time : start time of the span
context_carrier : object which contains values that are
used to construct a Context. This object
Expand Down

0 comments on commit e67218a

Please sign in to comment.