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

WCF Instrumentation - Using GetHeader with Try/Catch causes unintended consequences for logging tools #314

Closed
jifeingo opened this issue Oct 21, 2020 · 0 comments · Fixed by #313
Labels
bug Something isn't working

Comments

@jifeingo
Copy link
Contributor

Description
In v8.32, the WCF Instrumentation started to use the WCF Message Header to extract DT and CAT payloads. This enabled NetTCP binding support which is a headerless transport type (unlike HTTP).

In pulling the headers, the agent uses GetHeader and relies on a try/catch to deal with any problems in doing so.

                try
                {
                    headerValue = context.IncomingMessageHeaders.GetHeader<string>(key, string.Empty);
                }
                catch
                {
                }

The try catch was designed to swallow failures for when the header value wasn't a string. However, the catch also fires when the header is not found in the message. This occurs when CAT/DT is not being used.

Though this solution is functionally correct, it causes interference with a customers logging mechanism due to the catch being fired.

Customer recommended us to use the FindHeader method to determine if the header is present, first.

                try
                {
                    var headerIdx = context.IncomingMessageHeaders.FindHeader(key, string.Empty);
                    if (headerIdx != -1)
                    {
                        headerValue = context.IncomingMessageHeaders.GetHeader<string>(headerIdx);
                    }
                }
                catch
                {
                }

This results in fewer exceptions that are caught and removes any interference with customer logging tools.

Expected Behavior
No extra log messages are captured by customer app due to not finding headers.

Steps to Reproduce
??

@jifeingo jifeingo added the bug Something isn't working label Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant