Skip to content

Commit fea91b7

Browse files
committed
chore(wsgi): move setting request attributes to a separate method
Signed-off-by: Varsha GS <[email protected]>
1 parent 5bd20fe commit fea91b7

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/instana/instrumentation/wsgi.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,7 @@ def __call__(self, environ: Dict[str, Any], start_response: Callable) -> object:
3939
extract_custom_headers(span, env, format=True)
4040

4141
# Set request attributes
42-
if "PATH_INFO" in env:
43-
span.set_attribute("http.path", env["PATH_INFO"])
44-
if "QUERY_STRING" in env and len(env["QUERY_STRING"]):
45-
scrubbed_params = strip_secrets_from_query(
46-
env["QUERY_STRING"],
47-
agent.options.secrets_matcher,
48-
agent.options.secrets_list,
49-
)
50-
span.set_attribute("http.params", scrubbed_params)
51-
if "REQUEST_METHOD" in env:
52-
span.set_attribute(SpanAttributes.HTTP_METHOD, env["REQUEST_METHOD"])
53-
if "HTTP_HOST" in env:
54-
span.set_attribute("http.host", env["HTTP_HOST"])
42+
_set_request_attributes(span, env)
5543

5644
def new_start_response(
5745
status: str,
@@ -110,3 +98,18 @@ def _end_span_after_iterating(
11098
span.end()
11199
if token:
112100
context.detach(token)
101+
102+
def _set_request_attributes(span: "InstanaSpan", env: Dict[str, Any]) -> None:
103+
if "PATH_INFO" in env:
104+
span.set_attribute("http.path", env["PATH_INFO"])
105+
if "QUERY_STRING" in env and len(env["QUERY_STRING"]):
106+
scrubbed_params = strip_secrets_from_query(
107+
env["QUERY_STRING"],
108+
agent.options.secrets_matcher,
109+
agent.options.secrets_list,
110+
)
111+
span.set_attribute("http.params", scrubbed_params)
112+
if "REQUEST_METHOD" in env:
113+
span.set_attribute(SpanAttributes.HTTP_METHOD, env["REQUEST_METHOD"])
114+
if "HTTP_HOST" in env:
115+
span.set_attribute(SpanAttributes.HTTP_HOST, env["HTTP_HOST"])

0 commit comments

Comments
 (0)