Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing trace log for websocket protocols #1083

Merged
merged 3 commits into from Jun 19, 2021

Conversation

laggardkernel
Copy link
Contributor

@laggardkernel laggardkernel commented Jun 18, 2021

Formerly we only have trace log for http protocols on connection_made and
connection_lost events. Not very sure, but I guess we forget
to add trace log for websocket protocols?

@Kludex Kludex requested a review from euri10 June 18, 2021 14:31
Copy link
Member

@euri10 euri10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, this would look better with some tests added, I think we may have some in test_logging.py !

now one thing I just realize reading what seem to be a copy of what we do in the http protocols is the following (bear with me it's been a while I did not touch this) : self.logger here is a uvicorn.error logger, however iirc when we set log_level to trace in Config, we end up with a middleware that spits out those trace log levels on the uvicorn.asgi logger. so should we put those under the uvicorn.asgi logger ? not sure if that makes sense.

no, correcting myself, those are good under that uvicorn.error logger, those are not strictly speaking asgi message where we put the one sent by the middlware

tests/middleware/test_logging.py Outdated Show resolved Hide resolved
tests/middleware/test_logging.py Outdated Show resolved Hide resolved
tests/middleware/test_logging.py Outdated Show resolved Hide resolved
tests/middleware/test_logging.py Outdated Show resolved Hide resolved
tests/middleware/test_logging.py Outdated Show resolved Hide resolved
uvicorn/protocols/websockets/websockets_impl.py Outdated Show resolved Hide resolved
@euri10
Copy link
Member

euri10 commented Jun 19, 2021

genuine question @laggardkernel : why did you need that ?

@laggardkernel
Copy link
Contributor Author

genuine question @laggardkernel : why did you need that ?

What you mean by "that", this PR?

@euri10
Copy link
Member

euri10 commented Jun 19, 2021

genuine question @laggardkernel : why did you need that ?

What you mean by "that", this PR?

yes I mean the ws trace messages :)

@laggardkernel
Copy link
Contributor Author

@euri10 Not sure. Because there's only trace log for http protocol. It made me wonder if we forgot to add the same level log for ws.

I did a searching about the history of trace log on http protocol.

Logging on connection made, connection lost was first introduced in uvicorn 0.2.0,
commit 07c6c18. At that time, it was categorized as access log. (In fact, there was
no separate "uvicorn.access" loggers yet.)

Later, with the coming of the TRACE_LOG_LEVEL in commit 1238455, http protocol connection logs was changed
to be logged with level 5.

Maybe @tomchristie could answer this, considering he's the guy designed the trace log and later integrated it into MessageLoggerMiddleware.

@euri10
Copy link
Member

euri10 commented Jun 19, 2021

Ok I just wondered if there was a use case behind that and if you needed it to debug some sort of issue !

Formerly we only have trace log for http protocol. It seems we missed
to add trace log for websocket protocols.
Protocols emit trace logs on `connection_made()` and `connection_lost`.
Add missing tests for these logs.
The default transport protocol is http protocol. A ws request
is firstly handled using http protocol, then handled using ws protocol
by switching the protocol. To discriminate the trace log emitter,
we need to specify the protocol type in the log message.
Copy link
Member

@euri10 euri10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks beautiful, thanks a lot @laggardkernel and the benefit of having that trace level declared everywhere is that thre's no need to wait for the refactor PR merge !

@euri10 euri10 merged commit caa0e97 into encode:master Jun 19, 2021
@euri10 euri10 mentioned this pull request Jun 21, 2021
Kludex pushed a commit that referenced this pull request Nov 17, 2021
* Add missing trace log for websocket protocols

Formerly we only have trace log for http protocol. It seems we missed
to add trace log for websocket protocols.

* Add trace logging tests for protocols

Protocols emit trace logs on `connection_made()` and `connection_lost`.
Add missing tests for these logs.

* Specify connection type in protocol trace log

The default transport protocol is http protocol. A ws request
is firstly handled using http protocol, then handled using ws protocol
by switching the protocol. To discriminate the trace log emitter,
we need to specify the protocol type in the log message.
Kludex pushed a commit to sephioh/uvicorn that referenced this pull request Oct 29, 2022
* Add missing trace log for websocket protocols

Formerly we only have trace log for http protocol. It seems we missed
to add trace log for websocket protocols.

* Add trace logging tests for protocols

Protocols emit trace logs on `connection_made()` and `connection_lost`.
Add missing tests for these logs.

* Specify connection type in protocol trace log

The default transport protocol is http protocol. A ws request
is firstly handled using http protocol, then handled using ws protocol
by switching the protocol. To discriminate the trace log emitter,
we need to specify the protocol type in the log message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants