Skip to content

Commit 82d3b8d

Browse files
committed
Add better docstrings and also some types.
1 parent 9a551b1 commit 82d3b8d

File tree

1 file changed

+11
-7
lines changed
  • instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server

1 file changed

+11
-7
lines changed

instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,28 @@ def _parse_active_request_count_attrs(req_attrs):
6363
def get_default_span_details(request: web.Request) -> Tuple[str, dict]:
6464
"""Default implementation for get_default_span_details
6565
Args:
66-
scope: the asgi scope dictionary
66+
request: the request object itself.
6767
Returns:
6868
a tuple of the span name, and any attributes to attach to the span.
6969
"""
7070
span_name = request.path.strip() or f"HTTP {request.method}"
7171
return span_name, {}
7272

7373

74-
def _get_view_func(request) -> str:
75-
"""TODO: is this useful??"""
74+
def _get_view_func(request: web.Request) -> str:
75+
"""Returns the name of the request handler.
76+
Args:
77+
request: the request object itself.
78+
Returns:
79+
a string containing the name of the handler function
80+
"""
7681
try:
7782
return request.match_info.handler.__name__
7883
except AttributeError:
7984
return "unknown"
8085

8186

82-
def collect_request_attributes(request: web.Request):
87+
def collect_request_attributes(request: web.Request) -> Dict:
8388
"""Collects HTTP request attributes from the ASGI scope and returns a
8489
dictionary to be used as span creation attributes."""
8590

@@ -125,10 +130,9 @@ def collect_request_attributes(request: web.Request):
125130
return result
126131

127132

128-
def set_status_code(span, status_code):
133+
def set_status_code(span, status_code: int) -> None:
129134
"""Adds HTTP response attributes to span using the status_code argument."""
130-
if not span.is_recording():
131-
return
135+
132136
try:
133137
status_code = int(status_code)
134138
except ValueError:

0 commit comments

Comments
 (0)