Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Add support for connection scopes if logging is enabled #1953

Merged
merged 5 commits into from
Jul 12, 2017

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Jul 11, 2017

  • Don't create a scope if logging isn't on
  • Copied the pattern we use in Hosting

Questions:

  • Should we remove the connection id parameter from the logs? I'd suggesting removing it only if the log message is readable without it. For e.g we could say "Connected started" instead of "Connection {ConnectionId} started" but it doesn't really hurt.

Before:

image

After:

image

#640

- Don't create a scope if logging isn't on
- Copied the pattern we use in Hosting
Copy link
Contributor

@natemcmaster natemcmaster left a comment

Choose a reason for hiding this comment

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

LGTM, but I don't see tests.

@cesarblum
Copy link
Contributor

Should we have a scope per request as well?

@Tratcher
Copy link
Member

Hosting creates one right?

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

👍 for tests

return null;
}

private class ConnectionScope : IReadOnlyList<KeyValuePair<string, object>>
Copy link
Member

Choose a reason for hiding this comment

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

Move to another file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? It's a private class literally only used in this file.

Copy link
Member

Choose a reason for hiding this comment

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

That's also true for all the dozens of what used to be private classes we moved to their own files in Kestrel. FrameConnection is already pretty big.

var adaptedPipelineTask = Task.CompletedTask;
var input = _context.Input.Reader;
var output = _context.Output;
Log.ConnectionStart(ConnectionId);
Copy link
Member

Choose a reason for hiding this comment

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

Nit. No need for newline after try {

{
_cachedToString = string.Format(
CultureInfo.InvariantCulture,
"ConnectionId:{0}",
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove @"Connection id ""{ConnectionId}"" from KestrelTrace and LibuvTrace for logs we no we make from the async local scope? It seems a bit redundant if we don't remove it, but it could lead to a worse experience with loggers that don't support scopes.

Copy link
Member

Choose a reason for hiding this comment

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

Also now that we have this should we log any extra metadata about the connection (e.g. remote IP) when a connection starts?

Copy link
Contributor

Choose a reason for hiding this comment

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

How well do our own loggers support scopes? e.g. console, Azure app services, etc. If these don't easily display the name of the scope along with the message, we should keep the connection id in the message for now.

Copy link
Member

Choose a reason for hiding this comment

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

@natemcmaster That's what I was concerned about. Assuming this is for 2.1, maybe we should still do this and add scope support to our loggers.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we should keep it in the logs.

Copy link
Contributor

@natemcmaster natemcmaster left a comment

Choose a reason for hiding this comment

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

One minor nit, then :shipit:

@@ -0,0 +1,60 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: copyright header

@davidfowl davidfowl merged commit 7ebbdad into dev Jul 12, 2017
@halter73 halter73 deleted the davidfowl/connection-scopes branch July 12, 2017 22:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants