Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Inject W3C headers in netfx HTTP diagnostics hook #35880

Merged
merged 4 commits into from
Mar 15, 2019

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.

This change implements this and also prevents injection of any of the correlation headers if it was injected before e.g. by tracing system or explicitly in the app code.

@lmolkova lmolkova requested a review from vancem March 8, 2019 04:43
@lmolkova
Copy link
Author

@vancem could you please have a look?

if (e.MoveNext())
// do not inject header if it was injected already
// perhaps tracing systems wants to override it
if (request.Headers[TraceParentHeaderName] == null)
Copy link
Member

@stephentoub stephentoub Mar 15, 2019

Choose a reason for hiding this comment

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

Nit: Above the code uses request.Headers.Get(id) and here it's using request.Headers[id]. IIRC, one just calls the other, but is there a reason for the different access pattern?

Copy link
Author

Choose a reason for hiding this comment

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

no, no particular reason, thanks for noticing it

StringBuilder baggage = new StringBuilder();
do
request.Headers.Add(TraceParentHeaderName, activity.Id);
if (activity.TraceStateString != null)
Copy link
Member

Choose a reason for hiding this comment

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

Accessing TraceStateString looks like an O(N) operation. Seems like it should be cached into a local rather than accessing it twice, once to check for null and the other to add it.

{
// do not inject header if it was injected already
// perhaps tracing systems wants to override it
if (request.Headers[RequestIdHeaderName] == null)
Copy link
Member

@stephentoub stephentoub Mar 15, 2019

Choose a reason for hiding this comment

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

Nit: Same question/comment about Get vs indexer

@lmolkova lmolkova merged commit dee28e2 into dotnet:master Mar 15, 2019
@karelz karelz added this to the 3.0 milestone Mar 18, 2019
macrogreg pushed a commit to open-telemetry/opentelemetry-dotnet-instrumentation that referenced this pull request Sep 24, 2020
* Inject W3C headers in Http Desktop hook

* do not inject headers if they were injected before

* check that w3c headers are empty when format is Hierarchical

* review comments


Commit migrated from dotnet/corefx@dee28e2
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Inject W3C headers in Http Desktop hook

* do not inject headers if they were injected before

* check that w3c headers are empty when format is Hierarchical

* review comments


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