-
Notifications
You must be signed in to change notification settings - Fork 5k
Can't see FormattedMessage for EventSource events in PerfView #32877
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
Comments
What command are you using to collect the trace and which events are you expecting to see this information for? I assumed the picture you linked is to show an example of behavior you were expecting (it does have text in the FormattedText column), let me know if that isn't the correct interpretation. When I looked at your repro I saw a few potential issues:
If you want the trace to collect the counters (and you don't have to) then you need to tell it how often to collect them. It can be indicated like this:
|
If your goal is only to log counters and not to log the explicit events for each RequestStart and request failure then you probably want to remove the [Event(...)] attribute from those methods and use the NonEvent attribute instead. If your goal is to log an event each time a request starts/fails then you should call WriteEvent(...) inside the implementation of ModuleRequestStarted and ModuleRequestFailed. As the code is currently written you won't get explicit events for RequestStart/RequestFailed because WriteEvent() is never called. The Event attribute causes no harm that I am aware of, but it might confuse someone reading the source. There are also some minor side-effects where EventSource is creating data structures/event manifests assuming that RequestStart/RequestFailed events might be emitted but they never are. |
Thanks @noahfalk for clarification and educating me. I assumed that writing an event counter also wrote corresponding event. I've updated the code to call [Event(Id.RequestCompletedId, Message = "Request for module '{0}' completed", Level = EventLevel.Informational)]
public void RequestCompleted(string moduleId)
{
WriteEvent(Id.RequestCompletedId, moduleId);
// ...
} Thanks for the tip about fetching interval counters with specified interval. That explains why I occasionally saw them in perfview. I'm thinking of writing an event with a formatted message
|
I investigated a bit and there are appears to be more than one issue causing this. The first one that I expected is that you are running into a current limitation with nettrace file serialization. When collecting using ETW (.etl files) the string you put in the Message attribute is transmitted as part of the trace, but the nettrace file isn't saving it. Without the template string available PerfView is unable to produce the final formatted string. This is one of the unfortunate rough edges where nettrace isn't yet at full parity with ETW capabilities. As a workaround if you get rid of the FormattedMessage column in PerfView then the Rest column will show you the raw key/value pairs that were collected, including your moduleId parameter:
HttpClient supports pluggable handlers that can run code when the message is going out or a response is coming back. The logging you've spotted comes from two different handlers that I was aware of, though you could also add your own:
Unless you want to add your own HttpMessageHandler to log in a custom way, the rest of the solutions are around converting between the forms of logging that are in place and the form of logging you ultimately want. If your goal is to get the logging out-of-process using dotnet trace then we are looking at solutions that convert from DiagnosticSource -> EventSource or from ILogger to EventSource. You already spotted the option to implement your own DiagnosticListener and do the conversion directly. Likewise you could create your own ILoggerProvider and do a similar conversion on the ILogger messages. However there are also two existing mechanisms that might give you what you were hoping for:
Sorry about the FormattedMessage troubles but hope this info helps : ) |
Great post! I‘ve read it and intend to look into it in more detail and provide an answer to your proposals. I’ll mention another potential finding (so I won’t forget it my self) and it relates to ‘in’ parameter modifier passed to a method that in turns calls ‘WriteEvent’ with that parameter fails. I’ll provide a repro when I have the opportunity. Thanks again for a great answer, really appreciate it and the great work put into .NET Core |
Opening new issue on behalf of @joacar. It wasn't clear if the original issue #26727 was related. Copied from #26727 (comment)
The text was updated successfully, but these errors were encountered: