Skip to content

Commit ca868c1

Browse files
committed
handle empty attributes
1 parent 0b9fbcd commit ca868c1

File tree

1 file changed

+6
-1
lines changed
  • ext/opentelemetry-ext-asgi/src/opentelemetry/ext/asgi

1 file changed

+6
-1
lines changed

ext/opentelemetry-ext-asgi/src/opentelemetry/ext/asgi/__init__.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def collect_request_attributes(scope):
8080
server = scope.get("server") or ["0.0.0.0", 80]
8181
port = server[1]
8282
server_host = server[0] + (":" + str(port) if port != 80 else "")
83-
http_url = scope.get("scheme") + "://" + server_host + scope.get("path")
83+
http_url = (
84+
scope.get("scheme") + "://" + server_host + scope.get("path", "")
85+
)
8486
if scope.get("query_string"):
8587
http_url = http_url + ("?" + scope.get("query_string").decode("utf8"))
8688

@@ -107,6 +109,9 @@ def collect_request_attributes(scope):
107109
result["net.peer.ip"] = scope.get("client")[0]
108110
result["net.peer.port"] = scope.get("client")[1]
109111

112+
# remove None values
113+
result = {k: v for k, v in result.items() if v is not None}
114+
110115
return result
111116

112117

0 commit comments

Comments
 (0)