jonwagner / EventSourceProxy

EventSourceProxy (ESP) is the easiest way to add scalable Event Tracing for Windows (ETW) logging to your .NET program
Other
97 stars 20 forks source link

Auto-generated Keywords #9

Closed BeheadedKamikaze closed 10 years ago

BeheadedKamikaze commented 10 years ago

We have some WCF services and we are using ESP for Tracing. One of them has an interface with some number of methods (> 22 seems to be the magic number).

We are about to migrate our dev environment to Windows 8.1, so we set up one machine this way. Now, during execution of our packaging script, generateproxymanifest.exe crashes with an error that Keywords above 0x0000100000000000 are reserved for system use. It didn't do this under Windows 8.

What we can see is that a Keyword is automatically generated for every interface method (including Async versions). At 22 methods, 44 Keywords are generated, each with a higher power of 2.

Question is: what is the reason for the automatic Keywords generation, and is it possible to turn this off?

Thanks

agehrke commented 10 years ago

I had the same problem. You can prevent autogenerating keywords by specifying a Keywords type in the EventSourceImplementation attribute.

[EventSourceProxy.EventSourceImplementation(Name = "MyEvents", Keywords = typeof(YourNameSapce.MyKeywords))]
jonwagner commented 10 years ago

Correct - by default, ESP will generate a keyword for each method so you can enable tracing by method. This used to give you 64 bits, but Windows 8.1 changed that.

You can manually specify the keywords, and that will turn off the auto-keyword generation.

I think that ESP should handle that situation better. There are a few options:

  1. Throw a nice explanatory exception when you go over the allowed number methods.
  2. Silently stop adding Keywords at that point. (meh).
  3. Suggestions?

I would combine either option with an EventSourceImplementationAttribute option to disable Keyword generation.

BeheadedKamikaze commented 10 years ago

Adding this attribute to the interface in the WCF proxy generated Reference.cs fixed the crash. However every time we regenerate our proxy (i.e. Update Service Reference) it is going to go back how it was. How did you solve that? Is there a way to edit the template it uses to generate that file?

BeheadedKamikaze commented 10 years ago

Hi Jon, would not the event itself be enough to trace by method? I see the Keywords as being more 'categorical' in nature. E.g. "Database", "Network", "UI", "Admin", etc.

With regards to outright disabling that, I can't say how many people are or are not relying on it to automatically generate the Keywords from method names. If there might be outcry at the thought of removing that feature, possibly if it could work out there are too many methods then it could suppress generating any keywords, would be at least preferable to crashing.

Or opt-in rather than opt-out? Just throwing around ideas here :-)

mot256 commented 10 years ago

I tend to agree with kamikaze here. The the auto generated keywords feature should rather be a "opt-in" feature than default feature.

jonwagner commented 10 years ago

Ok, I now see how you are using it.

If you want to add attributes to a WCF proxy, create a separate .cs file and a partial class:

[EventSourceImpementation(...)]
public partial class MyWebService : WebService {}

The compiler will merge them together and your class won't be overwriiten when you generate the proxy.

jonwagner commented 10 years ago

Since people are using ESP for things like WCF proxies, we definitely can't choose the exception approach. You wouldn't want your code to blow up simply by enabling tracing.

Keywords are designed to be used for categories of calls. They are the only mechanism that lets you enable/disable tracing at a more granular level than the entire interface. If you're logging a wide interface, at some point in production, there is a good chance that you are going to want to only enable some of the events. So you should add your own keywords.

In my experience, not all dev teams are going to think through the logging implications of all of their interfaces. So I'd like ESP to be their best friend as much as possible and handle the keywords so when production is down, they can just turn on tracing.

I guess my rationale is that AutoKeywords hurts nobody who doesn't notice them, and helps people that don't have time to think through logging. So, the best choice seems to be AutoKeywords but don't throw exceptions. (And maybe do some smart folding of names like XXX, BeginXXX, EndXXX, XXXAsync all fold into XXX.)

Unless someone knows a reason why generating keywords is bad?

BeheadedKamikaze commented 10 years ago

Hi Jon,

I have made a change (locally) to the 1.1.2 release to allow it to stop auto-generating Keywords after 0x0000100000000000 for Windows 8.1. Would you be willing to accept a patch for a public 1.1.3 release (and available on NuGet)?

Changes are as follows. TypeImplementer.cs: Line 51: add this

        /// <summary>
        /// The maximum user-defined Keywords value since Windows 8.1.
        /// </summary>
        private const ulong MaxKeywordValue = 0x0000100000000000;

Line 235: add this inside foreach

                // System.ArgumentException: Keywords values larger than 0x0000100000000000 are reserved for system use
                if (autoKeyword >= MaxKeywordValue)
                {
                    autoKeyword = 0;
                }

Cheers Chris

jonwagner commented 10 years ago

Done. Thanks for the code.

v1.1.3 and v2.0.0-alpha2 both have this fix.

BeheadedKamikaze commented 10 years ago

My apologies.. couldn't find any other way to contact you directly.

Thank you very much!