chore(api): caching flask.request in a local variable

Avoid multiple attribute lookups and simplify code.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
pull/19297/head
QuantumGhost 1 year ago committed by GitHub
parent ad02a422a1
commit c40e6e01a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -56,10 +56,11 @@ def init_app(app: DifyApp):
status_code = int(status)
status_class = f"{status_code // 100}xx"
attributes: dict[str, str | int] = {"status_code": status_code, "status_class": status_class}
if flask.request and flask.request.url_rule:
attributes[SpanAttributes.HTTP_TARGET] = str(flask.request.url_rule.rule)
if flask.request and flask.request.method:
attributes[SpanAttributes.HTTP_METHOD] = str(flask.request.method)
request = flask.request
if request and request.url_rule:
attributes[SpanAttributes.HTTP_TARGET] = str(request.url_rule.rule)
if request and request.method:
attributes[SpanAttributes.HTTP_METHOD] = str(request.method)
_http_response_counter.add(1, attributes)
instrumentor = FlaskInstrumentor()

Loading…
Cancel
Save