Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Inject W3C headers in HTTP diagnostics handler#35882

Merged
vancem merged 4 commits intodotnet:masterfrom
lmolkova:w3cHttpCoreHooks
Mar 11, 2019
Merged

Inject W3C headers in HTTP diagnostics handler#35882
vancem merged 4 commits intodotnet:masterfrom
lmolkova:w3cHttpCoreHooks

Conversation

@lmolkova
Copy link

@lmolkova lmolkova commented Mar 8, 2019

Depending on the Activity.IdFormat we want to inject W3C distributed tracing headers or Request-Id headers.

@lmolkova lmolkova requested review from davidsh and vancem March 8, 2019 04:44
var diagnosticListenerObserver = new FakeDiagnosticListenerObserver(kvp =>
{
if (kvp.Key.Equals("System.Net.Http.Request"))
{ requestLogged = true; }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not standard bracing style for CoreFx.

request.Headers.Add(DiagnosticsHandlerLoggingStrings.TraceStateHeaderName, currentActivity.TraceStateString);
}
}
else if(!request.Headers.Contains(DiagnosticsHandlerLoggingStrings.RequestIdHeaderName))
Copy link

Choose a reason for hiding this comment

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

Do you want the 'if' condition to have two terms in it?
As it is if the ID format is W3C AND you already have a TraceParent header, you ALSO try to add a RequestId header.

This is not what I would have expected. Feels like what you want is

                if (currentActivity.IdFormat == ActivityIdFormat.W3C)
                {
                    if (request.Headers.Contains(DiagnosticsHandlerLoggingStrings.TraceParentHeaderName))
                    {
                        request.Headers.Add(DiagnosticsHandlerLoggingStrings.TraceParentHeaderName, currentActivity.Id);
                        if (currentActivity.TraceStateString != null)
                        {
                            request.Headers.Add(DiagnosticsHandlerLoggingStrings.TraceStateHeaderName, currentActivity.TraceStateString);
                        }
                    }
                }
                else // Not W3C Format
                { 
                    if(!request.Headers.Contains(DiagnosticsHandlerLoggingStrings.RequestIdHeaderName))
                    {
                        request.Headers.Add(DiagnosticsHandlerLoggingStrings.RequestIdHeaderName, currentActivity.Id);
                    }
                }

Copy link

Choose a reason for hiding this comment

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

But otherwise it looks OK.

Copy link
Author

Choose a reason for hiding this comment

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

thanks, fixed

@vancem
Copy link

vancem commented Mar 11, 2019

This change, if you ignore the testing changes, is quite small and simply propagating the new W3C ids into HTTP headers. It is doing the analogous thing to what was done before or previous (hierarachical) IDs. This is new behavior that should be back-compat.

Unless someone raises an objection I will merge this later today.

@vancem vancem merged commit 7314001 into dotnet:master Mar 11, 2019
@karelz karelz added this to the 3.0 milestone Mar 18, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Inject W3C headers in corefx Htpp Diagnostics HAndler

* Inject W3C headers if activity format is W3C

* fix style and indentation

* review: fix issue


Commit migrated from dotnet/corefx@7314001
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.

4 participants